In Woocommerce, I Would like co create add to cart link on a simple page of WordPress website (not product page).
So I have tried this code (Where 123 is the product ID):
<a href="http://example.com/cart/?add-to-cart=123">Buy</a>
I have enabled AJAX add to cart on archives pages Woocommerce option setting.
But It doesn't work and Ajax functionality is not enabled on my custom Add-to-cart link.
How to enable ajax add-to-cart on a custom link (in other pages than woocommerce ones)?
I suggest you to use the
[add_to_cart]
Shortcode.Simplest usage with the default parameters:
Disables the default style and hides the price:
See some sample output
To enable ajax in a custom add to cart button, there is 3 ways at least:
A simple HTML Ajax add to cart link:
Using Woocommerce existing
[add_to_cart id='123']
shortcode (same usage than above)The most customizable: A custom shortcode without price included (customizable button text, additional classes, quantity and many others possibilities)
This code goes on function.php file of your active child theme (or theme). Tested and works.
USAGE:
In posts and pages text editor:
In PHP files or templates:
Inserted in HTML code on a php page:
I used this for my plugin and it is working fine:
for showing button: