Currently, Woocommerce does not have a shipment tracking option and therefore your customers are unable to see the correct data about the orders. Now, in this tutorial I‘m going to show you how to add shipment tracking to Woocommerce. It will work as a charm and will show the tracking code on the orders table, single orders page and will send tracking information related emails to your customers.
Also, as a bonus – it will add the Track button to your orders page in a way that by clicking on the button the correct tracking provider site is opened. So, stay tuned.
Option 1: How to Add Shipment Tracking to Woocommerce with the plugin?
I’m going to show you two different options and first of them is adding a tracking system to Woocommerce with the help of a plugin. The best free plugin I can recommend is Advanced Shipment Tracking for WooCommerce plugin.
This awesome plugin lets you add tracking information to orders and provides your customers an easy way to track their orders. Also, you can manage and automate your post-shipping orders flow, reduce time spent on customer service.
Step 1: Install the Advanced Shipment Tracking for WooCommerce plugin
Go to Plugins >> Add new and search form Advanced Shipment Tracking for WooCommerce. Install and activate it.
Next, go to Woocommerce >> Shipment tracking and select the options you want to use.
Step 2: Choose the providers
Currently, there are 397 shipping provider you can choose from. All of them are activared by default but you can deactivate them if you want.
If there is something missing then press on the Custom button and you’ll be able to add your own providers.
Step 3: Customize emails
Under Shipment tracking >> Settings you’ll find Launch Customizer button. If you click on it youl’ll be able to customize the content and appearance of the transactional emails.
Step 4: Activate Actions
Go to Woocommerce >> Orders and under the Screen Options activate Actions. If you do that you will be able to use quick icons to modify your orders (see the screnshot).
Step 5: Add tracking information to orders
Since all the cusotmizations are done you can go and open up an order and add the tracking information. Just add the tracking code, choose the provider and select whether the order is shipped or partially shipped. Save and you’re done.
If everything is done then the end result should look like this.
Option 2: How to Add Shipment Tracking System to Woocommerce with the code?
Advanced Shipment Tracking plugin has a lot of options but maybe you don’t need something so sophisticated and you just need to add a tracking code (or information) to the orders. Well, take a look at the code snippet here below.
Step 1: Install a Code Snippets plugin
Code Snippets plugin is a free plugin which allows your to run PHP/HTML/CSS/JavaScript code snippets on your site without the need to modify functions.php. The plugin can be found here. In this tutorial we are going to use this plugin to add one code snippet
Another option, paste the code snippets shown below to your child theme’s functions.php file.
Step 2: Copy the code to the code box
Go to Snippets >> Add new
Now give it a meaningful title and paste this code here below to the code box.
This code will add a tracking info meta box to your orders. All the information saved there will be shown on the orders table and single orders page. If you want to change the column title look for “Tracking code” string inside the code.
// For displaying in Order page columns.
add_filter( 'manage_edit-shop_order_columns', 'set_tracking_column' );
function set_tracking_column($columns) {
$columns['tracking_column'] = __( 'Tracking code', 'your_text_domain' );
return $columns;
}
// Add the data to the custom columns for the order post type:
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column', 10, 2 );
function custom_shop_order_column( $column, $post_id ) {
switch ( $column ) {
case 'tracking_column' :
echo esc_html( get_post_meta( $post_id, 'tracking_column', true ) );
break;
}
}
// For display and saving in order details page.
add_action( 'add_meta_boxes', 'tracking_code_meta_box' );
function tracking_code_meta_box() {
add_meta_box(
'tracking_column',
__( 'Tracking code', 'your_text_domain' ),
'shop_order_display_callback',
'shop_order'
);
}
// For displaying it correctly
function shop_order_display_callback( $post ) {
$value = get_post_meta( $post->ID, 'tracking_column', true );
echo '<textarea style="width:100%" id="tracking_column" name="tracking_column">' . esc_attr( $value ) . '</textarea>';
}
// Saving the input data
function save_tracking_code_meta_box_data( $post_id ) {
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'shop_order' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_shop_order', $post_id ) ) {
return;
}
}
// Make sure that it is set.
if ( ! isset( $_POST['tracking_column'] ) ) {
return;
}
// Sanitize user input.
$my_data = sanitize_text_field( $_POST['tracking_column'] );
// Update the meta field in the database.
update_post_meta( $post_id, 'tracking_column', $my_data );
}
add_action( 'save_post', 'save_tracking_code_meta_box_data' );
// Showing the info on My orders page
// New column on My orders page
add_filter( 'woocommerce_account_orders_columns', 'add_account_orders_column', 1, 1 );
function add_account_orders_column( $columns ){
$columns['tracking-column'] = __( 'Tracking code', 'woocommerce' );
return $columns;
}
add_action( 'woocommerce_my_account_my_orders_column_tracking-column', 'add_account_orders_column_rows' );
function add_account_orders_column_rows( $order ) {
// Example with a custom field
if ( $value = $order->get_meta( 'tracking_column' ) ) {
echo esc_html( $value );
}
}
// Showing tracking code on View order page and on Thank you page
add_action( 'woocommerce_thankyou', 'tracking_on_thankyou_page', 20 );
add_action( 'woocommerce_view_order', 'tracking_on_thankyou_page', 20 );
function tracking_on_thankyou_page( $order_id ){ ?>
<table class="woocommerce-table shop_table gift_info">
<tbody>
<tr>
<th>Tracking code</th>
<td><?php echo wpautop( get_post_meta( $order_id, 'tracking_column', true ) ); ?></td>
</tr>
</tbody>
</table>
<?php }
If everything goes well then the end result should look like this.
So, here it is. Now you know how to add shipment tracking to Woocommerce. Go and add on to your system right now.