Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › add a product on the cart to get discount on other category › Reply To: add a product on the cart to get discount on other category
October 23, 2018 at 3:43 pm
#4000
Soft79
Keymaster
Probably because it’s a variable product. Try this:
add_filter( 'woocommerce_coupon_get_discount_amount', function( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
$COUPON_CODE = 'COUPON_CODE'; // replace with the coupon code
$DISCOUNTED_CATEGORY = 123; // replace with the category that is discounted
if ( 0 == strcasecmp( $coupon->code, $COUPON_CODE ) ) {
$_product = $cart_item['data'];
if ( $_product->get_parent_id() ) {
$_product = wc_get_product( $_product->get_parent_id() );
}
$cat_ids = $_product->get_category_ids();
if ( ! in_array( $DISCOUNTED_CATEGORY, $cat_ids ) ) {
$discount = 0;
}
}
return $discount;
}, 10, 5 );