OK so here’s how I solved it in the end. A quick and dirty example, uses JQuery.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<a id="buy" href="#">Buy this!</a> <script> $('#buy').click(function(e) { e.preventDefault(); addToCart(19); return false; }); function addToCart(p_id) { $.get('/wp/?post_type=product&add-to-cart=' + p_id, function() { // call back }); } </script> |
This just makes an AJAX GET request to the cart url
1 |
/wp/?post_type=product&add-to-cart=[PRODUCT_ID] |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.