My site has two options
- you can ship to the billing address
- you can enter a billing address and a separate delivery address, pretty standard.
If you enter both a billing and a shipping address during checkout, then in the order details page in My Account you can see both Billing address and Shipping address titles above the relevant addresses.
If you only enter a billing address during checkout, in the order details page in My Account you can only see ‘Billing’ address, the address isn’t duplicated as the shipping address. No Shipping address is shown, so it looks strange.
I would like to conditionally rename ‘Billing address’ to ‘Billing & Shipping address’ if the order has no separate shipping address.
It would be beneficial to change it in the emails as well, as it would make more sense.
I have found this for renaming the title (I haven’t tested it), but how can I do it conditionally?
function wc_billing_field_strings( $translated_text, $text, $domain ) { switch ( $translated_text ) { case 'Billing address' : $translated_text = __( 'Billing & Shipping address', 'woocommerce' ); break; } return $translated_text; } add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );
Advertisement
Answer
My Account
https://github.com/woocommerce/woocommerce/blob/master/templates/order/order-details-customer.php
- This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-customer.php.
Replace (line: 31)
<h2 class="woocommerce-column__title"><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>
With
<h2 class="woocommerce-column__title"> <?php // Show shipping = false if ( !$show_shipping ) { $title = 'Billing & Shipping address'; } else { $title = 'Billing address'; } esc_html_e( $title, 'woocommerce' ); ?> </h2>
https://github.com/woocommerce/woocommerce/blob/master/templates/emails/email-addresses.php
- This template can be overridden by copying it to yourtheme/woocommerce/emails/email-addresses.php.
Replace (line: 29)
<h2><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>
With
<h2> <?php // Billing_address if ( !$order->needs_shipping_address() ) { $title = 'Billing & Shipping address'; } else { $title = 'Billing address'; } esc_html_e( $title, 'woocommerce' ); ?> </h2>