Set a minimum order in Woocommerce 3.2.x

Sometimes it does not make sense that the shipping cost is greater than the total shopping cart, so it is better to limit that situation by establishing a minimum order.

We will place a message in the shopping cart and we will prevent them from reaching the payment page, for this we will use the link “woocommerce_check_cart_items”.

For the following example, the minimum quantity will be 50.

function letsgo_minimum_order() {
    if( is_cart() || is_checkout() ) { 
		$cart_subtotal = 0;
		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) :
			$cart_subtotal += $cart_item['line_total'];
        // Create the error message that is displayed when the minimum has not been reached
        if( $cart_subtotal < 50 ) {
            $message = 'Remember that to finalize your purchase you must reach a minimum amount of $USD 50.<br/>';
            wc_add_notice( $message, 'error' );
add_action( 'woocommerce_check_cart_items', 'letsgo_minimum_order' );

Remember to put this code in functions.php


0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Back to Top
Would love your thoughts, please comment.x