2
votes

I am trying to change the Shipping field order in WooCommerce new order emails, However, modifying the Shipping field in email-addresses.php will break the checkout page. How can I modify this?

This is how I am modifying:

0.Source code:

$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.Successfully modified the Billing field:

<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.This is I want to change shipping field, but not work:

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

Any help Where can i get and change it?

Thanks

1

1 Answers

1
votes

Hey there your code is perfect except the following lines

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

in above lines get_shipping_phone and get_shipping_email are the methods which are not available in the woocommerce itself so you can use get_billing_email and get_billing_phone instead of them if you want.