【发布时间】:2019-03-15 18:40:35
【问题描述】:
在 woocommerce 中,我需要根据送货区域在购物车或结帐页面上显示自定义消息,例如“您将为此邮政编码支付 10% 的费用”。
我觉得这很容易,但我不能让它工作!它让我发疯! 任何帮助表示赞赏。
我的解决方法是自定义这种默认消息:
add_filter( 'woocommerce_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
// For Checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
function wf_customize_default_message( $default_msg ) {
$zip_array = array(
'30031',
);
if ( in_array( WC()->customer->get_shipping_postcode() , $zip_array) ) {
$custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
if( empty( $custom_msg ) ) {
return $default_msg;
}
return $custom_msg;
}
return $default_msg;
}
【问题讨论】:
-
大家好,我忘了:)
-
嗨 Loic,感谢您的快速回答。我尚未测试您的代码,但是否可以将您的示例调整到我为我创建的一种运输方式创建的运输区域? + 我有很多邮政编码要添加,而不仅仅是一个...非常感谢您的帮助!
-
嗨,Loic,我不明白,我看不到你的第一个答案?
-
对不起,我想你已经删除了你的答案……你能再发一次吗?
-
我已经做出了不同的回答……更方便……如果用户更改送货区域,则在结帐时使用 woocommerce 通知将不起作用。
标签: php wordpress woocommerce shipping notice