The ast_api_create_item_arg filter lets you modify the arguments array before AST PRO creates a tracking entry via the REST API. It fires on every POST request to:
POST /wp-json/wc-shipment-tracking/v3/orders/{order_id}/shipment-trackings/
Filter signature
apply_filters( 'ast_api_create_item_arg', $args, $request )
| Parameter | Type | Description |
|---|---|---|
$args | array | Arguments array built from the API request payload. Keys: tracking_provider, tracking_number, date_shipped, status_shipped, replace_tracking, sku, qty, shipping_note. |
$request | WP_REST_Request | The full REST API request object. Use $request->get_param( 'key' ) to read any request parameter or $request->get_json_params() for the raw body. |
Example — force status_shipped to 1
add_filter( 'ast_api_create_item_arg', 'custom_ast_api_create_item_arg', 10, 2 );
function custom_ast_api_create_item_arg( $args, $request ) {
// Always mark as Shipped regardless of what the API payload sent
$args['status_shipped'] = 1;
return $args;
}
Example — override carrier based on a custom request header
add_filter( 'ast_api_create_item_arg', 'ast_override_provider_from_header', 10, 2 );
function ast_override_provider_from_header( $args, $request ) {
$carrier = $request->get_header( 'X-Carrier-Override' );
if ( ! empty( $carrier ) ) {
$args['tracking_provider'] = sanitize_text_field( $carrier );
}
return $args;
}
Notes
- Changes made here affect only the arguments passed to the tracking creation function — they do not modify the original API request or response.
- Always return
$argsfrom the callback, even if you make no changes, or tracking creation will fail. - See the REST API reference for the full list of fields and their accepted values.