Add Shippit delivery tracking to WooCommerce

Shippit has become my go-to shipping service for eCommerce stores with a decent order volume.

The company offers a WooCommerce integration plugin that pushes new orders to Shippit for dispatch. Once the delivery has been booked, the Shippit tracking information is sent back to WooCommerce and stored in the Order Notes section.

Frustratingly, this information isn’t added to the customer’s order summary page, nor is it included in any of the transactional emails sent from your store. To solve this annoyance, I’ve put together a little snippet that adds a Shippit tracking link to the WooCommerce Order Tracking page.

Installing the code

First, add the following snippet to your theme’s functions.php file or to a MU Plugin. You can also use the Code Snippets plugin to install the code, which is handy if you don’t have access to the filesystem.

//Show tracking information on view order pages
add_action( 'woocommerce_view_order', 'show_shippit_custom_tracking' );
function show_shippit_custom_tracking($order_id){
    
    // Get an instance of the `WC_Order` Object
    $order = wc_get_order( $order_id );
        
    //Get access to the database
    global $wpdb;
        
    //Get the comment containing the Shippit info
    $shippit_string = $wpdb->get_var("SELECT comment_content from wp_comments where comment_post_ID = '" . $order_id . "' and comment_content like '%Shippit.%';");
    
    $trimmed_shippit_string = str_replace('Order Synced with Shippit. Tracking number: ', '', $shippit_string);
    
    //Output the result
    echo '<h2 class="woocommerce-order-details__title">Order Tracking</h2>';
    echo '<p>Your tracking number is: <a target="_blank" style="color: #654ea3;" href="https://app.shippit.com/track/' . rtrim($trimmed_shippit_string, '.') .'/">' . rtrim($trimmed_shippit_string, '.') . '</a></p>';
 
}

Be aware that this isn’t particularly good code. It’s a quick and hacky solution that could stop working if Shippit makes modifications to their integration plugin. Use at your own risk, basically.

If you’re not using the default WordPress table prefix, you’ll need to change wp_comments to point to the correct database table.

Creating the order tracking page

The order tracking page is actually a little-known feature built right into WooCommerce. Just create a new page, add the [woocommerce_order_tracking] shortcode and press Publish. It will look something like this:

Also worth noting—

Shippit creates a tracking code for all of your orders at the time the order is placed. If you ultimately decide not to send that order with Shippit, the non-functional tracking link will still be added to the customer’s order tracking page.

Shane Gowland

Hi! I’m a web designer, software developer, and digital marketer based in South Australia. I've been building websites on WordPress for over 12 years. You can learn more about the projects and businesses I'm involved with on my website.

Leave a Reply