Skip to content

Instantly share code, notes, and snippets.

@zorem
Last active April 19, 2022 12:45
Show Gist options
  • Save zorem/18f7dd6292ca884b88c1f38e33259352 to your computer and use it in GitHub Desktop.
Save zorem/18f7dd6292ca884b88c1f38e33259352 to your computer and use it in GitHub Desktop.
Add AST tracking info in customer SMS using Twilio SMS Notifications plugin
/* add AST tracking info in customer SMS using Twilio SMS Notifications plugin */
add_filter( 'wc_twilio_sms_customer_sms_before_variable_replace', 'ast_pro_wc_twilio_sms_message_replacement', 10, 2 );
if ( !function_exists( 'ast_pro_wc_twilio_sms_message_replacement' ) ) {
function ast_pro_wc_twilio_sms_message_replacement( $message, $order ) {
if ( !function_exists( 'ast_get_tracking_items' ) ) {
return;
}
$order_id = $order->get_id();
$order_status = $order->get_status();
$tracking_items = ast_get_tracking_items($order_id);
//echo '<pre>';print_r($tracking_items);echo '</pre>';
//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;
}
}
@sotb0rlando
Copy link

Where do you add this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment