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 8
* @community https://businessbloomer.com/club/
*/
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:
CSS Snippet: Add an Icon to the Add to Cart Buttons – WooCommerce + Storefront Theme
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:
Advanced Plugin: Custom Add to Cart Button
The code snippet above will let you add an icon to the add to cart button. If youโd also like to customize the text, then I recommend the free WooCommerce Custom Add To Cart Button plugin.
This well-coded plugin lets you add an icon and either remove the text or change it to whatever you like, such as โAdd to Basketโ.
It works on its own, or with other plugins from the same company such as WooCommerce Product Table, which is useful for creating quick one-page order forms that benefit from a simplified add to cart button.
Hi Rodolfo,
I want to ask, how to add some space after the icon?
Thanks in advance!
There is already a blank space (see the space after the “raquo” semicolon)
The link of “icons from FontAwesome” in this blog ( https://fontawesome.io/icons/ ) is broken.
Thanks, fixed
It doesn’t work when im in incognito
Without incognito it works?
Hi Rodolfo,
how can you only add the button to the archive pages instead of single product pages?
Thanks!
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!
And here is the working solution for Font Awesome 5 Free:
Top!
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
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
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?
Thanks
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
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 ๐
Hello Tim, thanks for your comment ๐ That’s added by the affiliate plugin I’m using ๐
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
to this?
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!
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/
Nice! Thanks Katie ๐
How to make the button bigger?
Thanks for your comment Dewi! You will need custom CSS for that ๐
Thank you! Better UX now ๐
Excellent ๐
Excellent, thanks a mill, works beautifully :D.
Thank you ๐
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?
Hey Ahmed, thanks for your comment! You have to place CSS in your style.css, not to the PHP ๐
Hi and Thanks Rodolfo, and if i want this for all buttons “add to cart”, how i can do it ?
Hey Thierry, this already applies the icon to all ad to cart buttons ๐
Not work to the archives page, it’s ok only for the single.
Ah, gotcha! You just need to add one more class (CSS version) or one more filter (PHP version). Hope this helps ๐
yeap, thanks Rodolfo.
๐
Rodolfo iโm impressed by your free and full dedication to help woocommerce community.
Congratulations!
Thank you Paulo!