Docs Advanced Shipment Tracking Pro (AST PRO) Adding tracking info to orders

Adding tracking info to orders

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

ParameterTypeRequiredDescription
$order_idstring|intYesWooCommerce order ID.
$tracking_numberstringYesThe shipment tracking number.
$tracking_providerstringYesCarrier display name — must match an enabled carrier or configured API alias.
$date_shippedstringYesShipment date in YYYY-MM-DD format.
$status_shippedintYes0 = no status change; 1 = mark as Shipped/Completed; 2 = mark as Partially Shipped.
$skustringNoComma-separated product SKUs for per-item tracking.
$qtystringNoComma-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' ) and function_exists( 'ast_insert_tracking_number' ) to fail gracefully when AST PRO is inactive.
  • The $tracking_provider value 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.