AfterShip webhook for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Aftership Automatic Tracker | |
add_action('wp_head','trackship_catcher'); | |
function trackship_catcher() { | |
if(isset($_GET['webhook-listener']) && $_GET['webhook-listener'] == 'trackship') { | |
//Get and decode JSON | |
$str = file_get_contents("php://input"); | |
$json = json_decode($str, true); | |
//Extract Required Variables | |
$trackingnumber = $json['msg']['tracking_number']; | |
$shipmentstatus = $json['msg']['tag']; | |
$shiporderid = $json['msg']['order_id']; | |
//Update to the latest shipment status | |
update_post_meta( $shiporderid, '_shipment_status', $shipmentstatus ); | |
//Check if shipping status = InTransit, set order status to complete | |
if($shipmentstatus == 'InTransit'): | |
$order = wc_get_order( $shiporderid ); | |
$order->update_status( 'completed' ); | |
endif; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment