Refresh the page after product remove from cart Woocommerce

瘦欲@ 提交于 2021-02-08 09:24:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!