Add tracking information to orders history
Phone Orders adds a Shipment Tracking column to the customer’s order history page. This guide provides two PHP filters that insert the tracking information into the table, making it visible to customers when they view their past orders.
Prerequisite: This feature works only in Run at frontend mode (you find it in Phone Orders > Settings > Run at frontend settings tab). Before using this code, you must install and activate the WooCommerce Shipment Tracking plugin.
The Complete Code Snippet
Copy and paste the following code into your child theme’s functions.php file or via the Code Snippets plugin.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
add_filter( 'wpo_order_history_customer_table_headers', function($headers) { $new_headers = array(); foreach($headers as $header) { $new_headers[] = $header; if ( $header['key'] == 'status') $new_headers[] = array( 'key'=>'shipment_tracking', 'label'=>'Shipment Tracking', 'escape'=>false); } return $new_headers ; }); add_filter('wpo_order_history_customer_table_row', function($data,$order) { if( class_exists('WC_Shipment_Tracking_Actions') ) $data['shipment_tracking'] = WC_Shipment_Tracking_Actions::get_instance()- >get_shipment_tracking_column( $order->get_id() ); return $data; },10,2); |
How the Code Works
| Filter | Purpose |
|---|---|
wpo_order_history_customer_table_headers | Inserts a new column header labelled Shipment Tracking immediately after the Status column. The escape => false parameter allows the column to contain HTML links. |
wpo_order_history_customer_table_row | Populates the Shipment Tracking column with the actual tracking information (carrier name, tracking number, and a clickable tracking URL) by calling the get_shipment_tracking_column() method from the Shipment Tracking plugin. |
Why You Need This Code
The WooCommerce Shipment Tracking plugin stores tracking data in the order, but by default, this information does not appear on the customer’s Order History page. Customers must click into each order individually to see the tracking details. The code adds a dedicated column to the main order history table, giving customers a quick overview of all their shipments.
Step‑by‑Step Implementation
- Install and activate the WooCommerce Shipment Tracking plugin.
- Copy the code snippet.
- Install and activate the free Code Snippets plugin.
- Go to Snippets → Add New.
- Give the snippet a title, for example “Phone Orders – Shipment Tracking Column”.
- Paste the code into the Code text area.
- Set the “Run snippet” option to “Run everywhere”.
- Click Save Changes and Activate.
Testing the Integration
- Create a test order.
- Add shipment tracking information to the order (via WooCommerce → Orders → Edit Order → Shipment Tracking).
- Log in as a customer and go to My Account → Orders.
- Locate the order and check the Shipment Tracking column. The column should display the carrier name and a clickable tracking number.