Skip to main content

Shipment Tracking

Overview​

The Shipment Tracking module allows store owners to add tracking information to WooCommerce orders and automatically display tracking links to customers through emails and My Account pages.

Features​

Core Features​

  • Multiple Tracking Entries: Add multiple shipment tracking entries per order
  • Built-in Providers: Pre-configured tracking URLs for major carriers (FedEx, UPS, USPS, DHL, etc.)
  • Custom Providers: Add custom shipping providers with custom tracking URL templates
  • Email Integration: Automatically include tracking info in WooCommerce order emails
  • My Account Display: Show tracking information on the customer's order view page
  • Order Received Page: Display tracking on the thank you page

Admin Features​

  • Order Meta Box: HPOS-compatible meta box on order edit screen
  • Admin Dashboard Page: Central management UI with 4 tabs:
    • Overview: Statistics and recent tracking activity
    • Providers: Manage default and custom providers
    • Settings: Configure email and display settings
    • Diagnostics: Health checks and maintenance actions

File Structure​

includes/Modules/ShipmentTracking/
├── ShipmentTrackingModule.php # Main module entry point
├── Schema/
│ └── DatabaseSchema.php # Database table schema
├── DTO/
│ └── TrackingEntry.php # Tracking entry data structure
├── Repository/
│ └── TrackingRepository.php # CRUD operations for tracking entries
├── Service/
│ ├── ProviderRegistry.php # Provider management and URL building
│ ├── TrackingService.php # Business logic
│ └── DiagnosticsService.php # Health checks
├── Frontend/
│ ├── EmailHandler.php # Email injection
│ └── AccountHandler.php # My Account display
├── Admin/
│ └── OrderMetaBox.php # Order edit screen meta box
├── Jobs/
│ └── TrackingCleanupJob.php # Cleanup orphaned entries
└── Rest/
└── ShipmentTrackingRest.php # REST API endpoints

Database Schema​

Table: {prefix}aiowc_shipment_tracking_entries​

ColumnTypeDescription
idBIGINT PKAuto-increment
order_idBIGINTWC order ID (indexed)
provider_keyVARCHAR(50)Provider slug (e.g., 'fedex')
provider_nameVARCHAR(100)Display name
tracking_numberVARCHAR(100)Tracking number
tracking_urlVARCHAR(500) NULLCustom URL (overrides provider default)
shipped_atDATETIME NULLShip date
created_atDATETIMEEntry created
updated_atDATETIMELast modified

Default Shipping Providers​

ProviderKeyTracking URL
FedExfedexhttps://www.fedex.com/fedextrack/?trknbr={tracking_number}
UPSupshttps://www.ups.com/track?tracknum={tracking_number}
USPSuspshttps://tools.usps.com/go/TrackConfirmAction?tLabels={tracking_number}
DHLdhlhttps://www.dhl.com/en/express/tracking.html?AWB={tracking_number}
DHL eCommercedhl_ecommercehttps://webtrack.dhlecs.com/orders?trackingNumber={tracking_number}
Royal Mailroyal_mailhttps://www.royalmail.com/track-your-item#/tracking-results/{tracking_number}
Australia Postaustralia_posthttps://auspost.com.au/mypost/track/#/details/{tracking_number}
Canada Postcanada_posthttps://www.canadapost-postescanada.ca/track-reperage/en#/search?searchFor={tracking_number}
Deutsche Postdeutsche_posthttps://www.deutschepost.de/sendung/simpleQuery.html?locale=en_GB&form.sendungsnummer={tracking_number}
Aramexaramexhttps://www.aramex.com/track/shipments?ShipmentNumber={tracking_number}

REST API Endpoints​

All endpoints require manage_woocommerce capability.

Settings​

MethodEndpointDescription
GET/aiowc/v1/shipment-tracking/settingsGet module settings
PUT/aiowc/v1/shipment-tracking/settingsUpdate settings

Providers​

MethodEndpointDescription
GET/aiowc/v1/shipment-tracking/providersList all providers
POST/aiowc/v1/shipment-tracking/providersAdd custom provider
PUT/aiowc/v1/shipment-tracking/providers/{key}Update provider
DELETE/aiowc/v1/shipment-tracking/providers/{key}Delete custom provider
POST/aiowc/v1/shipment-tracking/providers/{key}/toggleToggle provider enabled

Statistics & Diagnostics​

MethodEndpointDescription
GET/aiowc/v1/shipment-tracking/statisticsOverview stats
GET/aiowc/v1/shipment-tracking/diagnosticsHealth check
POST/aiowc/v1/shipment-tracking/cleanupTrigger cleanup job

Tracking Entries​

MethodEndpointDescription
GET/aiowc/v1/shipment-tracking/orders/{orderId}/entriesGet entries for order
POST/aiowc/v1/shipment-tracking/orders/{orderId}/entriesAdd tracking entry
GET/aiowc/v1/shipment-tracking/entries/{id}Get single entry
PUT/aiowc/v1/shipment-tracking/entries/{id}Update entry
DELETE/aiowc/v1/shipment-tracking/entries/{id}Delete entry
GET/aiowc/v1/shipment-tracking/entries/recentGet recent entries

Settings​

Email Settings​

  • Include in Completed Order Email: Include tracking info in completed order email
  • Include in Shipped Order Email: Include tracking in shipped status email
  • Include in Processing Order Email: Include tracking in processing email

Display Settings​

  • Show in Order View: Display tracking on My Account order view
  • Show in Order Emails: Display tracking information in emails
  • Show Provider Logo: Display shipping provider logos when available
  • Date Format: Format for displaying ship dates

Usage​

Adding Tracking from Admin​

  1. Go to WooCommerce > Orders
  2. Edit an order
  3. Find the "Shipment Tracking" meta box
  4. Select a provider, enter tracking number, and optionally set ship date
  5. Click "Add Tracking"

Viewing Tracking as Customer​

Customers can view tracking information:

  • In order confirmation/completion emails
  • On the "Thank You" page after checkout
  • In My Account > Orders > View Order

WooCommerce Hooks​

Email Integration​

// Add tracking to order emails
add_action('woocommerce_email_after_order_table', [$this, 'displayTrackingInEmail']);

Account Page Integration​

// Display on order view page
add_action('woocommerce_order_details_after_order_table', [$this, 'displayTrackingOnOrderView']);

// Display on thank you page
add_action('woocommerce_thankyou', [$this, 'displayTrackingOnThankYou']);

HPOS Compatibility​

The module is fully compatible with WooCommerce High-Performance Order Storage (HPOS):

  • Uses $order->get_meta() and $order->update_meta_data() instead of post meta functions
  • Uses action hooks instead of add_meta_box() for order edit screen

Background Jobs​

Tracking Cleanup Job​

  • Hook: aiowc_shipment_tracking_cleanup
  • Schedule: Daily
  • Purpose: Removes orphaned tracking entries (entries for deleted orders)

Observability Events​

EventDescription
shipment_tracking_page_viewedAdmin viewed tracking page
shipment_tracking_settings_savedSettings were updated
shipment_tracking_entry_addedTracking entry added
shipment_tracking_entry_updatedTracking entry updated
shipment_tracking_entry_deletedTracking entry deleted
shipment_tracking_provider_addedCustom provider added
shipment_tracking_provider_deletedCustom provider deleted
shipment_tracking_provider_toggledProvider enabled/disabled
shipment_tracking_cleanup_runCleanup job executed
shipment_tracking_diagnostics_runDiagnostics check run