在 WooCommerce 电子邮件通知中隐藏本地取货的送货地址 [英] Hide shipping address on local pickup in WooCommerce email notifications

查看:22
本文介绍了在 WooCommerce 电子邮件通知中隐藏本地取货的送货地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择本地取件",您如何隐藏客户处理电子邮件中的送货地址"信息部分?

我不知道如何为此提供代码.

解决方案

是的,这是可能的 (请参阅本页底部的更新) ...

<块引用>

覆盖 WooCommerce 模板(复制 WooCommerce 插件templates 文件夹添加到您的活动子主题或主题,将其重命名为 woocommerce).
为此,请请务必阅读相关文档 <强>第一.

正确完成上述操作后,您必须编辑位于活动子主题或主题内的 woocommerce 文件夹中的 2 个模板.文件位于:

  1. emails (子文件夹) > email-addresses.php (php文件).

    替换此模板的代码第 19 行:

if ( !defined( 'ABSPATH' ) ) {出口;}?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;"边界=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('账单地址', 'woocommerce');?></h3><p class="text"><?php echo $order->get_formatted_billing_address();?></p></td><?php//========================>下面开始定制$shipping_local_pickup = false;如果 ( $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;}}//结尾如果 (!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('收货地址', 'woocommerce');?></h3><p class="text"><?php echo $shipping;?></p></td><?php endif;?></tr>

  1. emails (子文件夹) > plain (子文件夹) > email-addresses.php (php 文件).

    替换此模板的代码第 19 行:

if ( !defined( 'ABSPATH' ) ) {出口;}回声 "\n" .strtoupper( __( 'Billing address', 'woocommerce' ) ) ."\n\n";echo preg_replace( '#<br\s*/?>#i', "\n", $order->get_formatted_billing_address() ) ."\n";//======================>下面开始定制$shipping_local_pickup = false;如果 ( $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;}}//结尾如果 (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) {回声 "\n" .strtoupper( __( '送货地址', 'woocommerce' ) ) ."\n\n";echo preg_replace( '#<br\s*/?>#i', "\n", $shipping ) ."\n";}

<小时>

我刚刚添加了这个来检测订单中何时使用本地取货:

$shipping_local_pickup = false;如果 ( $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

<小时><块引用>

更新:可以使用** WC_Abstract_Order 类 - has_shipping_method()** 方法 这样:

$shipping_local_pickup = false;if ( $order->has_shipping_method( 'local_pickup' ) )$shipping_local_pickup = true;

并且在现有的if语句中停止显示送货地址(用于本地取货):

&&!$shipping_local_pickup

<小时>

参考资料:

How do you hide the "Shipping Address" info section in the customers' processing email if "Local Pickup" is chosen?

I don't know how to provide code for this.

解决方案

Yes it's possible (see the update at the bottom of this page)

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.

Once above correctly done, you have to edit 2 templates located in that woocommerce folder inside your active child theme or theme. the files are located in:

  1. emails (sub folder) > email-addresses.php (php file).

    Replace the code of this template from line 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>

  1. emails (sub folder) > plain (sub folder) > email-addresses.php (php file).

    Replace the code of this template from line 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";
}


I have jus added this to detect when Local Pickup is used in an order:

$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;
    }
}

And this in the existing if statement to stop the display of shipping address (for Local Pickup):

&& !$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


References:

这篇关于在 WooCommerce 电子邮件通知中隐藏本地取货的送货地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