2017-10-06 105 views
1

在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; 

但這似乎不工作。有任何想法嗎?

回答

3

可能是最好的辦法就是仿效它比較訂單的結算和送貨地址。在大多數可用的相關電子郵件通知掛鉤中,$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

2

啊啊啊..我們可以只檢查是否$_POST['ship_to_different_address']設置..

相關問題