Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Percentage discount on cart with restriction
- This topic has 5 replies, 3 voices, and was last updated 7 years ago by Bob Gregg.
- AuthorPosts
- February 20, 2018 at 5:21 pm #2701francesco d’aloisioParticipant
Hello,
I’m having troubles with a coupon:
This coupon provides the following instruction
Buy 3 packages of rice and do a minimum order of 39€ to receive -15% discount on all the cart.
But the problem is that -15% applies only on the rice packages and not on all cart.
There is a solution?
Thanks!February 21, 2018 at 4:17 pm #2706Soft79KeymasterHi,
the following snippet restores the discount type ‘Cart % discount’ which was removed in WC2.7/3.0. requires PHP5.3 or newer!
add_filter( 'woocommerce_cart_coupon_types', function ( $coupon_types ) { if ( ! in_array( 'percent_cart', $coupon_types ) ) $coupon_types[] = 'percent_cart'; return $coupon_types; }, 10, 1 ); add_filter( 'woocommerce_coupon_discount_types', function ( $coupon_discount_types ) { $coupon_discount_types['percent_cart'] = __( 'Percentage cart discount', 'your-language-domain' ); $coupon_discount_types['percent'] = __( 'Percentage product discount', 'your-language-domain' ); return $coupon_discount_types; }, 10, 1 ); add_filter( 'woocommerce_coupon_get_discount_amount', function( $discount_amount, $discounting_amount, $cart_item, $single, $coupon ) { if ( $coupon->is_type( 'percent_cart' ) ) { $discount = (float) $coupon->get_amount() * ( $discounting_amount / 100 ); $discount_amount = round( min( $discount, $discounting_amount ), wc_get_rounding_precision() ); } return $discount_amount; }, 10, 5 );February 23, 2018 at 9:12 am #2713francesco d’aloisioParticipantHello,
Sorry but where I should put this code?February 23, 2018 at 7:55 pm #2716Soft79KeymasterIn functions.php of your child theme.
February 26, 2018 at 3:38 pm #2726francesco d’aloisioParticipantIt works thank you! <3
August 26, 2019 at 10:14 pm #8394Bob GreggParticipantWhy was this feature removed in WC2.7/3.0? Adding that code back in didn’t resolve the problem for us. Is there any special location or other dependencies as to how that code is to be integrated back in? If I send you a copy of our functions.php can you insert that code snippet in the correct format for us to try to see if that will get it working?
- AuthorPosts
- You must be logged in to reply to this topic.