Skip to content

Instantly share code, notes, and snippets.

@brynzovskii
Forked from bagerathan/woo-events.js
Created March 29, 2022 06:05
Show Gist options
  • Save brynzovskii/c955e4f8e9237f915840c5c2054ac109 to your computer and use it in GitHub Desktop.
Save brynzovskii/c955e4f8e9237f915840c5c2054ac109 to your computer and use it in GitHub Desktop.
[Woocommerce Javascript events] #woo
//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' );
//Woocommerce cart page JS events
$( document.body ).trigger( 'wc_cart_emptied' );
$( document.body ).trigger( 'update_checkout' );
$( document.body ).trigger( 'updated_wc_div' );
$( document.body ).trigger( 'updated_cart_totals' );
$( document.body ).trigger( 'country_to_state_changed' );
$( document.body ).trigger( 'updated_shipping_method' );
$( document.body ).trigger( 'applied_coupon', [ coupon_code ] );
$( document.body ).trigger( 'removed_coupon', [ coupon ] );
//Woocommerce Single product page JS events
$( '.wc-tabs-wrapper, .woocommerce-tabs, #rating' ).trigger( 'init' );
//Woocommerce Add to cart JS events
$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
$( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
$( document.body ).trigger( 'removed_from_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
$( document.body ).trigger( 'wc_cart_button_updated', [ $button ] );
$( document.body ).trigger( 'cart_page_refreshed' );
$( document.body ).trigger( 'cart_totals_refreshed' );
$( document.body ).trigger( 'wc_fragments_loaded' );
//Woocommerce Add payment method JS events
$( document.body ).trigger( 'init_add_payment_method' );
//To bind listener to these events, use:
jQuery('<event_target>').on('<event_name>', function(){
console.log('<event_name> triggered');
});
//eg
$('body').on('change', '#billing_state', function(){
$( document.body ).trigger( 'update_checkout' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment