Tracking how often customers click the “Add to Cart” button in WooCommerce can provide valuable insights into product performance and customer behaviour. By counting these clicks, you can gauge interest in specific products, identify potential issues with the purchasing process, and improve your store’s overall conversion rate. This guide will show you how to count clicks of the “Add to Cart” button in WooCommerce without using a plugin.
Why Count Add to Cart Clicks?
Counting “Add to Cart” clicks offers several benefits:
- Conversion Rate Analysis: Understand the ratio of clicks to completed purchases, identifying potential drop-off points.
- Product Interest: Measure customer interest in specific products, even if they don’t end up buying them.
- UX Improvements: Identify if there are any usability issues in the cart or checkout process.
- Marketing Insights: Tailor marketing strategies based on customer interactions with different products.
Step 1: Add JavaScript to Count Clicks
To count clicks on the “Add to Cart” button, you will need to add a JavaScript snippet that listens for click events and sends this data to your server. Add the following code to your theme’s functions.php file:
/*
* Snippet: How to Count Clicks of the Add to Cart Button in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1301
* Tested with WooCommerce 10.7.0
* "Add JavaScript to count add to cart clicks"
*/
function wcsuccess_add_to_cart_click_counter_script() {
if (is_product()) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.single_add_to_cart_button').on('click', function() {
var product_id = $(this).val();
$.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'POST',
data: {
action: 'wcsuccess_count_add_to_cart_click',
product_id: product_id
},
success: function(response) {
console.log('Add to Cart Click Counted');
}
});
});
});
</script>
<?php
}
}
add_action('wp_footer', 'wcsuccess_add_to_cart_click_counter_script');
Step 2: Handle the AJAX Request in PHP
Next, create a function to handle the AJAX request and increment the click count for the product. Add the following code to your theme’s functions.php file:
/*
* Snippet: How to Count Clicks of the Add to Cart Button in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1301
* Tested with WooCommerce 10.7.0
* "Handle AJAX request and increment click count"
*/
function wcsuccess_count_add_to_cart_click() {
if (isset($_POST['product_id'])) {
$product_id = intval($_POST['product_id']);
$click_count = get_post_meta($product_id, '_wcsuccess_add_to_cart_click_count', true);
if (!$click_count) {
$click_count = 0;
}
$click_count++;
update_post_meta($product_id, '_wcsuccess_add_to_cart_click_count', $click_count);
wp_send_json_success();
}
}
add_action('wp_ajax_wcsuccess_count_add_to_cart_click', 'wcsuccess_count_add_to_cart_click');
add_action('wp_ajax_nopriv_wcsuccess_count_add_to_cart_click', 'wcsuccess_count_add_to_cart_click');
Step 3: Display the Click Count in the Product Admin
To view the click count for each product, add a custom column to the WooCommerce products admin screen. Add the following code to your theme’s functions.php file:
/*
* Snippet: How to Count Clicks of the Add to Cart Button in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1301
* Tested with WooCommerce 10.7.0
* "Add custom column for click count"
*/
function wcsuccess_add_click_count_column($columns) {
$columns['add_to_cart_click_count'] = 'Add to Cart Clicks';
return $columns;
}
add_filter('manage_edit-product_columns', 'wcsuccess_add_click_count_column');
function wcsuccess_display_click_count_column($column, $post_id) {
if ($column === 'add_to_cart_click_count') {
$click_count = get_post_meta($post_id, '_wcsuccess_add_to_cart_click_count', true);
echo $click_count ? $click_count : '0';
}
}
add_action('manage_product_posts_custom_column', 'wcsuccess_display_click_count_column', 10, 2);
Use Cases for Counting Add to Cart Clicks
- Conversion Rate Optimisation: By tracking how many customers click “Add to Cart” versus how many complete their purchase, you can calculate the conversion rate and identify potential areas for improvement.
- Product Interest Analysis: If a product has a high number of add-to-cart clicks but a low number of purchases, it may indicate issues with pricing, product descriptions, or customer confidence.
- User Experience Improvements: Understanding user behaviour at this stage can help you streamline the cart and checkout process, making it easier for customers to complete their purchase.
- Marketing Strategies: Products with high click rates can be promoted more aggressively, while those with low click rates can be re-evaluated for potential issues or enhancements.
- Inventory Management: Track which products are getting the most attention to better manage stock levels and anticipate demand.
Conclusion
Tracking “Add to Cart” clicks in WooCommerce provides valuable insights into customer behaviour and product performance. By following the steps outlined above, you can implement a system to count these clicks and use the data to enhance your store’s performance. Whether it’s optimising conversion rates, improving user experience, or refining marketing strategies, this feature is a powerful tool for any WooCommerce store owner.
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

