如何在新订单电子邮件中更改WooCommerce运输领域



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

这就是我的修改方式:

0.Source代码:

$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.实验室修改了计费字段:

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

我可以在哪里获得任何帮助?

谢谢

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

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,而不是如果需要。

最新更新