Php 基于两次显示装运方式的动态信息
我已经尝试从这个示例()开始工作,但是我的动态消息显示了两次。非常感谢您的帮助 基本上,我试图做的是,如果用户的配送不在配送区域(使用WooCommerce的“其他区域未覆盖的位置”配送区域),则显示一条消息。只有当用户不在已定义的装运区时,消息才会正确显示,但它会加倍显示。一个似乎在ajax刷新中,另一个似乎在它之外。不太清楚它是如何或为什么这样做的Php 基于两次显示装运方式的动态信息,php,html,ajax,wordpress,woocommerce,Php,Html,Ajax,Wordpress,Woocommerce,我已经尝试从这个示例()开始工作,但是我的动态消息显示了两次。非常感谢您的帮助 基本上,我试图做的是,如果用户的配送不在配送区域(使用WooCommerce的“其他区域未覆盖的位置”配送区域),则显示一条消息。只有当用户不在已定义的装运区时,消息才会正确显示,但它会加倍显示。一个似乎在ajax刷新中,另一个似乎在它之外。不太清楚它是如何或为什么这样做的 //add message to CHECKOUT if outside delivery area add_action( 'woocomme
//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
}
}
//如果在交付区域之外,则将邮件添加到签出
添加操作('woocommerce\u review\u order\u after\u shipping','outside\u delivery\u checkout',20);
功能在交付和签出之外(){
全球商业;
如果(did行动('WOOCOMERCESS'在装运后审查订单')>=2){
返回一次;
}
$selected_shipping_methods_id=WC()->session->get('selected_shipping_methods')[0];
$selected_shipping_method=explode(“:”,$selected_shipping_method_id)[0];
$cart\u subtotal=WC()->cart->subtotal;
如果($cart\u小计&&$selected\u shipping\u method==='free\u shipping'){
echo'请注意:
您的配送目的地在我们的正常配送区域之外。我们的团队将致电您计算额外的燃油附加费。请在更新您的配送设置后刷新页面。;
}其他($cart\u小计和$selected\u shipping\u方法!='free\u shipping'){
//无所事事
}
}
这里是问题的链接:-添加产品并转到结帐页面。这里的主要问题是,您试图在关闭
html标记后,在html
内插入带有某些内容的标记
因此,显示的Html会中断,即使看起来不是这样
相反,您应该使用以下html结构:
<tr><td colspan="2"><div>Your formatted text (message)</div></td></tr>
代码进入活动子主题(或活动主题)的functions.php文件。经过测试,效果良好。非常感谢您!这很有魅力。位置不同,但这对我来说并不重要。荣誉@Trisha配送后,woocommerce\u review\u order\u的实际位置是动作挂钩的位置,
action hook…您可以在相关模板中看到这一点。
//add message to CHECKOUT if outside delivery area
add_action( 'woocommerce_review_order_after_shipping', 'outside_delivery_checkout', 20);
function outside_delivery_checkout() {
$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' ) {
$html = '<tr class="delivery-message"><td colspan="2"><div class="outside-delivery checkout">
<strong>' . __("PLEASE NOTE:") . '</strong><br />';
$html .= __("Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.");
$html .= ' <strong>' . __("Please refresh the page after updating your shipping settings.") . '</strong>';
echo $html . '</div></td></tr>';
}
}