Skip to content

Instantly share code, notes, and snippets.

@rolandinsh
Created January 16, 2013 17:26
Show Gist options
  • Save rolandinsh/4548975 to your computer and use it in GitHub Desktop.
Save rolandinsh/4548975 to your computer and use it in GitHub Desktop.
WooCommerce: Add a product to cart programmatically via JS or PHP
<!--
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>
@felipemarques
Copy link

not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment