How to Set Up Shipment Tracking in WooCommerce (2021 Guide)

Ecommerce, WooCommerce
How to Set Up Shipment Tracking in WooCommerce (2021 Guide)

Shipping tracking is one of the most important tools in modern eCommerce. Providing customers with the necessary tracking data to give them an accurate delivery date both reassures them that their order is on the way, and ensures they won’t miss their delivery.

WooCommerce comes with some default email templates to provide your customer’s order details, but these only work if you’re shipping deliveries yourself, and doesn’t allow for custom providers in its interface. Given that most deliveries will be handled by a recognized postal service – USPS, FedEx, PostNL, you name it – your store needs a way for customers to track their orders directly through their chosen shipping company.

If you need a way to easily add shipment tracking details to orders in your WooCommerce store, then we’ve got the solution for you.

In this tutorial, we’ll show you how to set up the WooCommerce Shipment Tracking plugin on your WooCommerce store.

The WooCommerce Shipment Tracking plugin is an easy way to add the functionality to your store that will allow customers to track their shipment.

Whether you are manually adding the tracking details or using 3rd party tools like ShippingEasy or ShipStation, this plugin is for you.

It costs just $49 a year, and supports over 15 of the world’s major shipping providers out of the box.

How to setup Shipment Tracking in WooCommerce

The first step is to purchase the Shipment Tracking plugin.

Next, download the .zip file and navigate to your WordPress dashboard.

Then, go to Plugins, add a new plugin, and upload the .zip file.

Finally, activate the plugin. If you navigate to the WooCommerce Orders page in your WooCommerce backend, you will see that the Shipment Tracking column has been added.

If you are more of a visual learner, see the video below that goes over the installation process:

How to add a tracking number to an order

On your WooCommerce Orders page, click on a recent order.

Next, in the top righthand corner, click “Add Tracking Number.”

Then, add the Provider and Tracking Number, then click Save Tracking.

If your customer now goes to their shipping provider’s (USPS, DPD, FedEx, etc.) tracking page, their tracking information will have updated with the tracking number you’ve just added.

Finally, if you want to let your customer know that their order has been shipped and provide an email notification with their tracking URL, simply update the order status from Processing to Completed. This will let them go to the shipping company’s order tracking page and see the status of their order.

Shipment Tracking

Provide customers with an easy way to track their shipment!

Get the plugin

How can you automate this process further?

If you use a plugin such as ShippingEasy or ShipStation to print off your labels, these shipping tools will automatically POST back to your WooCommerce store with the tracking number.

Here is how the process works:

  1. Customer orders a product on your store
  2. Orders that are “processing” will be exported to ShipStation or ShippingEasy
  3. Store manager prints off label and ships product to the customer
  4. ShippingEasy or ShipStation POST back to your WooCommerce store and updates order status to “completed”
  5. Automated email goes out to the customer that their shipment is on their way with tracking code available on the email

Adding a Track Shipment” link to My Account – Orders page

To further improve the user experience, you’ll want your customers to be able to access their tracking info directly from the frontend of your ecommerce site’s account page. Let’s look at how to set this up:

First, edit  your active WordPress theme via SFTP or SSH.

Next, create a ‘woocommerce’ folder inside your active WordPress theme if you have not already. This will allow you to override core WooCommerce files.

Then, inside the /woocommerce/ folder, create another folder titled ‘myaccount’.

Next, open up the file inside your /woocommerce/myaccount/ folder called orders.php.

Edit your current orders.php file and search for the following snippet on lines 56 and 57:

// Search for this line of code in your orders.php file
<?php elseif ( 'order-status' === $column_id ) : ?>
	<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>

Replace with this snippet below:

// replace with the following code below in your orders.php file
<?php elseif ('order-status' === $column_id) :

	$status = $order->get_status();
	$column_output = "";

	// show tracking link
	if ($status == 'completed' && class_exists('WC_Shipment_Tracking_Actions')) {

		$st_actions = WC_Shipment_Tracking_Actions::get_instance();

		if ($tracking_items = $st_actions->get_tracking_items($order->get_id(), true)) {

			foreach ($tracking_items as $tracking_item) {

				if ($tracking_item['formatted_tracking_link'] !== '') {

					$column_output = sprintf("<a href='%s' target='_blank'>%s</a>",
						$tracking_item['formatted_tracking_link'], __('Track Shipment', 'bdl'));

					break;
				}
			}
		}
	}

	if (empty($column_output))
		$column_output = esc_html(wc_get_order_status_name($status));

	echo $column_output; ?>

If you would rather just replace the entire orders.php file, copy the code below and replace.

<?php
/**
 * Orders
 *
 * Shows orders on the account page.
 */

defined( 'ABSPATH' ) || exit;

do_action( 'woocommerce_before_account_orders', $has_orders ); ?>

