Skip to content

Instantly share code, notes, and snippets.

@mpdevcl
Created August 11, 2020 17:43

Revisions

  1. mpdevcl created this gist Aug 11, 2020.
    44 changes: 44 additions & 0 deletions woocommerce_events.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    # WooCommerce JS Events
    [Source](https://wordpress.stackexchange.com/a/352171)

    ## Checkout
    ```
    $( 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' );
    ```

    ## Cart
    ```
    $( 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 ] );
    ```

    ## Single Product
    ```
    $( '.wc-tabs-wrapper, .woocommerce-tabs, #rating' ).trigger( 'init' );
    ```

    ## Add to Cart
    ```
    $( 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' );
    ```

    ## Add Payment Method
    ```
    $( document.body ).trigger( 'init_add_payment_method' );
    ```