Skip to content

Instantly share code, notes, and snippets.

@zorem
Last active April 13, 2022 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorem/bd9a29807ee2cd057345fa9fe284eedc to your computer and use it in GitHub Desktop.
Save zorem/bd9a29807ee2cd057345fa9fe284eedc to your computer and use it in GitHub Desktop.
Compatibility with - WC – APG SMS Notifications. Add tracking info in SMS when order status is completed
add_filter( 'apg_sms_message', 'ast_pro_apg_sms_message_fun', 10, 2 );
/**
* Add tracking info in SMS when order status is completed
* Compatibility with - WC – APG SMS Notifications
*
*/
if ( !function_exists( 'ast_pro_apg_sms_message_fun' ) ) {
function ast_pro_apg_sms_message_fun( $message , $order_id ) {
if ( !function_exists( 'ast_get_tracking_items' ) ) {
return;
}
$order = wc_get_order( $order_id );
$order_status = $order->get_status();
$tracking_items = ast_get_tracking_items($order_id);
//You can comment this condition if you don't want to add tracking information on completed order status SMS message.
if ( 'completed' == $order_status || 'shipped' == $order_status ) {
if ( count( $tracking_items ) > 0 ) {
foreach ( $tracking_items as $key => $tracking_item ) {
$message .= sprintf(__("Your order was shipped with %s and your tracking code is: %s", 'ast-pro'), $tracking_item['formatted_tracking_provider'], $tracking_item['tracking_number'] );
}
}
}
//You can comment this condition if you don't want to add tracking information on Partially Shipped order status SMS message.
if ( 'partial-shipped' == $order_status ) {
if ( count( $tracking_items ) > 0 ) {
foreach ( $tracking_items as $key => $tracking_item ) {
$message .= sprintf(__("Your order was Partially Shipped with %s and your tracking code is: %s", 'ast-pro'), $tracking_item['formatted_tracking_provider'], $tracking_item['tracking_number'] );
}
}
}
return $message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment