Question: how to call on all coupons starting with ‘nm’ that exempt the minimum cart purchase requirement.

I added this code to my functions.php file in wordpress to make it so that a customer has to have a minimum purchase of $15 in their cart before they can complete their purchase.

        // SET CART TO MINIMUM ORDER OF 15 
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );

function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 15;

 // No minimum purchase if a specific coupon code is used
 if ( WC()->cart->has_discount( 'nm' ) ) {
    return;
}

if ( WC()->cart->total < $minimum ) {

    if( is_cart() ) {

        wc_print_notice( 
            sprintf( 'You must have an order with a minimum of %s to place 
your order, your current order total is %s.' , 
                wc_price( $minimum ), 
                wc_price( WC()->cart->total )
            ), 'error' 
        );

    } else {

        wc_add_notice( 
            sprintf( 'You must have an order with a minimum of %s to place 
your order, your current order total is %s.' , 
                wc_price( $minimum ), 
                wc_price( WC()->cart->total )
            ), 'error' 
        );

    }
}

}

However, when I have certain coupon codes for free shipping and/or free product, I don’t want the minimum requirement. I added the following in the above code.

        // No minimum purchase if a specific coupon code is used
 if ( WC()->cart->has_discount( 'nm' ) ) {
    return;
}

This works fine if I’m using a coupon called ‘nm’, but I will have various coupons and I would like it to utilize any coupons that start with ‘nm’. How do I do that?

Thanks for your help!

Read more here: woocommerce – string query for all coupons starting with ‘nm’


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: