Show customer phone
When an agent selects a customer in the Phone Orders, the Billing Details section populates their address. However, the customer’s phone number is not displayed. This creates a significant slowdown: to find a contact number, the agent must click away to the customer’s profile. Every second counts during a live call, and this extra step increases call times and leads to a poorer customer experience.
The Solution: A Simple Code Snippet
The Phone Orders for WooCommerce plugin provides two dedicated developer hooks that let you modify customer data before it is displayed: wpo_get_customer_by_array_data and wpo_after_update_customer. By attaching a custom function to these hooks, you can intercept the customer data array and append the phone number to the address.
The Complete Code Snippet
|
1 2 3 4 5 6 7 8 |
add_filter( "wpo_get_customer_by_array_data", "wpo_show_customer_phone_number", 5 ); add_filter( "wpo_after_update_customer", "wpo_show_customer_phone_number", 5 ); function wpo_show_customer_phone_number($data){ if($data["billing_phone"]) $data['formatted_billing_address'] .= " Phone:" . $data["billing_phone"]; return $data; } |
What This Code Does
- Checks for a phone number: The function first checks if the
billing_phonefield exists for the selected customer. If it does, the code proceeds. - Appends the phone number: The phone number is added to the end of the existing
formatted_billing_addressstring. The code also adds a line break (<br>) and a bold “Phone:” label for clear formatting. - Returns the modified data: The updated customer data array is returned to the plugin, which then displays the enriched address in the interface.
Pro tip: To add the phone number on the same line as the address, simply remove the
<br>from the code.
Choose where to add the code
You have two reliable options for adding custom PHP code:
- Option A (Recommended): Use a code snippet plugin. The free Code Snippets plugin is the safest method. It allows you to add, activate, and deactivate code snippets without ever touching your theme files.
- Option B: Add to your child theme’s
functions.phpfile. If you are comfortable editing theme files, add the code to your active child theme’sfunctions.phpfile. Never add custom code directly to a parent theme, because it will be lost when the theme is updated.