2017-08-29 8 views
3

私は、ユーザーがイベントに登録するフォームを用意しています。希望する場合は、その場で請求情報の一部を更新できます。WooCommerceで顧客の課金情報をプログラムで更新する

私はその後、変更された情報を更新するWC_Customerクラスを使用しようとした例

$inputs = array(
     'billing_city'   => 'City', 
     'billing_postcode'  => 'Postcode', 
     'billing_email'   => 'Email', 
     'billing_phone'   => 'Phone', 
    ); 

のために、彼らは更新できる情報のリストを持っている:

$customer = new WC_Customer(get_current_user_id()); 
foreach ($inputs as $key => $label) { 
    $method = 'set_'. $key; 
    $customer->$method($value); 
} 

それはまっすぐ進むと思われます十分な。ただし、請求情報は変更されません。

私は間違っていますか?この問題に対処するはずの他の機能がありますか?

Woocommerceのドキュメントでは、あまり詳しく説明していません。

$user_id = get_current_user_id(); 

$data = array(
    'billing_city'   => $city_value, 
    'billing_postcode'  => $postcode_value, 
    'billing_email'   => $email_value, 
    'billing_phone'   => $phone_value, 
); 
foreach ($data as $meta_key => $meta_value) { 
    update_user_meta($user_id, $meta_key, $meta_value); 
} 

あなたは、配列に値を設定する必要があります。

答えて

関連する問題