Blank Space
-
Hi, Would you be able to advise how can I add blank spaces for the shipping phone and email so that it matches that of the billing?
This is how it looks like on the My Account > Order Details
https://snipboard.io/7HJB1N.jpgThanks!
-
Hi @tjos123
Because of simplicity the phone and email are simple appended to the address without spacing. If you need the spaces (or other custom styles) you need to overwrite the email template file in your theme (documentation: https://docs.woocommerce.com/document/template-structure/). Its the template file “/emails/email-addresses.php”.
In the copied file you have to replace the following line:
<address class="address"><?php echo wp_kses_post( $shipping ); ?></address>with this code:
<address class="address"> <?php echo wp_kses_post( $shipping ); ?> <?php if(get_post_meta($order->get_id(), '_shipping_phone', true)) : ?> <br/><?php echo wc_make_phone_clickable(get_post_meta($order->get_id(), '_shipping_phone', true)); ?> <?php endif; ?> <?php if(get_post_meta($order->get_id(), '_shipping_email', true)) : ?> <br/><?php echo esc_html(get_post_meta($order->get_id(), '_shipping_email', true)); ?> <?php endif; ?> </address>The code is not tested, but should work. If not, just let us know.
Thanks. But nope, it doesn’t work.
Hi @tjos123
Sorry that was the wrong template. You can use this if you want the spaces in your email too. On the order confirmation you have to change the template “/order/order-details-customer.php”. You have to replace
<?php echo wp_kses_post( $order->get_formatted_shipping_address( esc_html__( 'N/A', 'woocommerce' ) ) ); ?>with
<?php echo wp_kses_post( $order->get_formatted_shipping_address( esc_html__( 'N/A', 'woocommerce' ) ) ); ?> <?php if(get_post_meta($order->get_id(), '_shipping_phone', true)) : ?> <p class="woocommerce-customer-details--phone"> <?php echo wc_make_phone_clickable(get_post_meta($order->get_id(), '_shipping_phone', true)); ?> </p> <?php endif; ?> <?php if(get_post_meta($order->get_id(), '_shipping_email', true)) : ?> <p class="woocommerce-customer-details--email"> <?php echo esc_html(get_post_meta($order->get_id(), '_shipping_email', true)); ?> </p> <?php endif; ?>The p tags and classes are taken from the default WooCommerce template. If you have another theme with other files the code might be slightly different.
Now the phone and email should be displayer twice. To avoid this, you have to add the following hook to your functions.php:
add_filter('F4/WCSPE/append_fields_to_formatted_address', '__return_false');This will remove the other email and phone from the address. If you dont use the snippet from my first response, you wont have any email or phone in your shipping address, so I’ll advice to use both.
I dont think anyone has ever used such a customization, if somethings not working correctly, just let us know.
How to remove the blank space from billing address email id and phone number?
Billing address I want to showing same for shipping address.
Hi @anish12345
You can follow the directions from the previous replies and copy the template files to your theme. Then replace this:
<?php if ( $order->get_billing_phone() ) : ?> <p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p> <?php endif; ?> <?php if ( $order->get_billing_email() ) : ?> <p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p> <?php endif; ?>with this:
<?php if ( $order->get_billing_phone() ) : ?> <?php echo esc_html( $order->get_billing_phone() ); ?><br /> <?php endif; ?> <?php if ( $order->get_billing_email() ) : ?> <?php echo esc_html( $order->get_billing_email() ); ?> <?php endif; ?>Its untested because it actually has nothing to do with our plugin, but it should remove the spaces.
It’s not working.
First of all back to the initial issue. @tjos123, is your problem solved with my second answer? Or can we still help you?
Secondly @anish12345:
Tell me which original template file you copied and where you placed it in your theme/child theme, followed the instructions here https://docs.woocommerce.com/document/template-structure/.
Then post the new, replaced code here so we can check if you have replaced the right code lines.
It’s not working. I am already resolved through another way.
The topic ‘Blank Space’ is closed to new replies.