产品从购物车中删除后刷新页面Woocommerce [英] Refresh the page after product remove from cart Woocommerce
本文介绍了产品从购物车中删除后刷新页面Woocommerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在woocommerce中面临这个问题.当我们从购物车中删除产品时,禁用更新购物车按钮.并且刷新页面工作正常之后.
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.
推荐答案
在最新版本的Woocommerce中,有一个JavaScript回调触发器可用,如
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' );
};
因此,您可以添加一段Javascript在触发该触发器时运行,并启用按钮或仅刷新页面.例如:
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.
});
这篇关于产品从购物车中删除后刷新页面Woocommerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文