【发布时间】:2026-01-19 07:50:02
【问题描述】:
在我的客户 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 - 类是否在 dom 中,但我想出的解决方案没有成功。
有什么想法吗?
【问题讨论】:
标签: php jquery woocommerce