WooCommerce: Pre-defined Add to Cart Quantity Selectors – 2026

Last updated on September 12th, 2024 at 02:30 pm

Creating pre-defined Add to Cart quantity selectors in WooCommerce can streamline the shopping experience by allowing customers to quickly select and add predefined quantities of a product to their cart with a single click. This approach can be particularly useful for bulk purchases, promotional bundles, or simply to enhance usability. In this guide, we’ll show you how to implement pre-defined quantity selectors that replace the standard “Add to Cart” button on your WooCommerce product pages.

Before modifying your theme’s files, it’s prudent to create a child theme to safeguard your changes. Our free WordPress child theme generator is a great resource to get this done quickly and efficiently.

Step 1: Removing the Default Add to Cart Button

First, we need to remove the default Add to Cart button and quantity input from the product pages. This can be done by adding the following code to your theme’s functions.php file:

/*
 * Snippet: WooCommerce: Pre-defined Add to Cart Quantity Selectors – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1469
* Tested with WooCommerce 10.7.0
* "Remove default add to cart button and quantity input from product pages"
*/ function wcsuccess_remove_add_to_cart_buttons() { remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); } add_action('init', 'wcsuccess_remove_add_to_cart_buttons');

This code effectively removes the Add to Cart button from all product types (single and loop listings) on your WooCommerce site.

Step 2: Adding Pre-defined Quantity Selectors

Next, we’ll add our custom pre-defined quantity selectors. These will be styled buttons that link to the product page with a query string that includes the product’s add-to-cart ID and the selected quantity. Insert the following code into the functions.php:

/*
 * Snippet: WooCommerce: Pre-defined Add to Cart Quantity Selectors – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1469
* Tested with WooCommerce 10.7.0
* "Add pre defined quantity selectors that replace standard add to cart button"
*/ function wcsuccess_predefined_add_to_cart_buttons() { global $product; // Define your predefined quantities $quantities = [1, 3, 5, 10]; // Example quantities echo '<div class="wc-success-predefined-quantities">'; foreach ($quantities as $quantity) { // Create a link for each predefined quantity $url = add_query_arg(array('add-to-cart' => $product->get_id(), 'quantity' => $quantity), get_permalink($product->get_id())); echo sprintf('<a href="%s" class="button predefined-qty" data-quantity="%d">Add %d to Cart</a>', esc_url($url), $quantity, $quantity); } echo '</div>'; } add_action('woocommerce_single_product_summary', 'wcsuccess_predefined_add_to_cart_buttons', 30);

This function creates a series of links/buttons. Each button, when clicked, will reload the product page with the specified quantity added to the cart using WooCommerce’s own cart management system.

See also  How to Display Product Dimensions and Weight on the WooCommerce Cart Page - 2026

Step 3: Styling the Quantity Selector Buttons

To ensure that the new buttons match your site’s design and are appealing to users, add the following CSS to your theme’s style.css file or via the WordPress Customizer:

.wc-success-predefined-quantities .button {
    display: inline-block;
    margin: 5px;
    padding: 10px 20px;
    color: #fff;
    background-color: #333;
    text-decoration: none;
    font-size: 16px;
    border-radius: 5px;
}

.wc-success-predefined-quantities .button:hover {
    background-color: #555;
}

This CSS styles the buttons with a basic design, which you can customize to fit your theme.

Conclusion

By following these steps, you’ve now replaced the standard WooCommerce Add to Cart button with pre-defined quantity selectors, enhancing the usability and efficiency of the shopping process. This setup not only makes it easier for customers to make bulk purchases but also can help in managing inventory for promotional items.

See also  WooCommerce Hide Specific Products for Certain Users - 2026

If you’re new to coding or theme customization, remember to use a child theme. Our free WordPress child theme generator can help protect your modifications during theme updates. Implementing these changes will make your WooCommerce store more user-friendly and tailored to your specific sales strategies.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×