Last active
October 28, 2024 06:19
-
-
Save bagerathan/2b57e7413bfdd09afa04c7be8c6a617f to your computer and use it in GitHub Desktop.
[Woocommerce Javascript events] #woo
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
//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' ); | |
}); |
Additional events that are useful for listening:
/***Single Product***/
$( document.body ).on( 'found_variation', function( event, variation ) {
console.log(variation);
});
//Same as above
$( document.body ).on( 'show_variation', function( event, variation ) {
console.log(variation);
});
//Not as useful but worth mentioning, fires whenever there is a change in the variation buttons
$( document.body ).on( 'woocommerce_variation_select_change', function( ) {
//Do something
});
/***Checkout***/
$( document.body ).on( 'applied_coupon_in_checkout', function( event, coupon ) {
console.log(coupon );
});
$( document.body ).on( 'removed_coupon_in_checkout', function( event, coupon ) {
console.log(coupon );
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to do something with the params in the function then here is an example