Skip to content

Instantly share code, notes, and snippets.

Last active October 19, 2021 11:41
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
AfterShip webhook for WordPress
//Aftership Automatic Tracker
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment