It was a lightbulb moment for me when I learned (from this forum) the master template for a page such as '/shop/add-to-cart' can be just the function on its own. Makes for very snappy ajax calls.
If you're going to bother with ajax, may as well go all the way and update the cart item count too, as I'm doing above. I've basically "ajax-ified" a lot of shop functions this way, including emptying cart, product wish-list feature, shipping methods... all ajax calls. And why not? It's the best user experience and allows you to display nicely designed "done" messages, green ticks, loading spinners and whatever other pretty things people expect these days.
You can call
perch_shop_add_to_cart()
and pass in the IDYep, ajax works great.
It was a lightbulb moment for me when I learned (from this forum) the master template for a page such as '/shop/add-to-cart' can be just the function on its own. Makes for very snappy ajax calls.
Then on your product page your ajax might look something like...
If you're going to bother with ajax, may as well go all the way and update the cart item count too, as I'm doing above. I've basically "ajax-ified" a lot of shop functions this way, including emptying cart, product wish-list feature, shipping methods... all ajax calls. And why not? It's the best user experience and allows you to display nicely designed "done" messages, green ticks, loading spinners and whatever other pretty things people expect these days.