Packboard documentation1.x
Buy Pro· 5 sites · $99/year
Developers

Carriers and order numbers

Add your own carriers and tracking links, let the pack station find custom order numbers, and read tracking from code.

Note

This is part of Packboard Pro.

Put the examples in a small custom plugin or your child theme's functions.php.

packboard_tracking_carriers

The carriers in the ship dialog and their tracking links. Each one is a key, a name and a URL template, where %s is replaced by the tracking number. An empty URL means no link.

add_filter( 'packboard_tracking_carriers', function ( $carriers ) {
	$carriers['evri'] = array(
		'name' => 'Evri',
		'url'  => 'https://www.evri.com/track/parcel/%s',
	);
	unset( $carriers['australia_post'] ); // Not one we use.
	return $carriers;
} );

Keep the other entry: it's the fallback for numbers whose carrier is no longer in the list, and always comes last in the dialog.

With WooCommerce Order Fulfillments on, the dialog lists WooCommerce's carriers plus yours. A carrier you add that WooCommerce doesn't know is recorded as WooCommerce's "Other" provider, with your carrier's name and tracking link.

packboard_resolve_order_number

The pack station looks up a scanned order number as an order ID. If your store shows customers different numbers (from a sequential order number plugin, for example), tell it how to find the order. Gets the order ID it would use (the number itself) and the scanned number without the #; return the order ID.

// Orders numbered SHOP-1042, with the number saved in _order_number.
add_filter( 'packboard_resolve_order_number', function ( $order_id, $number ) {
	if ( preg_match( '/^SHOP-\d+$/', $number ) ) {
		$orders = wc_get_orders( array( 'meta_key' => '_order_number', 'meta_value' => $number, 'limit' => 1, 'return' => 'ids' ) );
		return $orders ? (int) $orders[0] : 0;
	}
	return $order_id;
}, 10, 2 );

Scanned numbers may contain letters, digits and dashes.

Reading tracking from code

use Extendiment\PackboardPro\Fulfillment\Tracking;

foreach ( Tracking::get( $order ) as $parcel ) {
	// $parcel: carrier, carrier_name, number, url, shipped_at (Unix time).
}

Tracking::get( $order ) includes WooCommerce fulfillments when that feature is on; Tracking::get( $order, false ) only what Packboard Pro stored itself, in the _packboard_tracking order meta.

A product's bin is Extendiment\PackboardPro\Fulfillment\PickList::bin( $product ) (a variation falls back to its product's), stored in the _packboard_bin product meta.

The pack station's REST route

GET /wp-json/packboard/v1/fulfillment/order/<number>, for users who can edit orders, returns the order card, its lines still to ship (sku, gtin, bin, name, qty) and the customer's note; 404 for an unknown order, 409 when it isn't Processing.

Packboard's hooks

Packboard Pro is built on Packboard's own hooks (packboard_ship_order, packboard_print_documents, packboard_admin_pages and the board's JavaScript filters), which you can use too; see Filters and hooks.