ShipHero Integration
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_numbersmeta key onshop_orderposts - 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:
- ShipHero sends fulfillment webhook to
api-shiphero.php - api-shiphero.php processes serial numbers and executes:
$order->update_meta_data('serial_numbers', $serial_number); - WordPress
updated_post_metaaction fires - Our hook method detects this is a
serial_numbersupdate on ashop_order - Existing HubSpot system triggered via:
do_action('hubspot_sync_milli_process_serial_number', $order_id, $serial_number) - 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
- Debug messages in error logs starting with
[HubSpot Sync - Milli] DEBUG: - HubSpot device records appearing in CRM
- 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!