Advertisement
lorro

WooCommerce - Custom variable price by category

Feb 11th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement