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:
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.
Hey, thank you very much for this detailled explanation.
In which file do you replace the email informations ?
Thanks for your comment.
The code need to update here woocommerce/emails/email-addresses.php
Good tutorial but shipping fees are still calculated depending on the billing address and not shipping.
hello,
you need to set the shipping address from woocommerce>settings
let me know if it’s not work
Thanks.
I tired your code and it worked great, however is seems the Company name does not print out on the email (?)
Is there any way we could get your help doing this? We are not coders and don’t have a child theme.
Hello Julia,
sorry for the late reply, you can easily do this by using a plugin here is a plugin https://wordpress.org/plugins/woocommerce-checkout-manager/
if you still need any help, contact me I will try to solve.
Thanks
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.
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
Is it possible to provide code for making the billing and shipping info appear correctly on the order confirmation page? Thanks!
I have the same request! https://ibb.co/prNqyDV
This works really well however how can we update the backend of woocommerce to swap the shipping and payment addresses!! image here https://ibb.co/prNqyDV