【问题标题】:How to change WooCommerce Shipping field in new order emails?如何在新订单电子邮件中更改 WooCommerce Shipping 字段?
【发布时间】:2019-03-06 04:12:51
【问题描述】:

我正在尝试更改 WooCommerce 新订单电子邮件中的运输字段订单, 但是,修改 email-addresses.php 中的 Shipping 字段会破坏结帐页面。我该如何修改?

这就是我的修改方式:

0.源码:

$text_align = is_rtl() ? 'right' : 'left';
$address    = $order->get_formatted_billing_address();
$shipping   = $order->get_formatted_shipping_address();

?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; padding:0;" border="0">
    <tr>
        <td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; border:0; padding:0;" valign="top" width="50%">
            <h2><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>

            <address class="address">
                <?php echo wp_kses_post( $address ? $address : esc_html__( 'N/A', 'woocommerce' ) ); ?>
                <?php if ( $order->get_billing_phone() ) : ?>
                    <br/><?php echo esc_html( $order->get_billing_phone() ); ?>
                <?php endif; ?>
                <?php if ( $order->get_billing_email() ) : ?>
                    <br/><?php echo esc_html( $order->get_billing_email() ); ?>
                <?php endif; ?>
            </address>
        </td>
        <?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && $shipping ) : ?>
            <td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; padding:0;" valign="top" width="50%">
                <h2><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>

                <address class="address"><?php echo wp_kses_post( $shipping ); ?></address>
            </td>
        <?php endif; ?>
    </tr>
</table>

1.修改Billing字段成功:

<address class="address">
    <?php //echo wp_kses_post( $address ? $address : esc_html__( 'N/A', 'woocommerce' ) ); ?>
        Name: <?php echo $order->billing_first_name; ?><?php echo $order->billing_last_name; ?><br>
        Address:<?php echo $order->billing_country; ?><?php echo $order->billing_postcode; ?><?php echo $order->billing_city; ?><?php echo $order->billing_state; ?><?php echo $order->billing_address_1; ?>
    <?php if ( $order->get_billing_phone() ) : ?>
        <br/>Phone:<?php echo esc_html( $order->get_billing_phone() ); ?>
    <?php endif; ?>
    <?php if ( $order->get_billing_email() ) : ?>
        <br/>Email:<?php echo esc_html( $order->get_billing_email() ); ?>
    <?php endif; ?>
</address>
</td>

2.这是我想更改运输字段,但不起作用:

<td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; padding:0;" valign="top" width="50%">
                <h2><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>

                <address class="address">
                    <?php //echo wp_kses_post( $shipping ); ?>
                         Shipping Name:<?php echo esc_html($order->get_shipping_first_name() ); ?><?php echo esc_html($order->get_shipping_last_name() ); ?><br>
                         Shipping Address:<?php echo $order->esc_html(get_shipping_country() ); ?><?php echo esc_html($order->get_shipping_postcode() ); ?><?php echo esc_html($order->get_shipping_city() ); ?><?php echo esc_html($order->get_shipping_state() ); ?><?php echo esc_html($order->get_shipping_address_1() );?>
                    <?php if ( $order->get_shipping_phone() ) : ?>
                         <br/>Shipping Phone:<?php echo esc_html( $order->get_shipping_phone() ); ?>
                <?php endif; ?>
                <?php if ( $order->get_shipping_email() ) : ?>
                         <br/>Shipping Email:<?php echo esc_html( $order->get_shipping_email() ); ?>
                <?php endif; ?>


                </address>

任何帮助我可以从哪里获得和更改它?

谢谢

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    嘿,你的代码是完美的,除了以下几行

    1> if ( $order->get_shipping_phone() )
    2> if ( $order->get_shipping_email() )
    

    在上述行中,get_shipping_phone 和 get_shipping_email 是 woocommerce 本身不可用的方法,因此您可以根据需要使用 get_billing_email 和 get_billing_phone 代替它们。

    【讨论】:

      猜你喜欢
      • 2018-11-23
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 1970-01-01
      • 2019-01-12
      • 2020-12-12
      相关资源
      最近更新 更多