List of JS events in the WooCommerce frontend

On a hunt for the same I took a little dive into the JS source files. Woocommerce Javascript events Woocommerce Checkout JS events $( document.body ).trigger( ‘init_checkout’ ); $( document.body ).trigger( ‘payment_method_selected’ ); $( document.body ).trigger( ‘update_checkout’ ); $( document.body ).trigger( ‘updated_checkout’ ); $( document.body ).trigger( ‘checkout_error’ ); $( document.body ).trigger( ‘applied_coupon_in_checkout’ ); $( document.body … Read more

Get the product list of a given Category ID

I suspect the main problem is that you should be using the WP_Query object rather than get_posts(). The later by default only returns items with a post_type of post not products, So given a category with ID 26, the following code would return it’s products (WooCommerce 3+): $args = array( ‘post_type’ => ‘product’, ‘post_status’ => … Read more

Woocommerce – Add a product to cart programmatically via JS or PHP [closed]

OK so here’s how I solved it in the end. A quick and dirty example, uses JQuery. <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 /wp/?post_type=product&add-to-cart=[PRODUCT_ID]