daily pastebin goal
78%
SHARE
TWEET

WooCommerce - Change price example

lorro May 2nd, 2017 (edited) 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price', 40, 2 );
  3. add_filter( 'woocommerce_variable_price_html', 'custom_variable_price', 40, 2 );
  4. function custom_variable_price( $price, $_product ) {
  5.   $terms = get_the_terms( $_product->id, 'product_cat' );
  6.   foreach ($terms as $term) {
  7.     switch ($term->term_id) {
  8.       case 134: // some other category
  9.         $price = '$0.80-$2.00';
  10.         break;
  11.       case 132: // some other category
  12.         $price = '$1.50-$2.00';
  13.         break;
  14.       case 138: // some other category
  15.         $price = '$1.25';
  16.         break;
  17.       case 142: // some other category
  18.         $price = '$0.30';
  19.         break;
  20.       case 140: // some other category
  21.         $price = '$5.00';
  22.         break;
  23.       case 141: // some other category
  24.         $price = '$1.00-$1.50';
  25.         break;
  26.       case 139: // some other category
  27.         $price = '$1.00';
  28.         break;
  29.       case 143: // some other category
  30.         $price = '$3.00';
  31.         break;
  32.       case 150: // some other category
  33.         $price = '$0.80-$2.00';
  34.         break;
  35.       case 152: // some other category
  36.         $price = '$0.80-$2.00';
  37.         break;
  38.       case 153: // some other category
  39.         $price = '$0.80-$2.00';
  40.         break;
  41.       case 156: // some other category
  42.         $price = '$0.80-$2.00';
  43.         break;
  44.       case 159: // some other category
  45.         $price = '$1.00';
  46.         break;
  47.       case 160: // some other category
  48.         $price = '$1.50-$2.00';
  49.         break;
  50.       case 154: // some other category
  51.         $price = '$0.80-$2.00';
  52.         break;
  53.       case 157: // some other category
  54.         $price = '$5.00';
  55.         break;
  56.       case 158: // some other category
  57.         $price = '$3.00';
  58.         break;
  59.       case 163: // some other category
  60.         $price = '$0.80-$2.00';
  61.         break;
  62.       default:
  63.     } // end switch
  64.   } // end foreach
  65.   // now do the specials
  66.   switch ($_product->id) {
  67.     case 6952:
  68.       $price = '$0.25'; // applies to 6952
  69.       break;
  70.     default: // anything else
  71.   } // end switch
  72.   return $price; // any other category
  73. } // end function
RAW Paste Data
Top