Advertisement
lorro

WooCommerce - Product page text dependant on category

Nov 3rd, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2. // print some text on the product page, under the add-to-cart button
  3. // for some categories but different text for others
  4. // snippet goes in functions.php for your child theme
  5.  
  6. add_action( 'woocommerce_single_product_summary', 'cat_condition', 35);
  7. function cat_condition() {
  8.   global $post;
  9.   if ( is_product() ) {
  10.     $socks = 116; // category id for socks
  11.     $terms = get_the_terms( $post->ID, 'product_cat' );
  12.     $found = false;
  13.     foreach ($terms as $term) {
  14.       if ($socks == $term->term_id) {
  15.         $found = true;
  16.         break;
  17.       }
  18.     } // end for
  19.     if ($found) {
  20.       print '<p>Socks found!</p>';
  21.     } else {
  22.       print '<p>No socks here!</p>';
  23.     }      
  24.   } // end if
  25. } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement