Set minimum and maximum product quantity 2 pcs in specific product category in woocommerce woodmart theme

Viewed 20

I want to make minimum and maximum product quantity 2 pcs in specific product category of my site. That means customer can only buy any 2 products from that category

Can someone fix me the following code?

Code:

add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' ); function required_min_cart_subtotal_amount() {

// HERE Set minimum cart total amount

$minimum_amount = 200;

// Total (before taxes and shipping charges)

$cart_subtotal = WC()->cart->subtotal;

// Add an error notice is cart total is less than the minimum required

if( $cart_subtotal < $minimum_amount  ) {
    

// Display an error message

    wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($minimum_amount) ) . '<strong>', 'error' );
}

}

0 Answers
Related