首页 > 解决方案 > woocommerce js 事件无法按预期工作

问题描述

我用:

$(document.body).on('updated_cart_totals', function() {
  $('.woocommerce a#my_remove').css({
    'background-color': randCol
  });
  quantSpinner();
  //console.log('updated_cart_totals');
});

$(document.body).on('wc_cart_emptied', function() {
  $('a.restore-item').css({
    'color': randCol
  });
  //console.log('cart emptied: catches when last item is removed');
});

他们按预期工作。

但是,当从购物车中删除商品时,以下内容不会执行任何操作:

$(document.body).on('removed_from_cart', function() {
  console.log('removed_from_cart');
});

下一个测试也是否定的,当加载结帐页面时,控制台中没有任何反应:

$(document.body).on('update_checkout', function() {
  console.log('init_checkout');
});

知道如何正确捕捉这些事件吗?

标签: jquerywoocommerce

解决方案


对于结帐页面,以下效果很好:

$(document.body).on('updated_checkout', function() {
  console.log('updated_checkout');
  $('#payment a').css({
    'color': randCol
  });
});

之前的“removed_from_cart”无关紧要。问题解决了。


推荐阅读