简体   繁体   中英

Set a minimum undiscounted order amount in WooCommerce

I am using " Minimum Order Amount " to require a minimum order amount.

If I have a basket of € 50 of purchase and I apply my 10% discount code, I can't order my shopping cart because the total is € 45.

But I want to order for < € 50 ONLY with a discount code

Updated : Use the following revisited and compacted code, that uses the undiscounted total:

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 = 50;

    $total = WC()->cart->total;
    $discount_total = WC()->cart->get_discount_total(); // updated thanks to 7uc1f3r
    $maximized_total = $total + $discount_total;

    if ( $maximized_total < $minimum ) {

        $notice = sprintf( __('Your current order total is %s — you must have an order with a minimum of %s to place your order '), 
            wc_price( $maximized_total ), 
            wc_price( $minimum )
        );

        if( is_cart() ) {
            wc_print_notice( $notice , 'error' );
        } else {
            wc_add_notice( $notice , 'error' );
        }
    }
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM