Customising the “Add to Cart” button in WooCommerce can significantly enhance the user experience and make your store more visually appealing. One effective way to customise this button is by adding an icon. This guide will cover several methods to add an icon to the “Add to Cart” buttons in WooCommerce using PHP, CSS, HTML entity codes, Dashicons, and FontAwesome.
Why Add Icons to the Add to Cart Buttons?
- Enhanced Visual Appeal: Icons make buttons more attractive and engaging.
- Improved User Experience: Icons can help convey the purpose of the button more quickly.
- Brand Consistency: Custom icons can align the button design with your brand’s style.
Method 1: Using PHP and HTML Entity Codes
You can add an icon to the “Add to Cart” button by modifying your theme’s functions.php file. If you don’t already have a child theme, create one using our free child theme generator.
- Create a Child Theme (if needed):
- Visit our Free WordPress Child Theme Generator to create and download your child theme.
- Follow the instructions to install and activate your child theme.
- Add Code to
functions.php:- Navigate to Appearance > Theme File Editor in your WordPress dashboard.
- Select the
functions.phpfile of your child theme. - Add the following code to include an HTML entity code icon (e.g., a shopping cart icon):
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Add HTML entity icon to Add to Cart button"
*/
function wcsuccess_add_icon_to_cart_button( $button, $product ) {
if ( $product->is_purchasable() && $product->is_in_stock() ) {
$button_text = $product->add_to_cart_text();
$icon = '?'; // HTML entity code for shopping cart icon
$button = sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>%s %s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
$icon,
esc_html( $button_text )
);
}
return $button;
}
add_filter( 'woocommerce_product_add_to_cart_link', 'wcsuccess_add_icon_to_cart_button', 10, 2 );
Method 2: Using Dashicons
Dashicons are built into WordPress and can be easily added to your WooCommerce buttons.
- Add Code to
functions.php:- Add the following code to your
functions.phpfile:
- Add the following code to your
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Add Dashicon to Add to Cart button"
*/
function wcsuccess_add_dashicon_to_cart_button( $button, $product ) {
if ( $product->is_purchasable() && $product->is_in_stock() ) {
$button_text = $product->add_to_cart_text();
$icon = '<span class="dashicons dashicons-cart"></span>';
$button = sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>%s %s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
$icon,
esc_html( $button_text )
);
}
return $button;
}
add_filter( 'woocommerce_product_add_to_cart_link', 'wcsuccess_add_dashicon_to_cart_button', 10, 2 );
- Enqueue Dashicons:
- Add this code to ensure Dashicons are enqueued:
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Enqueue Dashicons"
*/
function wcsuccess_enqueue_dashicons() {
wp_enqueue_style( 'dashicons' );
}
add_action( 'wp_enqueue_scripts', 'wcsuccess_enqueue_dashicons' );
Method 3: Using FontAwesome
FontAwesome offers a wide range of icons that can be added to your WooCommerce buttons.
- Enqueue FontAwesome:
- Add this code to your
functions.phpfile to load FontAwesome:
- Add this code to your
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Enqueue FontAwesome"
*/
function wcsuccess_enqueue_fontawesome() {
wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css' );
}
add_action( 'wp_enqueue_scripts', 'wcsuccess_enqueue_fontawesome' );
- Add FontAwesome Icon to
functions.php:- Add the following code to include a FontAwesome icon:
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Add FontAwesome icon to Add to Cart button"
*/
function wcsuccess_add_fontawesome_to_cart_button( $button, $product ) {
if ( $product->is_purchasable() && $product->is_in_stock() ) {
$button_text = $product->add_to_cart_text();
$icon = '<i class="fas fa-shopping-cart"></i>'; // FontAwesome shopping cart icon
$button = sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>%s %s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
$icon,
esc_html( $button_text )
);
}
return $button;
}
add_filter( 'woocommerce_product_add_to_cart_link', 'wcsuccess_add_fontawesome_to_cart_button', 10, 2 );
Method 4: Using CSS
For a quick and simple method, you can use CSS to add an icon to the “Add to Cart” button.
- Add Custom CSS:
- Navigate to Appearance > Customize > Additional CSS and add the following CSS:
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Add CSS icon to Add to Cart button"
*/
.button.add_to_cart_button:before {
content: '\f07a'; /* Unicode for FontAwesome shopping cart icon */
font-family: 'FontAwesome';
padding-right: 5px;
}
Method 5: Using a PNG or Animated GIF Image
Adding a PNG or animated GIF icon to your “Add to Cart” button can make it stand out and attract more clicks. Here’s how you can do it.
Step 1: Upload Your Icon
First, upload your PNG or GIF icon to your WordPress media library.
- Go to your WordPress Dashboard.
- Navigate to Media > Add New.
- Upload your icon file and copy its URL.
Step 2: Add CSS to Style the Button
Next, you need to add some CSS to display the icon in the button.
- Navigate to Appearance > Customize > Additional CSS.
- Add the following CSS code, replacing
your-icon-url.pngwith the URL of your uploaded icon:
/*
* Snippet: How to Add an Icon to the Add to Cart Buttons in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1351
* Tested with WooCommerce 10.7.0
* "Add icon to add to cart button using PNG or GIF"
*/
.add_to_cart_button::before,
.single_add_to_cart_button::before {
content: '';
display: inline-block;
background: url('your-icon-url.png') no-repeat center center;
background-size: contain;
width: 20px; /* Adjust the width as needed */
height: 20px; /* Adjust the height as needed */
margin-right: 5px;
}
Step 3: Save and Check
Save your changes and check your WooCommerce store. The “Add to Cart” buttons should now display your icon.
Conclusion
Adding an icon to the “Add to Cart” button in WooCommerce can significantly enhance the user experience and improve the visual appeal of your store. Whether you choose to use PHP, Dashicons, FontAwesome, or CSS, this guide provides multiple methods to achieve this customisation.
For more advanced customisations, always consider creating a child theme to protect your changes. Our free child theme generator can help you get started quickly.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

