检查Woocommerce中是否已选中“发送至其他地址”
问题描述:
在WwooCommerce中,我试图将该邮轮添加到我的管理员电子邮件中的不同地址信息中。检查Woocommerce中是否已选中“发送至其他地址”
如何检查从结帐页面运送到不同地址的复选框是否被选中?
我试着使用:
$ship_to_different_address = get_option('woocommerce_ship_to_destination') === 'shipping' ? 1 : 0;
if($ship_to_different_address == 1):
//the additional email text here
endif;
但这似乎不工作。有任何想法吗?
答
可能是最好的办法就是仿效它比较订单的结算和送货地址。在大多数可用的相关电子邮件通知挂钩中,$order
对象作为参数包含在内。
下面是使用此功能在woocommerce_email_order_details
行动挂钩钩住,将显示不同的东西取决于一个例子:
add_action('woocommerce_email_order_details', 'custom_content_email_order_details', 10, 4);
function custom_content_email_order_details($order, $sent_to_admin, $plain_text, $email){
// Only for "New Order" and admin email notification
if ('new_order' != $email->id && ! $sent_to_admin) return;
// Displaying something related
if($order->get_billing_address_1() != $order->get_shipping_address_1()) {
echo '<p style="color:red;">Different billing and shipping addresses<p>';
} else {
echo '<p style="color:green;">Same billing and shipping addresses<p>';
}
}
代码放在您的活动子主题的function.php文件(或主题)还是在任何插件文件中。
这个代码在WooCommerce 3.1+测试和工程
您也可以使用(不同的优先级)任何在此代码如下挂钩:
-woocommerce_email_before_order_table
-woocommerce_email_after_order_table
-woocommerce_email_order_meta
-woocommerce_email_customer_details
答
啊啊啊..我们可以只检查是否$_POST['ship_to_different_address']
设置..