Skip to content

Instantly share code, notes, and snippets.

@hendcorp
Last active Oct 19, 2021
Embed
What would you like to do?
AfterShip webhook for WordPress
<?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