1. Home
  2. Docs
  3. Pick List
  4. Hooks & Custom Code
  5. Auto-fill Tracking/Reference Number in Shipping Label Dialog

Auto-fill Tracking/Reference Number in Shipping Label Dialog

Pick List can print a shipping label and optionally include a barcode/QR based on a tracking/reference number.

Out of the box, Pick List does not connect directly to carrier APIs (UPS/FedEx/etc.) to purchase labels or fetch tracking numbers. Instead, Pick List can auto-fill the tracking/reference field if the value is stored on the WooCommerce order (order meta) by another plugin/service or custom code.

NOTE: From vs 2.6.2

Hook: cas_picklist_shipping_label_tracking_number

Use this filter to provide a tracking/reference number for the current order. If a non-empty value is returned:

  • Include Barcode will be pre-checked
  • the Tracking/Reference input will be pre-filled
  • Pick List can use it to generate barcode/QR on the label

Filter signature

/**
 * Provide tracking/reference number for Pick List shipping labels.
 *
 * @param string         $tracking_number Tracking/reference number to encode as barcode/QR.
 * @param int            $order_id        WooCommerce order ID.
 * @param WC_Order|false $order           WooCommerce order object (or false if not found).
 *
 * @return string Tracking/reference number (empty string = no prefill).
 */
apply_filters( 'cas_picklist_shipping_label_tracking_number', '', $order_id, $order );

Example 1: Read tracking number from a custom order meta key

If another plugin saves tracking to a known meta key (example: _tracking_number):

add_filter( 'cas_picklist_shipping_label_tracking_number', function( $tracking, $order_id, $order ) {

	$value = get_post_meta( $order_id, '_tracking_number', true );

	return is_string( $value ) ? trim( $value ) : '';

}, 10, 3 );

Example 2: Try multiple common meta keys (best-effort)

Useful when you are not sure which plugin writes the tracking number, or you support multiple setups:

add_filter( 'cas_picklist_shipping_label_tracking_number', function( $tracking, $order_id, $order ) {

	$candidates = [
		'_tracking_number',
		'tracking_number',
		'_aftership_tracking_number',
	];

	foreach ( $candidates as $key ) {
		$value = get_post_meta( $order_id, $key, true );
		if ( is_string( $value ) && '' !== trim( $value ) ) {
			return trim( $value );
		}
	}

	return '';

}, 10, 3 );

Example 3: Read tracking from an order item / shipping item meta

Some shipping integrations store tracking on shipping items rather than the order itself. This example loops shipping items and reads a meta key:

add_filter( 'cas_picklist_shipping_label_tracking_number', function( $tracking, $order_id, $order ) {

	if ( ! $order instanceof WC_Order ) {
		$order = wc_get_order( $order_id );
	}

	if ( ! $order ) {
		return '';
	}

	foreach ( $order->get_items( 'shipping' ) as $item_id => $item ) {
		$value = $item->get_meta( 'tracking_number', true );
		if ( is_string( $value ) && '' !== trim( $value ) ) {
			return trim( $value );
		}
	}

	return '';

}, 10, 3 );

Notes and best practices

  • Pick List will only prefill what you return from the filter. If tracking is not stored on the order yet, the field remains empty.
  • The tracking value should be a string (numbers are fine, but return them as a string).
  • Make sure tracking is stored before you open the shipping label dialog (i.e., after label purchase/creation).
  • If your workflow uses UPS rates at checkout but purchases labels elsewhere (ShipStation, UPS WorldShip, etc.), ensure the tracking number is written back to the WooCommerce order (meta) to enable auto-fill.

How can we help?