WooCommerce: Add “Quantity” Label in front of Add to Cart Button

Here’s another little WooCommerce tweak for your website user experience: let’s add a string just in front of the Add to Cart button that says “Quantity: “. As usual, the biggest thing is looking for the right “hook”… but thankfully WooCommerce plugin is full of them and adding a string where we want is so easy πŸ™‚

Add “quantity” label before Add to Cart @ Single Product Page

PHP Snippet: Add “Quantity” Label in front of Add to Cart Button – WooCommerce

/**
 * @snippet       Add "Quantity" Label in front of Add to Cart Button - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=21986
 * @author        Rodolfo Melogli
 * @testedwith    WC 3.5.1
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_echo_qty_front_add_cart' );

function bbloomer_echo_qty_front_add_cart() {
 echo '<div class="qty">Quantity: </div>'; 
}

And a couple of CSS lines as well:

div.qty {
    float: left;
    padding: 10px;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

51 thoughts on “WooCommerce: Add “Quantity” Label in front of Add to Cart Button

  1. how can i use this code so it uses the translations of Quantity and not the english word. Thanks in advance.

    add_action( 'woocommerce_before_add_to_cart_quantity', 'wp_echo_qty_front_add_cart' );
    function wp_echo_qty_front_add_cart() {
     echo '<div class="qty">Quantity:</div>'; 
    }
    1. 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 πŸ™‚

  2. Hello how i can do to add quantity in just one product? thanks!

    1. I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Enjoy πŸ™‚

  3. 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.

    1. Great!

  4. Greetings,
    would you help me to customize woocommerce product page

    thank you in advance & have a wonderful day.

    1. 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!

  5. 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

    1. 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!

  6. 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.

    1. Here photo
      https://ibb.co/JpK3vZP

      Thanks you

      1. 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

  7. Hello, the snippet isn’t working anymore, it doesn’t apply the amount in the shopping cart. Can you please check this?

    1. Hey Mo, tested on Woo 3.5.1, works perfect. Thank you πŸ™‚

  8. is it possible to add this texte but ONLY for some products ?

    1. 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 πŸ™‚

  9. As of 3.0 you should use: woocommerce_before_add_to_cart_quantity

    1. That’s awesome Lucas. Thank you so much πŸ™‚

  10. it didnt work well for me πŸ™

    It got mixed up with some other info

    Can you please help me to fix?
    Thanks in advance

    1. pls i am using divi 2.2 theme i forgot to add

    2. got it fixed by tweaking cs πŸ˜‰ thanks buddy God bless

  11. 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
    }

    1. Thanks Chris πŸ™‚

  12. It worked like a charm!

  13. 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

    1. 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

  14. 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

    1. 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

  15. how to add any text after add to cart button in the loop/shop page (not single view)?

    1. 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

  16. 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

    1. You could override the default Woo template called

      global/quantity-input.php

      That way the quantity label will only show when the quantity input field is displayed.

      1. Gantsta, thanks so much for your comment! However, it’s not a great idea overriding templates, just so you know πŸ™‚

  17. 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.

  18. 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:

    .quantity:before {
      content:"Quantity:";
      margin-right:10px
    }
    .quantity input {
      display:inline;
      margin-right:30px
    }
    .woocommerce-variation-add-to-cart {
      margin-top:20px
    }
    1. Thank you Falling Ocean πŸ™‚

  19. 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.

    1. Hey Kate, thanks for your comment! When you say “I need ____ text to follow the Qty field”, what do you mean? Thanks πŸ™‚

  20. 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!

    1. Hey Melanie! If you enable WP_DEBUG on your site, what error do you see?

  21. 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

    1. just checked the previous screenshot link was broken
      Here is the new screenshot : https://ibb.co/kC1QGF

      1. 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!

  22. 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;
    }

    1. Awesome, thanks for sharing this Mad Dog!

      1. 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

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

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