相反,您可以尝试使用挂接在
woocommerce_thankyou
add_action( 'woocommerce_thankyou', 'wc_custom_sending_sms_after_purchase', 20, 1 );
function wc_custom_sending_sms_after_purchase( $order_id ) {
if ( ! $order_id ) return;
// Avoid SMS to be sent twice
$sms_new_order_sent = get_post_meta( $order_id, '_sms_new_order_sent', true );
if( 'yes' == $sms_new_order_sent ) return;
// Get the user complete name and billing phone
$user_complete_name = get_post_meta( $order_id, '_billing_first_name', true ) . ' ';
$user_complete_name .= get_post_meta( $order_id, '_billing_last_name', true );
$user_phone = get_post_meta( $order_id, '_billing_phone', true );
// 1st Query args (to the admin)
$query1 = http_build_query( array(
'token' => 'My-Token',
'sender' => 'medexit',
'message' => 'NEW ORDER',
'recipients.0.msisdn' => 4511111111
) );
// 2nd Query args (to the customer)
$query2 = http_build_query( array(
'token' => 'My-Token',
'sender' => 'medexit',
'message' => "Hello $user_complete_name. This is your new order confirmation",
'recipients.0.msisdn' => intval($user_phone)
) );
// Send both SMS
file_get_contents('https://gatewayapi.com/rest/mtsms?' . $query1);
file_get_contents('https://gatewayapi.com/rest/mtsms?' . $query2);
// Update (avoiding SMS to be sent twice)
update_post_meta( $order_id, '_sms_new_order_sent', 'yes' );
}
代码进入函数。活动子主题(或主题)或任何插件文件中的php文件。
相关短信回复:
Sending an SMS for specific email notifications and order statuses