Docs Advanced Shipment Tracking Adding tracking info to orders

Adding tracking info to orders

This page is for developers adding shipment tracking to orders from code — a shipping integration, a fulfillment plugin, or a snippet in your own theme.

AST stores tracking in the order’s meta data and can fulfill the order at the same time. You can write that data with the helper functions below, or, if you’re calling in from outside WordPress, use the shipment tracking REST API instead.

Shipment tracking field reference

These are the same fields the REST API uses, so both routes behave identically.

AttributeTypeRequiredDescription
order_idintegerRequiredThe ID of the order to attach the tracking to.
tracking_numberstringRequiredThe tracking number.
tracking_providerstringRequiredThe carrier name, as it appears in your enabled carriers. AST resolves it to the carrier slug. If it doesn’t match a carrier, the value is stored as given and no tracking link is generated.
date_shippedstring or timestampOptionalWhen the package shipped. Accepts a date string or a Unix timestamp. If you leave it out, AST uses the current time.
status_shippedintegerOptional0 — don’t change the order status (default). 1 — set the order to Completed (shown as Shipped if renamed). 2 — set it to Partially Shipped. 3 — set it to Updated Tracking. Values 2 and 3 only apply if that status is enabled in Order Statuses & Notifications.

Add shipment tracking

Use ast_insert_tracking_number(). It takes the carrier name and resolves it to the right carrier for you.

<?php
// Check that AST is installed and active.
if ( class_exists( 'WC_Advanced_Shipment_Tracking_Actions' ) ) {

	$order_id          = 123;
	$tracking_number   = '123123';
	$tracking_provider = 'USPS';
	$date_shipped      = '2026-04-21';
	$status_shipped    = 1;

	if ( function_exists( 'ast_insert_tracking_number' ) ) {
		ast_insert_tracking_number( $order_id, $tracking_number, $tracking_provider, $date_shipped, $status_shipped );
	}
}

Call it once per shipment. Calling it again on the same order adds another tracking number rather than replacing the first.

Function reference

FunctionSignatureWhat it does
ast_insert_tracking_number()( $order_id, $tracking_number, $tracking_provider, $date_shipped = null, $status_shipped = 0 )Adds a tracking number to an order, resolving the carrier name to its slug. This is the one to use in most cases.
ast_add_tracking_number()( $order_id, $tracking_number, $tracking_provider, $date_shipped = null, $status_shipped = 0 )Same arguments, but the carrier is stored as you pass it, without name resolution. Use it when you already have the carrier slug.
ast_get_tracking_items()( $order_id )Returns the tracking items on an order as an array. See Get tracking info from orders.

Always guard the call with function_exists() or class_exists(), so your code doesn’t fatal if AST is deactivated.

Next: Get tracking info from orders.