Here’s another little WooCommerce tweak for your website user experience: let’s add some text in front of the Add to Cart button that says “Quantity: “.
As usual, we go looking for the right “hook”… the WooCommerce plugin is full of them and adding some custom content in the exact position we want is very easy. Enjoy!

PHP Snippet: Add “Quantity” Label in front of Add to Cart Button – WooCommerce
/**
* @snippet Add "Quantity:" before Add to Cart Button - WooCommerce
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 8
* @community https://businessbloomer.com/club/
*/
add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_echo_qty_front_add_cart' );
function bbloomer_echo_qty_front_add_cart() {
global $product;
if ( $product->get_min_purchase_quantity() == $product->get_max_purchase_quantity() ) return;
echo '<div class="qty">Quantity: </div>';
}
And a couple of CSS lines as well:
div.qty {
float: left;
padding: 10px;
}
Annoyingly it isn’t quite as simple as this. When a product has a stock level of 1 WooCommerce hides the quantity input. this means you are left with your pseudo ‘Quantity’ label showing and no corresponding input. Also worth noting WooCommerce outputs a visually hidden label element for the input, therefore it would be a good idea to add a aria-hidden=”true” attribute to the added element so assistive technology isn’t getting duplicate content.
Thank you. I’ve fixed the “sold individually” scenario, so the label doesn’t appear now when there is no quantity input. Thanks re: the aria-hidden tip as well!
how can i use this code so it uses the translations of Quantity and not the english word. Thanks in advance.
In order to make a string translatable you have to wrap it in a __() function: https://codex.wordpress.org/I18n_for_WordPress_Developers#Translatable_strings – hope this helps π
Hello how i can do to add quantity in just one product? thanks!
I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Enjoy π
HI Rodolfo,
This is an incredibly clear and helpful little post and snippet(s) – thanks so much.
And it came up close to the top of a google search for ‘woocommerce product quantity field label’
I am using product variations for simple venue hire products for a church hall. So i’ve used the variatons to set the number of hours in the hire booking, and the quantity field to set the number of days the hire is repeated. So it was really important to be able to label that field – i’ve done so using ‘days’ instead of ‘quantity.
Great!
Greetings,
would you help me to customize woocommerce product page
thank you in advance & have a wonderful day.
Hey Jaouahar, thanks so much for your comment! If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
I’ve added this code, but the only thing that doesn’t work is the plus or minus buttons which we’ve added to the sides of the quantity box, using a previous code of yours.
The quantity box stays empty and the plus or minus buttons won’t work.
Without your filter for the quantity div, the plus or minus buttons work ok.
Not sure what would be the best way to resolve this?
Kind Regards,
Andrew
I guess some adjustment might be needed to make them work together, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Normally quantity was in front of the add to cart button. Few plugins installed after checking my website i see its above of add to cart button. I tried code here but it didnt work.
Here photo
https://ibb.co/JpK3vZP
Thanks you
Hi Gary, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?
To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.
Hope this helps!
R
Hello, the snippet isn’t working anymore, it doesn’t apply the amount in the shopping cart. Can you please check this?
Hey Mo, tested on Woo 3.5.1, works perfect. Thank you π
is it possible to add this texte but ONLY for some products ?
Hello Julienne, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know π
As of 3.0 you should use: woocommerce_before_add_to_cart_quantity
That’s awesome Lucas. Thank you so much π
it didnt work well for me π
It got mixed up with some other info
Can you please help me to fix?
Thanks in advance
pls i am using divi 2.2 theme i forgot to add
got it fixed by tweaking cs π thanks buddy God bless
Awesome π
This code works best for me:
.quantity:before {
content:”Quantity:”;
margin-right:10px
}
.quantity input {
display:inline;
margin-right:30px
}
.woocommerce-variation-add-to-cart {
margin-top:20px
}
Thanks Chris π
It worked like a charm!
π
Hi Rodolfo,
I managed to change the label but after adding the CSS code in my X theme, I am still not able to see the lable on the left side of the box. It’s still on top of the quantity box.
Can you please email me, as I have a few projects to discuss as well.
Cheers
Hey Chirag, thanks so much for your comment! I guess this is X-theme specific, so the CSS will need to be changed in order to work. If you’d like to get a quote, feel free to contact me here. ~R
Hello Rodolfo, Thank you so much for the explanation !
it works great for me.
I would need a little thing additional to have it perfect for my need : how to add a label (for quantity unit) AFTER the quantity input field?
Thank you in advance for your help !
Best regards,
Julie
Hey Julie, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
how to add any text after add to cart button in the loop/shop page (not single view)?
Hey Gen, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hi this is great, but how can I remove this display for products that have no quantity box . So I want that the label will be conditionally displayed. Thanks
Tania, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know π
You could override the default Woo template called
That way the quantity label will only show when the quantity input field is displayed.
Gantsta, thanks so much for your comment! However, it’s not a great idea overriding templates, just so you know π
Hi, how can i display “quantity label” only in selected pages/post id? Cause i would insert “per-night” label for specific product pages in my website.
Hey Alex, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know π
Great site with awesome tips. Much appreciated.
Regarding this, didn’t work for me with variation products. Found a workaround with CSS that works for me in case anyone still needs it:
Thank you Falling Ocean π
Thank you for the information. I am struggling to get Mad Dog’s workaround right. I have changed my wording to “Number of Guests” but when i select the variation then I need the “Number of Guests” text to follow the Qty field. Thanks again.
Hey Kate, thanks for your comment! When you say “I need ____ text to follow the Qty field”, what do you mean? Thanks π
The Code doesnt work on my page. I have no add to cart at my categorie pages and there I get white screen. Whats wrong? Thanks for your good website!
Hey Melanie! If you enable WP_DEBUG on your site, what error do you see?
I tried the code, the code is working but there is one problem.
I am actually using product addon. The βQuantityβ text appear between my variation and product addon tab. (screenshot attached below)
Can you please help me out.
Here is the Screenshot : https://imgur.com/a/F82Sd
just checked the previous screenshot link was broken
Here is the new screenshot : https://ibb.co/kC1QGF
Hey Mahesh, which code did you try, mine or the one provided by “Mad Dog” in the comments? Maybe try the 2 and let me know if either works. Cheers!
This didn’t work for me because it displays before variables…..
But I did the same thing with simple CSS:
/* ADD “Quantity” in front of Quantity and Add to Cart buttons */
.woocommerce div.product form.cart div.quantity::before {
content: “Quantity: “;
font-weight: bold;
padding-right: 8px;
}
Awesome, thanks for sharing this Mad Dog!
I tried the code, the code is working but there is one problem.
I am actually using product addon. The “Quantity” text appear between my variation and product addon tab. (screenshot attached below)
Can you please help me out.
Here is the Screenshot : https://imgur.com/a/F82Sd