• Hello!

    When a user clicks on the “Remove item” link of the “Cart Line Items” block from the WooCommerce Blocks plugin, the javascript event wc_cart_emptied is not being fired.

    When you use WooCommerce out of the box, this javascript is fired when you remove everything from your cart on the cart page. I really think this javascript event should be fired, but is there an alternative? I haven’t found anything on the documentation.

    Thanks in advance for your help! (And hopefully you could implement this or a similar javascript event on the plugin).

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Nadir Seghir

    (@assassinateur)

    Hey! we don’t have an event for when the cart is fully emptied. We have events for when an item is removed:

    1. WordPress JS action via wp.hooks.addAction and experimental__woocommerce_blocks-cart-remove-item action.

    
    wp.hooks.addAction(
    	'experimental__woocommerce_blocks-cart-remove-item',
    	'my-plugin-namespace',
    	() => {
    		console.log( 'AddAction event' );
    	}
    );
    

    2. Subscribe to the wc/store/cart data store and listen to the content of Cart and when it’s emptied (not recommended for performance reasons).

    
    wp.data.subscribe( () => {
    	const { getCartData } = wp.data.select( 'wc/store/cart' );
    	const { items } = getCartData();
    	if ( items.length === 0 ) {
    		// your logic
    	};
    });
    
    • This reply was modified 3 years, 4 months ago by Nadir Seghir.
    Thread Starter Aaron Barraza

    (@aebs90)

    Thanks for your reply Nadir.

    experimental__woocommerce_blocks-cart-remove-item is useful, but that’s fired at the beggining of the remove item process, before the AJAX call is made. It would be really helpful if you could add an event after the AJAX call is done. Do you think that’s possible on a future version?

    It’s certainly possible. I’d suggest you open an issue on the repo or better yet, submit a PR. https://github.com/woocommerce/woocommerce-gutenberg-products-block

    Plugin Author Nadir Seghir

    (@assassinateur)

    If it’s happening at the beginning of the request, then it’s possibly a bug.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘“wc_cart_emptied” javascript event not being fired’ is closed to new replies.