【发布时间】:2020-09-05 19:32:40
【问题描述】:
我已尝试使用此示例 (Dynamic information based on shipping method and cart total In Woocommerce),但是我的动态消息显示了两次。非常感谢任何帮助。
基本上我要做的是在用户的送货超出送货区域时显示一条消息(使用 WooCommerce 的“您的其他区域未覆盖的位置”送货区域)。仅当用户不在定义的运输区域中时,该消息才会正确显示 - 但它会加倍。一个似乎在 ajax 刷新之内,另一个似乎在它之外。不完全确定它是如何或为什么这样做的。
//add message to CHECKOUT if outside delivery area
add_action( 'woocommerce_review_order_after_shipping', 'outside_delivery_checkout', 20);
function outside_delivery_checkout() {
global $woocommerce;
if ( did_action( 'woocommerce_review_order_after_shipping' ) >= 2 ) {
return once;
}
$chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0];
$chosen_shipping_method = explode(':', $chosen_shipping_method_id)[0];
$cart_subtotal = WC()->cart->subtotal;
if ($cart_subtotal && $chosen_shipping_method === 'free_shipping') {
echo '<div class="outside-delivery checkout"><b>PLEASE NOTE:</b><br /> Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge. <strong>Please refresh the page after updating your shipping settings.</strong></div>';
} elseif ($cart_subtotal && $chosen_shipping_method != 'free_shipping') {
// do nothing
}
}
这里是问题的链接:https://redstarrolloffqc.com/dumpster-sizes-rates/ - 添加产品并转到结帐页面。
【问题讨论】:
标签: php html ajax wordpress woocommerce