daily pastebin goal
12%
SHARE
TWEET

WooCommerce - Custom variable price by category

lorro Feb 11th, 2017 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // WooCommerce - Custom variable price by category
  3.   // code goes in functions.php for your child theme
  4.   add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price', 40, 2 );
  5.   add_filter( 'woocommerce_variable_price_html',      'custom_variable_price', 40, 2 );
  6.   function custom_variable_price( $price, $_product ) {
  7.     $terms = get_the_terms( $_product->id, 'product_cat' );
  8.     foreach ($terms as $term) {
  9.       switch ($term->term_id) {
  10.         case 20: // my category id
  11.         case 21: // my category id, same text as category 20
  12.           return 'From $0.80 per item';
  13.         case 22: // some other category
  14.           return 'From $1.20 per item';
  15.         default:
  16.       } // end switch
  17.     } // end foreach
  18.     return $price; // any other category  
  19.   } // 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