Repository Forums Support WooCommerce Extended Coupon Features PRO Minimum subtotal agreed products does not work

Topic Resolution: Resolved
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2490
    jazzynl
    Participant

    Hello,

    The counting ‘Minimum subtotal agreed products’ does not apply.
    When i fill in 3 there, i can still add a coupon code at 1 product.
    I tried re-install the plugin, cleaning cache, stopped WP Rocket plugin but all will not slove the problem.
    In the DEBUG file there is noting to see.

    The option ‘Minimum number of agreed products’ works, but that is not suitable.
    What can be the problem?

    #2491
    Soft79
    Keymaster

    Hi,

    Minimal subtotal of matching products refers to the total price of the matching products in the cart. So if the subtotal exceeds $ 3 (or whatever currency) it will apply.

    #2493
    jazzynl
    Participant

    Ok, this is working in a price value!

    The problem is, i want to add 5€ on 1 product but the costumer must have 3 products in total in the basket.
    How can i achief that? The products have not all the same price.
    When i not excluse the products, then the €5 will added on the wrong product combination.

    #2495
    Soft79
    Keymaster

    If you use the following snippet, the coupon will only apply if you have 3 or more items in the cart.

    1. Create a € 5 discount coupon
    2. On the Usage Restrictions-tab select the Product to which it must apply
    3. Append the following snippet to your child themes’ functions.php (replace your_coupon_code by the actual coupon code):

    
    add_action( 'wjecf_assert_coupon_is_valid', 
        function( $coupon, $wc_discounts ) {
            if ( strtolower( WJECF_Wrap( $coupon )->get_code() ) == strtolower( 'your_coupon_code' ) ) {    
                //Must have at least 3 items in the cart
                $items = WJECF_WC()->get_discount_items( $wc_discounts );
                $qty = 0;
                foreach( $items as $item_key => $item ) {
                    if ( $item->product === false ) continue;
                    $qty += $item->quantity;
                    if ($qty >= 3) return;
                }
                throw new Exception( WC_Coupon::E_WC_COUPON_NOT_APPLICABLE );
            }
        }, 
        10, 2
    );
    

    Now the coupon will only be valid if there are at least 3 items in the cart.

    #2496
    jazzynl
    Participant

    Hi Soft79, thanks for the fast response!
    The problem when i add the code to the functions.php i get an: HTTP ERROR 500 error.
    Is there a fault in the code?

    add_action( 'wjecf_assert_coupon_is_valid', 
        function( $coupon, $wc_discounts ) {
            if ( strtolower( WJECF_Wrap( $coupon )->get_code() ) == strtolower( 'earlybird' ) ) {    
                //Must have at least 3 items in the cart
                $items = WJECF_WC()->get_discount_items( $wc_discounts );
                $qty = 0;
                foreach( $items as $item_key => $item ) {
                    if ( $item->product === false ) continue;
                    $qty += $item->quantity;
                    if ($qty >= 3) return;
                }
                throw new Exception( WC_Coupon::E_WC_COUPON_NOT_APPLICABLE );
            }
        }, 
        10, 2
    );
    #2497
    Soft79
    Keymaster

    What version of php do you have? It’s mentioned in the WooCommerce System Status.

    #2498
    jazzynl
    Participant

    PHP-versie: 7.1.12

    #2499
    Soft79
    Keymaster

    What version of Extended Coupon Features? Any error message in the debug.log ?

    #2500
    jazzynl
    Participant

    The version of Extended Coupon Features is: 2.6.0.2

    the debus shows no errors:
    (just a part of it)
    2018-01-13T21:02:28+00:00 DEBUG woocommerce_after_calculate_totals WJECF_AutoCoupon::get_all_auto_coupons Autocoupons:
    2018-01-13T21:02:28+00:00 DEBUG woocommerce_after_calculate_totals WJECF_AutoCoupon::update_matched_autocoupons Auto coupons that should be in cart:
    2018-01-13T21:02:28+00:00 DEBUG woocommerce_after_calculate_totals WJECF_AutoCoupon::update_matched_autocoupons Coupons in cart: earlybird

    I have a fatal error log:
    2018-01-13T20:14:42+00:00 CRITICAL Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /****/public_html/wp-includes/class-wp-hook.php on line 286 and exactly 2 expected in /****/public_html/wp-content/themes/****/functions.php:152
    Stack trace:
    #0 /****/public_html/wp-includes/class-wp-hook.php(286): {closure}(Object(WC_Coupon))
    #1 /****/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)
    #2 /****/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
    #3 /****//public_html/wp-content/plugins/woocommerce-auto-added-coupons/includes/WJECF_Controller.php(463): do_action(‘wjecf_assert_co…’, Object(WC_Coupon))
    #4 /****/public_html/wp-includes/class-wp-hook.php(286): WJECF_Controller->assert_coupon_is_valid(true, Object(WC_Coupon), Object(WC_Discounts))
    #5 /

    your help is greatly appreciated! Sorry for the problem.

    #2501
    Soft79
    Keymaster

    The snippet requires at least version 2.6.1 of WooCommerce Extended Coupon Features PRO. Please update to the latest version.

    #2505
    jazzynl
    Participant

    PRO version in combination with the snippet is working well.
    Maybe it is an feature in an next update so that you can select it.

    – product A gives €5 discount, but it will be only there if product B an/or C are in the basket with minimum of 3.

    Thanks for support.

    #2509
    Soft79
    Keymaster

    Great! Thanks for the feedback.

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