Created
January 16, 2013 17:26
-
-
Save rolandinsh/4548975 to your computer and use it in GitHub Desktop.
WooCommerce: Add a product to cart programmatically via JS or PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
source: http://wordpress.stackexchange.com/a/53516/7577 | |
--> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what should i write instead of wp in below line
/wp/?post_type=product&add-to-cart='