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
Per-item tracking example
Requires Tracking Per Item enabled in General Settings.