Enhanced AJAX Add to Cart for WooCommerce


This extension for WooCommerce allows you to render an AJAX button with an associated quantity field. Create effective and functional buttons to use for your or your customers convenience anywhere on your site you want!

Shortcode Documentation

New Shorter Shortcode: ajax_add_to_cart is now an option for enh_ajax_add_to_cart_button
The required field for every button is the product_id, with six optional fields:
– variation_id (used for variable products)
– title (to reflect the label before the button)
– quantity (sets the default quantity AND hides the quantity checkbox)
– show_quantity (if quantity is specified, re-enables the checkbox)
– show_price
– button_text

[enh_ajax_add_to_cart_button product_id={pid} variation_id={vid} show_price={beginning|b|after|a|rear|r} button_text={STRING} title={none|attributes|att|attribute} quantity={INTEGER} show_quantity={yes} ]

SIMPLE PRODUCT: Use only the required parameters to make a quantity box and add to cart button for a simple product with the title to the left:

[enh_ajax_add_to_cart_button product=42 ]

Refer to screenshot 1 below to see the output

VARIABLE PRODUCT: Use the product and variation parameters to make a quantity box and add to cart button for a specific variation of a variable product, with the fully qualified name:

[enh_ajax_add_to_cart_button product=3312 variation=3313 ]

Refer to screenshot 2 below to see the output

Use the product and variation parameters to make a quantity box and add to cart button for a specific variation of a variable product, with only the variation attributes listed separated with a space as the name:

[enh_ajax_add_to_cart_button product=3312 variation=3313 title=attributes ]

Refer to screenshot 3 below to see the output

Use the product and variation parameters to make a quantity box and add to cart button for a specific variation of a variable product, with no name listed:

[enh_ajax_add_to_cart_button product=3312 variation=3313 title=none ]

Refer to screenshot 4 below to see the output

Use the button_text parameter to change the text on the Add to Cart button! (Strips out HTML tags)
Use double quotes ( “like this” ) to get a phrase with spaces

[ajax_add_to_cart product=3312 variation=3313 button_text="Add this to cart!" ]

Use the show_price parameter to make a price field appear, with the options being before the title, after the title but before the quantity/add to cart button, or at the very rear of the line!


[ajax_add_to_cart product=3312 variation=3313 show_price=b ]

After Title

[ajax_add_to_cart product=3312 variation=3313 show_price=a ]

Rear (After Button)

[ajax_add_to_cart product=3312 variation=3313 show_price=r ]


  • Minimum parameter requirements for shortcode and output
  • Variable product shortcode parameters and output
  • Variable product variation only title (no product base name)
  • No title for quantity and button inputs


Minimum Requirements

  • PHP version 5.2.4 or greater (PHP 7.2 or greater is recommended)

Automated Installation

  1. Download, install and activate through the WP Admin panels plugin directory
  2. Enjoy!


Manual Installation

  1. Upload the entire /enhanced-ajax-add-to-cart-wc directory to the /wp-content/plugins/ directory.
  2. Activate WooCommerce Cost of Shipping through the ‘Plugins’ menu in WordPress.
  3. Enjoy the easy input of the flexible AJAX add to cart buttons on any page on your site!


Can I put multiple words on the button?

Shortcode: By using the button_text parameter using double quotes around your phrase. button_text=”quickly add this product!”

How can I change the separator between the price and the button or text?

There is a CSS selector available for changing the separator for the plugin as a whole. You can put this in your themes styles.css or “Additional CSS” section of theme customizer
The default is shown below. To change the character, change the content value from ” – ” to whatever you see fit. Leave blank quotes for removing it all together (e.g. content: “”;)

.ea-separator::before {
    content: " - ";
Does this work for variable products?

Yes! To use variable products, you must specify both the product id and the variation id in the shortcode parameters.

Can there be multiple ajax buttons on the same page?

Yes! You can only safely do the same variation of a variable product once on the same page, or one simple (of the same product) product button on the same page. The reason being, the JavaScript used to pass the quantity to the server is using either the variation id or the product id (respectively) to find which quantity box should be used.

Does this replace the add to cart button on product pages or archives?

At this point, no. This is designed to supplement your store to let the buttons be anywhere.


June 28, 2020
This plugin works as it says without any problem. I would like to thank the developer for making my life easier! This plugin can be created to display product information, quantity button and add to cart - easy to customise.
January 27, 2020
This plugin has proven to be a lifesaver and a massive convenience for adding product add to cart buttons anywhere on your site. Extremely easy to use and to implement as well as customize. Thank you so much to the developer. I hope that the plugin gains more usage. Please continue to update the plugin and support as well as you have done thus far.
June 20, 2019
Developer went above and beyond to sort out an issue with the plugin. The functionality this plugin provides should of been standard in woocommerce. Keep up the great work! 🙂
Read all 8 reviews

Contributors & Developers

“Enhanced AJAX Add to Cart for WooCommerce” is open source software. The following people have contributed to this plugin.




  • Fixed bug where currency positioning was not taking effect from WooCommerce settings.


  • Added button blocking using the disabled html parameter. This prevents requests being skipped when many buttons pressed within short time.
  • Tweaked how assets are enqueued to only enqueue on pages when the shortcode is on it. This prevents overriding the AJAX setting in WooCommerce settings page.
  • Fixed bug where variation was showing with parent product default cost. Now shows correct variation price.


  • Added feature where when product is out of stock the add to cart button displays as “out of stock” instead.


  • Fixed bug when using shortcodes in blocks – blocks try to run shortcode earlier than classic editor.


  • Fixed bug when quantity input was hidden the add to cart button was no longer working.


  • Changed how javascript selector worked for grabbing quantity from input. Only a bug in custom implementations around this plugin.


  • Added class names to spans around ajax button title lines to allow for better styling
  • Added new span around separator to allow for customized styling
  • Fixed minor bug in how javascript files are enqueued to support themes that selectively enqueue WooCommerce assets
  • Fixed bug when same product is on the same page, only one quantity field was working


  • Added way to display price alongside button or quantity box or at the beginning of the line
  • Added shorter shortcode name
  • Added a way to change the text on the add to cart button


  • Fixed bug where non-logged in users were not able to add multiple products to cart, especially on mobile.


  • Fixed bug where minimized javascript entry point was using the wrong location


  • Added notices to show if and why a product could not be added to cart
  • Added minimized JavaScript files and enqueued if file exists
  • Added some debugging tools and constant
  • Added security nonces
  • Fixed bug where on some browsers the event of clicking a button would trigger a page reload
  • Tweaked how AJAX is enqueued in the plugin
  • Tweaked files to take out unnecessary lines and repeated words
  • Tested for new versions of WooCommerce and WordPress


  • Fixed bug that unnecessarily changed the global product on variable product pages
  • Added action to allow ajax buttons for non-logged in users
  • Changed styling of title slightly


  • Added feature to be able to hide the quantity input box
  • Added feature to be able to change the default quantity


  • Updated readme.txt


  • First release
  • Creates shortcode to create AJAX add to cart button for simple and variable products
  • Shortcode allows for title to be fully qualified product name (including variation attributes)
  • Shortcode allows for title to be only the variation attributes
  • Shortcode allows for title to be hidden
  • Shortcode associates quantity with AJAX button