How to Swap the Position of the Billing with Shipping

How to Swap the Position of the Billing with Shipping

There was once a client requested to swap the position of the billing with shipping details, because by default WooCommerce displays the Billing info first. But, the client cares more about the shipping address because that is the most important information he needs for him to ship the products.

The first method that comes out of my mind is changing the template. However, I thought it wasn’t very efficient because these pieces of information can be found in the backend, emails and checkout page, which means you need to change all the templates everytime WooCommerce releases an update for the templates.

Therefore, I have discovered this method below to minimise the time taken. Instead of changing the .php templates, I have used hooks in functions.php to change the text:

Step 1: Use this to change all default woocommerce frontend and backend labels:

function wc_custom_addresses_labels( $translated_text, $text, $domain )
{
    switch ( $translated_text )
    {
        case 'Billing Address' : /* Front-end */
            $translated_text = __( 'Shipping address', 'woocommerce' );
            break;
            
        case 'Shipping Address' : /* Front-end */
            $translated_text = __( 'Billing address', 'woocommerce' );
            break;

        case 'Billing details' : // Back-end
            $translated_text = __( 'Shipping Info', 'woocommerce' );
            break;

        case 'Ship to a different address?' :
            $translated_text = __( 'Bill to a different address?', 'woocommerce' );
            break;

        case 'Deliver to a different address?' :
            $translated_text = __( 'Bill to a different address?', 'woocommerce' );
            break;

        case 'Shipping details' : // Back-end
            $translated_text = __( 'Billing Info', 'woocommerce' );
            break;

        case 'Ship to' : // Back-end
            $translated_text = __( 'Bill to', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'wc_custom_addresses_labels', 20, 3 );

Step 2: This to change the text for error messages:

function customize_wc_errors( $error ) {
 if ( strpos( $error, 'Billing ' ) !== false ) {
 $error = str_replace("Billing ", "", $error);
 } elseif ( strpos( $error, 'Shipping ' ) !== false ) {
 $error = str_replace("Shipping ", "Billing ", $error);
 }
 return $error;
 }
 add_filter( 'woocommerce_add_error', 'customize_wc_errors' );

Step 3: Change address on order emails:

<table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">
 <tr>
 <?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) ) : ?>
 <td class="td" style="text-align:<?php echo $text_align; ?>; 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 get_post_meta($order->ID,'_shipping_first_name', true).' '.get_post_meta($order->ID,'_shipping_last_name', true); ?><br/>
 <?php echo get_post_meta($order->ID,'_shipping_address_1', true).' '.get_post_meta($order->ID,'_shipping_address_2', true); ?><br/>
 <?php echo get_post_meta($order->ID,'_shipping_city', true).'<br/>';
 $state = get_post_meta($order->ID,'_shipping_state', true);
 $state = str_replace('Victoria', 'VIC', $state);
 $state = str_replace('Australian Capital Territory', 'ACT', $state);
 $state = str_replace('Western Australia', 'WA', $state);
 $state = str_replace('Tasmania', 'TAS', $state);
 $state = str_replace('New South Wales', 'NSQ', $state);
 $state = str_replace('South Australia', 'SA', $state);
 $state = str_replace('Queensland', 'QLD', $state);
 $state = str_replace('Northern Territory', 'NT', $state);
 echo $state.' '.get_post_meta($order->ID,'_shipping_postcode', true); ?><br/>
 <?php if (get_post_meta($order->ID,'_shipping_country', true) != 'AU') { echo get_post_meta($order->ID,'_shipping_country', true); } ?>
 </p>
 </td>
 <?php endif; ?>
 <td class="td" style="text-align:<?php echo $text_align; ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
 <h3><?php _e( 'Shipping address', 'woocommerce' ); ?></h3>

<p class="text" style="color: #000000;">
 <?php echo get_post_meta($order->ID,'_billing_first_name', true).' '.get_post_meta($order->ID,'_billing_last_name', true); ?><br/>
 <?php echo get_post_meta($order->ID,'_billing_address_1', true).' '.get_post_meta($order->ID,'_billing_address_2', true); ?><br/>
 <?php echo get_post_meta($order->ID,'_billing_city', true).'<br/>';
 $state = get_post_meta($order->ID,'_billing_state', true);
 $state = str_replace('Victoria', 'VIC', $state);
 $state = str_replace('Australian Capital Territory', 'ACT', $state);
 $state = str_replace('Western Australia', 'WA', $state);
 $state = str_replace('Tasmania', 'TAS', $state);
 $state = str_replace('New South Wales', 'NSQ', $state);
 $state = str_replace('South Australia', 'SA', $state);
 $state = str_replace('Queensland', 'QLD', $state);
 $state = str_replace('Northern Territory', 'NT', $state);
 echo $state.' '.get_post_meta($order->ID,'_billing_postcode', true); ?><br/>
 <?php if (get_post_meta($order->ID,'_billing_country', true) != 'AU') { echo get_post_meta($order->ID,'_billing_country', true); } ?>
 </p>
 </td>
 </tr>
</table>

The above code need to update here woocommerce/emails/email-addresses.php

Here is the Result:

How to Swap the Position of the Billing with Shipping

Most important thing before apply to your site i highly recommend first backup your site.

I believe this post help you to Swap the Position of the Billing with Shipping. Comment out if you have any question.

10 thoughts on “How to Swap the Position of the Billing with Shipping”

  1. Thank for this tutorial but unfortunately, it does not work: When the “Bill to different address” checkbox is checked, it always uses the billing country for shipping cost calculation. No matter if I set the woocommerce settings to shipping address or to billing address. Example: The shipping country is set to Germany, which has free shipping > shipping costs are shown correctly. But if I check the “Bill to different address” checkbox and say billing country is “France”, then the shipping costs are updated to 17 Euro, although it should stay free shipping.
    Any help about how to fix that would be really appreciated.

    1. Thanks for your comment.
      unfortunately, I need to check the issue but I am so much busy with my client project right now. can you send me the website URL so i can check later this week

  2. Geoffrey Campbell

    Is it possible to provide code for making the billing and shipping info appear correctly on the order confirmation page? Thanks!

Leave a Comment

Your email address will not be published.

0 Shares
Tweet
Share
Pin
Share