<?php if ( $has_orders ) : ?>

	<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
		<thead>
			<tr>
				<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
					<th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
				<?php endforeach; ?>
			</tr>
		</thead>

		<tbody>
			<?php
			foreach ( $customer_orders->orders as $customer_order ) {
				$order      = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
				$item_count = $order->get_item_count() - $order->get_item_count_refunded();
				?>
				<tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?> order">
					<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
						<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
							<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
								<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>

							<?php elseif ( 'order-number' === $column_id ) : ?>
								<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
									<?php echo esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ); ?>
								</a>

							<?php elseif ( 'order-date' === $column_id ) : ?>
								<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>

							<?php elseif ('order-status' === $column_id) :

								$status = $order->get_status();
								$column_output = "";

								// show tracking link
								if ($status == 'completed' && class_exists('WC_Shipment_Tracking_Actions')) {

									$st_actions = WC_Shipment_Tracking_Actions::get_instance();

									if ($tracking_items = $st_actions->get_tracking_items($order->get_id(), true)) {

										foreach ($tracking_items as $tracking_item) {

											if ($tracking_item['formatted_tracking_link'] !== '') {

												$column_output = sprintf("<a href='%s' target='_blank'>%s</a>",
													$tracking_item['formatted_tracking_link'], __('Track Shipment', 'bdl'));

												break;
											}
										}
									}
								}

								if (empty($column_output))
									$column_output = esc_html(wc_get_order_status_name($status));

								echo $column_output; ?>

							<?php elseif ( 'order-total' === $column_id ) : ?>
								<?php
								/* translators: 1: formatted order total 2: total order items */
								echo wp_kses_post( sprintf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ) );
								?>

							<?php elseif ( 'order-actions' === $column_id ) : ?>
								<?php
								$actions = wc_get_account_orders_actions( $order );

								if ( ! empty( $actions ) ) {
									foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
										echo '<a href="' . esc_url( $action['url'] ) . '" class="woocommerce-button button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
									}
								}
								?>
							<?php endif; ?>
						</td>
					<?php endforeach; ?>
				</tr>
				<?php
			}
			?>
		</tbody>
	</table>

	<?php do_action( 'woocommerce_before_account_orders_pagination' ); ?>

	<?php if ( 1 < $customer_orders->max_num_pages ) : ?>
		<div class="woocommerce-pagination woocommerce-pagination--without-numbers woocommerce-Pagination">
			<?php if ( 1 !== $current_page ) : ?>
				<a class="woocommerce-button woocommerce-button--previous woocommerce-Button woocommerce-Button--previous button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>"><?php esc_html_e( 'Previous', 'woocommerce' ); ?></a>
			<?php endif; ?>

			<?php if ( intval( $customer_orders->max_num_pages ) !== $current_page ) : ?>
				<a class="woocommerce-button woocommerce-button--next woocommerce-Button woocommerce-Button--next button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>"><?php esc_html_e( 'Next', 'woocommerce' ); ?></a>
			<?php endif; ?>
		</div>
	<?php endif; ?>

<?php else : ?>
	<div class="woocommerce-message woocommerce-message--info woocommerce-Message woocommerce-Message--info woocommerce-info">
		<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
			<?php esc_html_e( 'Go to the shop', 'woocommerce' ); ?>
		</a>
		<?php esc_html_e( 'No order has been made yet.', 'woocommerce' ); ?>
	</div>
<?php endif; ?>

<?php do_action( 'woocommerce_after_account_orders', $has_orders ); ?>

Summary

The WooCommerce Shipment Tracking plugin is an easy-to-use plugin if you need a solid way to allow your customers to track their shipments.

You can use this plugin to allow your customers to track their order with the world’s major shipping providers, ensuring your brand remains linked in their minds to a high-quality and professional delivery service.

Shipment Tracking

Provide customers with an easy way to track their shipment!

Get the plugin

Additional Resources

Leave a reply

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted. Your email address will not be published. Required fields are marked*

Comments

  1. Wesley Townie August 13, 2019 | 11:46 am

    Hi Simon, thanks for the tutorial. I have the plugin setup but curious how I can copy and override the orders.php file in my theme. I am stuck on how to do this. Any insight?

  2. Denchok July 2, 2020 | 11:31 am

    How can I find a table of shipment tracking in database?

  3. echo October 14, 2020 | 9:12 am

    Just so I understand this correctly. The code you added doesn’t add a tracking number to the “completed order” email notice correct? It’s just for the user inside their my account page. Correct? So there’s no way of using a snippet to add it to the notice. We have to use a plugin?

    Thanks

FAQ

How to add a Shipping Tracking Number to an WooCommerce Order?

On your WooCommerce Orders page, do the following:
1. Click into a recent order of yours.
2. Next, in the top righthand corner, click “Add Tracking Number”.
3. Then, add the Provider and Tracking Number, then click Save Tracking.
4. Finally, if you want to notify your customer that their order has been shipped and provide the tracking link in their email confirmation, update the orders status from processing to completed.

Best shipping plugins for WooCommerce?

How to buy the WooCommerce Shipment Tracking plugin?