{"id":15183,"date":"2025-09-30T15:03:52","date_gmt":"2025-09-30T15:03:52","guid":{"rendered":"https:\/\/www.kadencewp.com\/help-center\/?post_type=docs&#038;p=15183"},"modified":"2026-04-22T15:22:10","modified_gmt":"2026-04-22T15:22:10","password":"","slug":"track-woocommerce-cart-actions-with-javascript","status":"publish","type":"docs","link":"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-theme\/track-woocommerce-cart-actions-with-javascript\/","title":{"rendered":"How to Track WooCommerce Cart Actions with JavaScript"},"content":{"rendered":"\n<p>Tracking customer interactions in your WooCommerce store can provide valuable insight into how shoppers engage with your products. Two of the most important actions to monitor are when a customer <strong>adds an item<\/strong> to the cart and when they <strong>remove an item<\/strong>. This guide will show you how to capture these events using <strong>JavaScript<\/strong>, so you can connect them to your analytics, trigger marketing automations, or run custom scripts based on user behavior.<\/p>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15183_f29712-fa, .wp-block-kadence-advancedheading.kt-adv-heading15183_f29712-fa[data-kb-block=\"kb-adv-heading15183_f29712-fa\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15183_f29712-fa mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15183_f29712-fa[data-kb-block=\"kb-adv-heading15183_f29712-fa\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading15183_f29712-fa img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15183_f29712-fa[data-kb-block=\"kb-adv-heading15183_f29712-fa\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h2 class=\"kt-adv-heading15183_f29712-fa wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15183_f29712-fa\">Tracking Add To Cart Events<\/h2>\n\n\n\n<p>This script will add a listener for the WooCommerce&#8217;s <em><strong>add_to_cart<\/strong><\/em> event.  In this example, the script simply sends text to the console log.  You&#8217;ll want to replace that with your custom functionality.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">jQuery( function( $ ) {\n\t$( document.body ).on( 'added_to_cart', function( event, fragments, cart_hash, button ) {\n\t\t\/\/ Add your custom script here\n\t\tconsole.log('Item added to cart');\n\t});\n});<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15183_9f572f-3a, .wp-block-kadence-advancedheading.kt-adv-heading15183_9f572f-3a[data-kb-block=\"kb-adv-heading15183_9f572f-3a\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15183_9f572f-3a mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15183_9f572f-3a[data-kb-block=\"kb-adv-heading15183_9f572f-3a\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading15183_9f572f-3a img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15183_9f572f-3a[data-kb-block=\"kb-adv-heading15183_9f572f-3a\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h2 class=\"kt-adv-heading15183_9f572f-3a wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15183_9f572f-3a\">Tracking Remove From Cart Events<\/h2>\n\n\n\n<p>Similar to the above example, this script will add a listener for the WooCommerce&#8217;s <em><strong>removed_from_cart<\/strong><\/em> event.  You&#8217;ll also want to replace the console.log function with your own custom functionality.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">jQuery( function( $ ) {\n\t$( document.body ).on( 'removed_from_cart', function( event, fragments, cart_hash, button ) {\n\t\t\/\/ Add your custom script here\n\t\tconsole.log('Item removed from cart');\n    });\n});<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15183_09b79d-83, .wp-block-kadence-advancedheading.kt-adv-heading15183_09b79d-83[data-kb-block=\"kb-adv-heading15183_09b79d-83\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15183_09b79d-83 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15183_09b79d-83[data-kb-block=\"kb-adv-heading15183_09b79d-83\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading15183_09b79d-83 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15183_09b79d-83[data-kb-block=\"kb-adv-heading15183_09b79d-83\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h2 class=\"kt-adv-heading15183_09b79d-83 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15183_09b79d-83\">Conclusion<\/h2>\n\n\n\n<p><br>Tracking add-to-cart and remove-from-cart actions helps you understand how customers interact with your store. With these simple JavaScript events, you can capture key actions and use the data to improve your analytics tracking and marketing efforts.<\/p>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15183_c759f5-97, .wp-block-kadence-advancedheading.kt-adv-heading15183_c759f5-97[data-kb-block=\"kb-adv-heading15183_c759f5-97\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15183_c759f5-97 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15183_c759f5-97[data-kb-block=\"kb-adv-heading15183_c759f5-97\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading15183_c759f5-97 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15183_c759f5-97[data-kb-block=\"kb-adv-heading15183_c759f5-97\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15183_c759f5-97 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15183_c759f5-97\">See Also:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-theme\/how-to-add-scripts-in-header-footer\/\">How to add scripts in header\/footer<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-guides\/how-to-use-custom-css-and-scripts-using-kadence\/\">How to use Custom CSS and Scripts using Kadence<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-theme\/how-to-add-a-custom-filter-or-function-with-code-snippets\/\">How to add a custom filter or function with Code Snippets<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Tracking customer interactions in your WooCommerce store can provide valuable insight into how shoppers engage with your products. Two of the most important actions to monitor are when a customer adds an item to the cart and when they remove an item. This guide will show you how to capture these events using JavaScript, so&#8230;<\/p>\n","protected":false},"author":227588,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"doc_category":[409],"doc_tag":[],"knowledge_base":[6],"class_list":["post-15183","docs","type-docs","status-publish","hentry","doc_category-theme-woocommerce","knowledge_base-kadence-theme"],"year_month":"2026-04","word_count":265,"total_views":"1887","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"display_name":"Anthony Paparelli","author_link":"https:\/\/www.kadencewp.com\/help-center\/author\/anthony-paparelli\/"},"doc_category_info":[{"term_name":"Woocommerce","term_url":"https:\/\/www.kadencewp.com\/help-center\/knowledge-base\/kadence-theme\/theme-woocommerce\/"}],"doc_tag_info":[],"knowledge_base_info":[{"term_name":"Kadence Theme","term_url":"https:\/\/www.kadencewp.com\/help-center\/knowledge-base\/kadence-theme\/","term_slug":"kadence-theme"}],"knowledge_base_slug":["kadence-theme"],"taxonomy_info":{"doc_category":[{"value":409,"label":"Woocommerce"}],"knowledge_base":[{"value":6,"label":"Kadence Theme"}]},"featured_image_src_large":false,"comment_info":0,"_links":{"self":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/users\/227588"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/comments?post=15183"}],"version-history":[{"count":3,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15183\/revisions"}],"predecessor-version":[{"id":15186,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15183\/revisions\/15186"}],"wp:attachment":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/media?parent=15183"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_category?post=15183"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_tag?post=15183"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/knowledge_base?post=15183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}