2017-08-12 13 views
0

WooCommerceでは、私のwebshopが新しい注文を受けたときに実行しているスクリプトがあります。このスクリプトはSMSを私に送信しますが、私はそれを顧客にも送信したいと思います。WooCommerceで受注される直前の顧客データを取得

スクリプトはカスタム関数スクリプトを使用して、注文に関する情報を注文受領ページの直前で実行しています。

ユーザーが使用した名前と電話番号に関する注文から自動情報を取得するにはどうすればよいですか?この読み

How to get WooCommerce order detailsポスト、私は必要な情報を得ることができ、私を助け、私がしようとすると、注文ページに障害が発生していませんが...

私のコードは、今日はこのようなものです:

add_action('template_redirect', 'wc_custom_redirect_after_purchase'); 
function wc_custom_redirect_after_purchase() { 
    global $wp; 

    if (is_checkout() && ! empty($wp->query_vars['order-received'])) { 

    // Query args 
    $query21 = http_build_query(array(
     'token' => 'My-Token', 
     'sender' => 'medexit', 
     'message' => 'NEW ORDER', 
     'recipients.0.msisdn' => 4511111111, 
    )); 
    // Send it 
    $result21 = file_get_contents('https://gatewayapi.com/rest/mtsms?' . $query21); 

    //  exit; 
    } 
} 

私はメッセージにファーストネームを含める必要があります。

私のような何か希望:

$firstname = $order_billing_first_name = $order_data['billing']['first_name']; 
$phone = $order_billing_phone = $order_data['billing']['phone']; 

をしかし、何も私の作品には思いません。

答えて

1

代わりにあなたが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'); 
} 

コードは、任意のプラグインファイルでも、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルになりますか。 WooCommerce 3 + ...


関連SMSの答えでテスト

:PERFECT、最初の部分は動作しませんでした

Sending an SMS for specific email notifications and order statuses

+0

!カスタム関数を作成することが鍵でした、ありがとう.... – user2975926

関連する問題