daily pastebin goal
78%
SHARE
TWEET

WooCommerce - Product page text dependant on category

lorro Nov 3rd, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
Top