Coupons Brands restriction
-
Hi, the ‘Brands restriction’ is a great feature of your plugin. I have an issue with it though…
Currently, when one or more product in the cart is of that brand, the complete cart will receive a discount. I would expect for ‘Percentage Discount’ and ‘Fixed Product Discount’ that only the products of the given brand will be discounted. At least that is how WooCommerce discounts normally work.
I solved this by this little snippet:
function woocommerce_coupon_is_valid_for_product_brand( $valid, $product, $coupon, $values ) { if ( ! $valid ) return false; $coupon_id = is_callable( array( $coupon, 'get_id' ) ) ? $coupon->get_id() : $coupon->id; $selected_brands = get_post_meta( $coupon_id, '_pwb_coupon_restriction', true ); if ( empty( $selected_brands ) ) return; $product_id = is_callable( array( $product, 'get_id' ) ) ? $product->get_id() : $product->id; $product_brands = wp_get_post_terms( $product_id, 'pwb-brand', array( 'fields' => 'ids' ) ); $valid_brands = array_intersect( $selected_brands, $product_brands ); return ! empty( $valid_brands ); } add_filter( 'woocommerce_coupon_is_valid_for_product', 'woocommerce_coupon_is_valid_for_product_brand', 10, 4 );
It would be great if this could be integrated into the plugin. What do you think?
Thanks for this nice plugin.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Coupons Brands restriction’ is closed to new replies.