Omowe
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;
}

 

Facebook
Twitter
LinkedIn
Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

This is an Advertorial

Learn how to build digital products without writing a single line of code

Build anything you can dream of without writing code or hiring a developer

Our non-technical students start companies using tools like Bubble, Softr , Elementor and Airtable. It’s easier, faster and more fun.

No matter what your background is, our lessons are designed to figure out what you don’t know and fill in the gaps

Join our learning community of soulmates, learn at your own pace and stay motivated to reach your objectives.

Begin Your No-Code Journey.


Training Mode : in-class
Location : E-349 Ikota Shopping Complex, VGC, Ajah, Lagos
Fees : N150,000