Docly Child

Adding tracking info to orders

This article provides developer documentation for adding support with the to Advanced Shipment Tracking (AST) and AST PRO.

AST provides a way for shipping services and plugin to add shipment tracking information to the WooCommerce order meta data and to fulfill the orders. You can add the shipment tracking information to orders programmatically or, use the shipment tracking endpoint in WooCommerce API.

Shipment Tracking order meta reference

ATTRIBUTETYPEDESCRIPTIONPERMISSIONS
order_idstringUnique identifier for orderRequired
tracking_providerstringTracking provider nameRequired
tracking_numberstringTracking numberRequired
date_shippeddateDate when the package was shipped – default to the date/time that the tracking was added via the APIOptional
status_shippedint0 – do not change the order status, 1 – change order status to “Shipped” (completed), 2 – change the order status to custom status “Partially Shipped” (Defaults to 0).Optional
skustringLine item SKU – Add tracking per itemOptional
qtystringLine item quantity – Add tracking per itemOptional

Add Shipment tracking

With the use of this code snippet, you can add shipment tracking information to the order.

<?php
// Check if the AST PRO plugin is installed
if ( class_exists( 'AST_Pro_Actions' ) ) {

	// Set the order ID
	$order_id = '123';

	// Set the tracking provider name
	$tracking_provider = 'USPS';

	// Set the tracking number
	$tracking_number = '123123';

	// Set the date shipped
	$date_shipped = '2022-04-21';

	// Set the shipped status (1 = shipped)
	$status_shipped = 1;

	// Check if the "ast_insert_tracking_number" function exists
	if ( function_exists( 'ast_insert_tracking_number' ) ) {
		ast_insert_tracking_number( $order_id, $tracking_number, $tracking_provider, $date_shipped, $status_shipped );
	}
}

Add Shipment Tracking Per Item

You can add tracking to the order to specific line items (products) using the product SKU and the quantity shipped properties.

For example, if you received an order of 5 items and want to send them in s packages with different tracking numbers:

Package 1 – tracking number – 123456

  • t-shirt x 1
  • blue-jeans x 1

Package 2 – tracking number – 456789

  • t-shirt x 1
  • blue-jeans x 2

Add tracking for Package One:

<?php
// Check if AST PRO plugin is Installed
if ( class_exists( 'AST_Pro_Actions' ) ) {
	
	$order_id = '123';
	$tracking_provider = 'USPS';
	$tracking_number = '123456';
	$date_shipped = '2022-04-21';
	$status_shipped = 1;
	$sku = 't-shirt,blue-jeans';
  	$qty = '1,1';
	
	if ( function_exists( 'ast_insert_tracking_number' ) ) {
		ast_insert_tracking_number( $order_id, $tracking_number, $tracking_provider, $date_shipped, $status_shipped, $sku, $qty );
	}
}

Add tracking for Package Two:

<?php
// Check if AST PRO plugin is Installed
if ( class_exists( 'AST_Pro_Actions' ) ) {
	
	$order_id = '123';
	$tracking_provider = 'USPS';
	$tracking_number = '456789';
	$date_shipped = '2022-04-21';
	$status_shipped = 1;
	$sku = 't-shirt,blue-jeans';
  	$qty = '1,2';
	
	if ( function_exists( 'ast_insert_tracking_number' ) ) {
		ast_insert_tracking_number( $order_id, $tracking_number, $tracking_provider, $date_shipped, $status_shipped, $sku, $qty );
	}
}

$129.00

Billed annually

Buy Now