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

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