1

我在woocommerce中面临这个问题。当我们从购物车中删除产品时,更新购物车按钮被禁用。刷新页面后工作正常。

我正在尝试这个钩子:

woocommerce_cart_item_removed

但它不工作没有回报。

4

1 回答 1

1

在最新版本的 Woocommerce 中,有一个 JavaScript 回调触发器可用,如本次提交中所述:

/**
 * 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 以在触发此触发器并启用按钮或简单地刷新页面时运行。例如:

$('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.
});
于 2016-08-25T10:04:03.093 回答