Use ast_insert_tracking_number() to add shipment tracking to a WooCommerce order from PHP — for example, from a custom shipping integration, a cron job, or a webhook handler.
For REST API integration, see the Shipment Tracking REST API reference instead.
Function signature
ast_insert_tracking_number( $order_id, $tracking_number, $tracking_provider, $date_shipped, $status_shipped, $sku = '', $qty = '' )
Note the argument order:
$tracking_number comes before $tracking_provider. Swapping them is the most common integration bug — the tracking number is silently saved as the carrier name.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$order_id | string|int | Yes | WooCommerce order ID. |
$tracking_number | string | Yes | The shipment tracking number. |
$tracking_provider | string | Yes | Carrier display name — must match an enabled carrier or configured API alias. |
$date_shipped | string | Yes | Shipment date in YYYY-MM-DD format. |
$status_shipped | int | Yes | 0 = no status change; 1 = mark as Shipped/Completed; 2 = mark as Partially Shipped. |
$sku | string | No | Comma-separated product SKUs for per-item tracking. |
$qty | string | No | Comma-separated quantities matching the SKUs above. |
Single-package example
<?php
if ( class_exists( 'AST_Pro_Actions' ) && function_exists( 'ast_insert_tracking_number' ) ) {
$order_id = 123;
$tracking_number = '123123';
$tracking_provider = 'USPS';
$date_shipped = '2025-06-12';
$status_shipped = 1; // Mark as Shipped
ast_insert_tracking_number( $order_id, $tracking_number, $tracking_provider, $date_shipped, $status_shipped );
}
Per-item tracking example
Requires Tracking Per Item enabled in General Settings.
<?php
if ( class_exists( 'AST_Pro_Actions' ) && function_exists( 'ast_insert_tracking_number' ) ) {
$order_id = 123;
// First package — t-shirt and blue-jeans
ast_insert_tracking_number(
$order_id,
'123456', // tracking_number
'USPS', // tracking_provider
'2025-06-12', // date_shipped
2, // status_shipped: 2 = Partially Shipped
't-shirt,blue-jeans', // sku
'1,1' // qty
);
// Second package — remaining items
ast_insert_tracking_number(
$order_id,
'456789',
'USPS',
'2025-06-13',
1, // status_shipped: 1 = Shipped (all fulfilled)
'blue-jeans',
'1'
);
}
Notes
- Wrap calls in both
class_exists( 'AST_Pro_Actions' )andfunction_exists( 'ast_insert_tracking_number' )to fail gracefully when AST PRO is inactive. - The
$tracking_providervalue must match an enabled carrier name or a configured API alias exactly (case-sensitive). An unrecognised carrier name is silently saved as a plain string with no tracking link. - Order status changes and customer email notifications follow your AST PRO settings, exactly as for tracking added manually.
- Test on a staging site before deploying to production.