Woocommerce: Limit Quantity That Can Be Ordered in A Particular Category to 1

This code limits the quantity of products that can be purchased in the “domains” category to only one.

The code snippet hooks into the woocommerce_quantity_input_args filter, which allows you to modify the arguments for the quantity input field for a product. It checks if the product belongs to the “domains” category, and if it does, it sets the max_value and min_value arguments to 1, which will limit the quantity that can be purchased to only one.

You can add this code snippet to your WordPress site by adding it to your theme’s functions.php file, add it to a code snippet plugin or by creating a custom plugin.

add_filter( 'woocommerce_quantity_input_args', 'limit_quantity_for_domains_category', 10, 2 );
function limit_quantity_for_domains_category( $args, $product ) {
    if ( has_term( 'domains', 'product_cat', $product->get_id() ) ) {
        $args['max_value'] = 1;
        $args['min_value'] = 1;
    return $args;


Leave the first comment