在WooCommerce中以编程方式更新客户的结算信息
问题描述:
我有一个表单,用户注册一个事件,如果他们想要,他们可以即时更新他们的一些结算信息。在WooCommerce中以编程方式更新客户的结算信息
我有,他们可以更新信息的列表,例如
$inputs = array(
'billing_city' => 'City',
'billing_postcode' => 'Postcode',
'billing_email' => 'Email',
'billing_phone' => 'Phone',
);
然后我试图使用WC_Customer
类更新变化的信息:
$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);
}
您需要在阵列中设置的值: