Tuesday, November 25, 2014

How to Adjust Minimum Order Amount in WooCommerce

WooCommerce is the most famous WordPress eCommerce plug in. Here, Find a WordPress code snippet which allows us to set minimum order amount in WooCommerce. If cart totals of a customer are as per below the minimum order amount, it shows an error message, and It does not allow the customer to place an order.

WooCommerce
Following code snippet is used to set the minimum order amount.

//Set minimum order amount in WooCommerce
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;

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.' ,
woocommerce_price( $minimum ),
woocommerce_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.' ,
woocommerce_price( $minimum ),
woocommerce_price( WC()->cart->total )
), 'error'
);

}
}

}

0 comments:

Post a Comment