在我的客户WooCommerce网站上,我们运行一个脚本来强制在购物车页面上计算运费:
add_action('wp_head','prevent_proceed_to_checkout');
function prevent_proceed_to_checkout() {
echo ' <script>
jQuery(function(){
jQuery(".woocommerce-cart .wc-proceed-to-checkout a.checkout-button").on("click",function(e){
var _this = this;
alert("Bitte berechne die Versandkosten!");
e.preventDefault();
jQuery(".shipping-calculator-form .button").on("click",function(){
jQuery(_this).off();
});
});
});
</script>';
}
我需要更改此设置,以便在购物车中没有实体产品时不执行该操作。我尝试使用JavaScript来检查.woocommerce-shipping-totals-class是否在dom中,但我提出的解决方案未成功。
有什么想法吗?
答案 0 :(得分:0)
我现在通过在onclick函数中添加一个if语句来解决此问题,该语句基本上会检查单击结帐按钮后是否在页面上显示“ .woocommerce-shipping-totals”类。这是我添加的代码:(在警报之前)
var shipping = document.getElementsByClassName("woocommerce-shipping-totals").length;
if (shipping > 0) {