Reputation: 119
I want to add custom label to phone and email information on 'Thank You' page. With YITH WooCommerce Checkout Manager I customized some fields and added the following code to functions.php:
function woo_custom_order_formatted_billing_address( $address , $WC_Order ) {
$address = array(
'first_name' => 'First Name: ' . $WC_Order->billing_first_name,
'address_1' => 'Address: ' . $WC_Order->billing_address_1,
'city' => 'City: ' . $WC_Order->billing_city,
);
if(!empty($ship_date)) $address['order_time'] = 'Shipping time: ' . $ship_date;
if(!empty($WC_Order->billing_corpus)) $address['house'] = 'House: ' . $WC_Order->billing_house;
if(!empty($WC_Order->billing_corpus)) $address['corpus'] = 'Corpus: ' . $WC_Order->billing_corpus;
if(!empty($WC_Order->billing_flat)) $address['flat'] = 'Room: ' . $WC_Order->billing_flat;
if(!empty($WC_Order->billing_phone)) $address['billing_phone'] = 'Phone: ' . $WC_Order->billing_phone;
return $address;
}
But for some reason label 'Phone' doesn't want to be added.
Is there any solution?
Upvotes: 1
Views: 1328
Reputation: 253901
1). Overriding WooCommerce templates via your theme
You will have to copy/edit order/order-details-customer.php
template file as the billing phone and the billing email are not handled by the billing formatted address function.
For the Billing Phone you need to replace the line 37
:
<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
by the following line:
<p class="woocommerce-customer-details--phone"><?php _e("Phone: ", "woocommerce"); echo esc_html( $order->get_billing_phone() ); ?></p>
For the Billing email you need to replace the line 41
:
<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
by the following line:
<p class="woocommerce-customer-details--email"><?php _e("Email: ", "woocommerce"); echo esc_html( $order->get_billing_email() ); ?></p>
2). Using some composite filter hooks (for Order Received - Thankyou page)
// Phone
add_filter('woocommerce_order_get_billing_phone', 'wc_order_get_billing_phone_filter' );
function wc_order_get_billing_phone_filter( $billing_phone ) {
// Only on Order Received page (thankyou)
if ( is_wc_endpoint_url( 'order-received' ) && $billing_phone ) {
return __("Phone:", "woocommerce") . ' ' . $billing_phone;
}
return $billing_phone;
}
// Email
add_filter('woocommerce_order_get_billing_email', 'wc_order_get_billing_email_filter' );
function wc_order_get_billing_email_filter( $billing_email ) {
// Only on Order Received page (thankyou)
if ( is_wc_endpoint_url( 'order-received' ) && $billing_email ) {
return __("Email:", "woocommerce") . ' ' . $billing_email;
}
return $billing_email;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Upvotes: 1