Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

WooCommerce - Product page text dependant on category

lorro Nov 3rd, 2016 72 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top