Repository Forums Support WooCommerce Extended Coupon Features PRO Percentage discount on cart with restriction

Topic Resolution: Resolved
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2701

    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!

    #2706
    Soft79
    Keymaster

    Hi,

    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 );
    
    #2713

    Hello,
    Sorry but where I should put this code?

    #2716
    Soft79
    Keymaster

    In functions.php of your child theme.

    #2726

    It works thank you! <3

    #8394
    Bob Gregg
    Participant

    Why 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?

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.