Extract a ShipStation Tracking Number From WooCommerce Order Meta

Quick Summary

  • Load the WooCommerce order with wc_get_order(), read its mailchimp_woocommerce_landing_site meta, and pull the ShipStation tracking_number from that URL's query string.
  • get_meta() works for orders stored as posts or in HPOS tables, and parse_url() plus parse_str() turn the query string into an array.
  • Confirm your meta key and parameter name on a real order, and add isset() or empty() checks, since missing data triggers errors.

This WooCommerce snippet reads a tracking number from an order’s meta data. In the setup it was written for, the ShipStation tracking number is stored as a tracking_number parameter inside a URL, and that URL is saved in the order meta field mailchimp_woocommerce_landing_site. The code pulls the number out of the URL’s query string.

Before you use it, open an order and check where your tracking number is actually stored: the meta key and the parameter name must match your data. Use the code wherever you already have an order ID, such as a hook callback in a custom plugin or your child theme’s functions.php.

PHP
$order = wc_get_order( $order_id );
$mailchimp_message = $order->get_meta('mailchimp_woocommerce_landing_site');

$parts = parse_url($mailchimp_message);
parse_str($parts['query'], $query);
$track_number = $query['tracking_number'];

How the code reads the tracking number from WooCommerce order meta

  • wc_get_order() loads the order. $order_id must already be set, for example by the hook you use the code in.
  • get_meta() reads the meta field. It works whether orders are stored as posts or in WooCommerce’s custom order tables (HPOS), so prefer it over get_post_meta() for orders.
  • parse_url() splits the stored URL into its parts, and parse_str() turns the query string into the $query array.
  • $query['tracking_number'] is the value you want. Change the key if your parameter has a different name.

The code doesn’t check that anything exists. If the ID isn’t a valid order, wc_get_order() returns false and the next line fails. If the field is empty, or the URL has no query string or no tracking_number, PHP shows warnings and $track_number has no value. Check with isset() or empty() before you use the number, and escape it with esc_html() when you print it.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More