在 WooCommerce 电子邮件通知中隐藏本地取货的送货地址
Hide shipping address on local pickup in WooCommerce email notifications
如果选择 "Local Pickup",如何隐藏客户处理电子邮件中的 "Shipping Address" 信息部分?
我不知道如何为此提供代码。
有可能 (请参阅本页底部的更新) …
overriding WooCommerce templates (copying the WooCommerce plugin templates
folder to your active child theme or theme, renaming it woocommerce
).
For that please be sure to read the related docs First.
以上正确完成后,您必须编辑位于活动子主题或主题中 woocommerce
文件夹中的 2 个模板。这些文件位于:
emails
(sub folder)
> email-addresses.php
(php file)
.
从第 19 行替换此模板的代码 :
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">
<tr>
<td class="td" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
<h3><?php _e( 'Billing address', 'woocommerce' ); ?></h3>
<p class="text"><?php echo $order->get_formatted_billing_address(); ?></p>
</td>
<?php // ======================> Here begins the customization
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
}
// End
if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) : ?>
<td class="td" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
<h3><?php _e( 'Shipping address', 'woocommerce' ); ?></h3>
<p class="text"><?php echo $shipping; ?></p>
</td>
<?php endif; ?>
</tr>
</table>
emails
(sub folder)
> plain
(sub folder)
> email-addresses.php
(php file)
.
从第 19 行替换此模板的代码 :
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
echo "\n" . strtoupper( __( 'Billing address', 'woocommerce' ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $order->get_formatted_billing_address() ) . "\n";
// ======================> Here begins the customization
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
} // End
if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) {
echo "\n" . strtoupper( __( 'Shipping address', 'woocommerce' ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $shipping ) . "\n";
}
我刚刚添加了这个来检测何时在订单中使用了Local Pickup:
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
}
并且在现有的if
语句中停止显示送货地址(本地取件):
&& !$shipping_local_pickup
Update: Is possible to use a much more compact code using the ** WC_Abstract_Order class - has_shipping_method()
** method this way:
$shipping_local_pickup = false;
if ( $order->has_shipping_method( 'local_pickup' ) )
$shipping_local_pickup = true;
And this in the existing if
statement to stop the display of shipping address (for Local Pickup):
&& !$shipping_local_pickup
参考文献:
如果选择 "Local Pickup",如何隐藏客户处理电子邮件中的 "Shipping Address" 信息部分?
我不知道如何为此提供代码。
有可能 (请参阅本页底部的更新) …
overriding WooCommerce templates (copying the WooCommerce plugin
templates
folder to your active child theme or theme, renaming itwoocommerce
).
For that please be sure to read the related docs First.
以上正确完成后,您必须编辑位于活动子主题或主题中 woocommerce
文件夹中的 2 个模板。这些文件位于:
emails
(sub folder)
>email-addresses.php
(php file)
.
从第 19 行替换此模板的代码 :
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">
<tr>
<td class="td" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
<h3><?php _e( 'Billing address', 'woocommerce' ); ?></h3>
<p class="text"><?php echo $order->get_formatted_billing_address(); ?></p>
</td>
<?php // ======================> Here begins the customization
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
}
// End
if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) : ?>
<td class="td" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
<h3><?php _e( 'Shipping address', 'woocommerce' ); ?></h3>
<p class="text"><?php echo $shipping; ?></p>
</td>
<?php endif; ?>
</tr>
</table>
emails
(sub folder)
>plain
(sub folder)
>email-addresses.php
(php file)
.
从第 19 行替换此模板的代码 :
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
echo "\n" . strtoupper( __( 'Billing address', 'woocommerce' ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $order->get_formatted_billing_address() ) . "\n";
// ======================> Here begins the customization
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
} // End
if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) {
echo "\n" . strtoupper( __( 'Shipping address', 'woocommerce' ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $shipping ) . "\n";
}
我刚刚添加了这个来检测何时在订单中使用了Local Pickup:
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
}
并且在现有的if
语句中停止显示送货地址(本地取件):
&& !$shipping_local_pickup
Update: Is possible to use a much more compact code using the ** WC_Abstract_Order class -
has_shipping_method()
** method this way:$shipping_local_pickup = false; if ( $order->has_shipping_method( 'local_pickup' ) ) $shipping_local_pickup = true;
And this in the existing
if
statement to stop the display of shipping address (for Local Pickup):&& !$shipping_local_pickup
参考文献: