WooCommerce: Add an Icon to the Add to Cart Buttons

Ecommerce is all about user experience, and making it easier for people to add to cart and checkout smoothly. Reducing the number of checkout fields is a great idea for example – as well as graphically communicating your number 1 objective: “please add to cart now!”.

So, how do you add an icon (or an HTML symbol) to the add to cart buttons in WooCommerce? This can be done in two ways – via CSS if you want to show Fontawesome Icons or via PHP if you prefer to use a simple HTML unicode symbol.

Let’s take a look at both methods!

PHP Snippet: Add an HTML Symbol to the Add to Cart Buttons – WooCommerce

You can find the list of HTML symbols here: https://www.w3schools.com/html/html_symbols.asp. Basically, by using some HTML entities, you can print a symbol on the screen such as –> € <– (FYI, I just used “&”, “euro” and “;” without spaces to print the symbol).

In this example, I want to show a simple symbol called “raquo” (don’t forget to add the “&” and final “;” to actually generate the symbol).

 * @snippet       Add HTML Symbol to Add to Cart Button - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 5.
 * @donate $9     https://businessbloomer.com/bloomer-armada/

add_filter( 'woocommerce_product_single_add_to_cart_text', 'bbloomer_add_symbol_add_cart_button_single' );

function bbloomer_add_symbol_add_cart_button_single( $button ) {
   $button_new = '» ' . $button;
   return $button_new;

Final result:

Add an HTML Symbol to the Add to Cart Buttons

CSS Snippet: Add an Icon to the Add to Cart Buttons – WooCommerce

If you want a better range of icons, Storefront theme already uses a library of icons from FontAwesome to print special icons on the screen. If your theme doesn’t support FontAwesome, you can simply add a script in the header to load the special font.

In this example, I wish to add a “Shopping Cart +” icon provided by Fontawesome, which comes with a code “\f217”.

button.single_add_to_cart_button:before {
   display: inline-block;
   font-family: FontAwesome;
   float: left;
   content: "\f217";
   font-weight: 300;
   margin-right: 1em;

Here’s the final result:

Add a FontAwesome Icon to the Add to Cart Buttons

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its 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 guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went 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.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 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.

36 thoughts on “WooCommerce: Add an Icon to the Add to Cart Buttons

  1. Hi Rodolfo,

    I want to ask, how to add some space after the icon?

    Thanks in advance!

    1. There is already a blank space (see the space after the “raquo” semicolon)

  2. The link of “icons from FontAwesome” in this blog ( https://fontawesome.io/icons/ ) is broken.

      1. It doesn’t work when im in incognito

        1. Without incognito it works?

  3. Hi Rodolfo,

    how can you only add the button to the archive pages instead of single product pages?


    1. Hello Jarno, thanks so much for your comment! Yes, this is definitely possible, 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!

  4. And here is the working solution for Font Awesome 5 Free:

    .single_add_to_cart_button::before {
    	font-family: 'Font Awesome 5 Free';
    	content: "\f291";
    1. Top!

  5. Hi Rodolfo Thans for the incredible work you’re doing, I am finding it difficult putting “Add To Cart and By NOw” on my woocommerce website which i use Electro Theme for

    1. Hey Willie, 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

  6. Thanks for sharing! But why when I’m trying to add via CSS code it just show me the square? Please, take a look: https://imgur.com/a/3PrjNn1. And there is an added fontawesome code. What can be a problem?


    1. Bohdan, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  7. In your feature image for this post, how did you add the United States and United Kingdom flags and circle selectors? I have also variable products but its a dropdown box 🙁

    1. Hello Tim, thanks for your comment 🙂 That’s added by the affiliate plugin I’m using 🙂

  8. Hey Rodolfo, finding great resources on your site!
    Well done for sharing your knowledge!!
    Similar to your article above, I am adding icons to the ‘Add to Cart’ Buttons…
    I’ve added a SVG icon to the add to cart button on the single product page – See lines 60-62 on https://gist.github.com/macgraphic/324207402d72ae4163c0e91c2a967391
    But I need to add the same to the archive page buttons. So, that would be theme/woocommerce/loop/add-to-cart.php file? How would I go about adding the

    <?php echo bjas_svg_get_icon( 'bag-fill' ); ?>

    to this?

    1. Hiya Mark 🙂 In that case, there is a filter called “woocommerce_loop_add_to_cart_link” that you can manipulate via a PHP snippet, without overriding any template. Hope this helps!

  9. Great article thanks! We’ve just launched a free WordPress plugin that lets you add a cart icon to the WooCommerce add to cart button without editing any code, so this will be useful for your less technical readers. You can download the plugin via https://wordpress.org/plugins/woo-custom-add-to-cart-button/

    1. Nice! Thanks Katie 🙂

  10. How to make the button bigger?

    1. Thanks for your comment Dewi! You will need custom CSS for that 🙂

  11. Thank you! Better UX now 🙂

  12. Excellent, thanks a mill, works beautifully :D.

  13. Hi! Rodolfo! I tried the code with CSS Snippet on WordPress and I get the following error message

    (Don’t Panic

    The code snippet you are trying to save produced a fatal error on line 1:

    syntax error, unexpected ‘:’)

    What could be the problem?

    1. Hey Ahmed, thanks for your comment! You have to place CSS in your style.css, not to the PHP 🙂

  14. Hi and Thanks Rodolfo, and if i want this for all buttons “add to cart”, how i can do it ?

    1. Hey Thierry, this already applies the icon to all ad to cart buttons 🙂

    2. Not work to the archives page, it’s ok only for the single.

      1. Ah, gotcha! You just need to add one more class (CSS version) or one more filter (PHP version). Hope this helps 🙂

    3. yeap, thanks Rodolfo.

  15. Rodolfo i’m impressed by your free and full dedication to help woocommerce community.

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 *