ShipHero Integration Hook Implementation

What Was Added

I’ve successfully added a WordPress hook to monitor when the existing api-shiphero.php file updates order meta with serial numbers, and automatically trigger HubSpot device creation without modifying the existing ShipHero code.

Implementation Details

1. Added WordPress Hook

File: /hubspot-sync-milli/includes/class-hubspot-sync-milli.php

Hook Added:

add_action( 'updated_post_meta', array( $this, 'on_order_meta_updated' ), 10, 4 );

2. Created Monitoring Method

Method: on_order_meta_updated()

This method:

  • Monitors all WordPress post meta updates
  • Specifically watches for serial_numbers meta key on shop_order posts
  • Validates the order exists and HubSpot sync is enabled
  • Parses comma-separated serial numbers
  • Prevents duplicate processing
  • Triggers the existing HubSpot device creation system

3. Integration Flow

ShipHero Webhook → api-shiphero.php → Order Meta Update → WordPress Hook → HubSpot Device Creation

Detailed Flow:

  1. ShipHero sends fulfillment webhook to api-shiphero.php
  2. api-shiphero.php processes serial numbers and executes: $order->update_meta_data('serial_numbers', $serial_number);
  3. WordPress updated_post_meta action fires
  4. Our hook method detects this is a serial_numbers update on a shop_order
  5. Existing HubSpot system triggered via: do_action('hubspot_sync_milli_process_serial_number', $order_id, $serial_number)
  6. HubSpot device created using established infrastructure

Benefits

Zero modifications to existing api-shiphero.php
Uses existing HubSpot device creation system
Automatic detection of serial number additions
Duplicate prevention built-in
Debug logging for troubleshooting
Respects plugin settings (sync enabled/disabled)

Testing

Test File Created

File: /hubspot-sync-milli/test-shiphero-integration.php

Usage:

  • Navigate to the test file in browser
  • Select a recent order to test with
  • Click test link to simulate serial number addition
  • Check error logs for debug messages

Manual Testing URLs

?test=1&order_id=12345&serial=TEST-123456

What to Look For

  1. Debug messages in error logs starting with [HubSpot Sync - Milli] DEBUG:
  2. HubSpot device records appearing in CRM
  3. Order meta being updated with device IDs

Configuration

No additional configuration needed! The integration automatically:

  • Uses existing HubSpot API settings
  • Respects existing sync preferences
  • Follows existing device creation rules
  • Uses the same logging and error handling

Monitoring

The integration includes comprehensive logging:

[HubSpot Sync - Milli] DEBUG: ShipHero serial number update detected for order 12345: SN123456
[HubSpot Sync - Milli] DEBUG: Triggering HubSpot device creation for serial: SN123456 from order 12345
[HubSpot Sync - Milli] DEBUG: Processing single serial number SN123456 for order 12345
[HubSpot Sync - Milli] DEBUG: Successfully processed serial number SN123456 for order 12345

Production Readiness

This integration is production-ready because:

  • It uses WordPress’s native hook system
  • Integrates with proven existing code
  • Has comprehensive error handling
  • Includes duplicate prevention
  • Respects all existing plugin settings
  • Non-destructive (doesn’t modify existing files)

The integration is now active and monitoring for serial number updates from ShipHero!