Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // WooCommerce - Custom variable price by category
- // code goes in functions.php for your child theme
- add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price', 40, 2 );
- add_filter( 'woocommerce_variable_price_html', 'custom_variable_price', 40, 2 );
- function custom_variable_price( $price, $_product ) {
- $terms = get_the_terms( $_product->id, 'product_cat' );
- foreach ($terms as $term) {
- switch ($term->term_id) {
- case 20: // my category id
- case 21: // my category id, same text as category 20
- return 'From $0.80 per item';
- case 22: // some other category
- return 'From $1.20 per item';
- default:
- } // end switch
- } // end foreach
- return $price; // any other category
- } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement