php - Null the price of a Specific Product category from Cart Total -
i want remove / takeout price of specific category products cart total.
please see screenshot:
what hook use this?
thanks.
the right hook woocommerce_before_calculate_totals
using has_term() wordpress conditional function filter product categories in cart items. way can null price cart items.
this code:
add_action( 'woocommerce_before_calculate_totals', 'custom_price_product_category', 10, 1 ); function custom_price_product_category( $cart_object ) { foreach ( $cart_object->cart_contents $key => $item ) { // when product has 'glass' category null price. if( has_term( 'posters', 'product_cat', $item["product_id"] ) ) $item['data']->price = '0'; } }
this goes in function.php file of active child theme (or theme) or in plugin file.
this code tested , works.
Comments
Post a Comment