问题
I am facing this issue in woocommerce. When product us removed from the cart, then update cart button disabled. And after the refresh page is working fine.
I am trying this hook:
woocommerce_cart_item_removed
But its not working return nothing.
回答1:
In the latest versions of Woocommerce there is a JavaScript callback trigger available as described in this commit:
/**
* Update the .cart_totals div with a string of html.
*
* @param {String} html_str The HTML string with which to replace the div.
*/
var update_cart_totals_div = function( html_str ) {
$( '.cart_totals' ).replaceWith( html_str );
$( document.body ).trigger( 'updated_cart_totals' );
};
So you can add a piece of Javascript to run when this trigger is fired and enable the button or simply refresh the page. For example:
$('body').on('updated_cart_totals',function() {
$( '.shop_table.cart' ).closest( 'form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', false ); // this will enable the button.
//location.reload(); // uncomment this line to refresh the page.
});
来源:https://stackoverflow.com/questions/38560342/refresh-the-page-after-product-remove-from-cart-woocommerce