【发布时间】:2019-08-06 00:23:50
【问题描述】:
我有一个商店,用户在个人资料中注册了数据。在结帐页面中,可以更改自动填充的数据(拉动配置文件)。
我希望:例如,如果客户输入另一个地址或另一个电子邮件,这些数据将不会保存在配置文件中。
【问题讨论】:
标签: php wordpress woocommerce checkout hook-woocommerce
我有一个商店,用户在个人资料中注册了数据。在结帐页面中,可以更改自动填充的数据(拉动配置文件)。
我希望:例如,如果客户输入另一个地址或另一个电子邮件,这些数据将不会保存在配置文件中。
【问题讨论】:
标签: php wordpress woocommerce checkout hook-woocommerce
如果下订单时数据已经存在,以下将禁用更新用户配置文件(参见WC_Checkoutprocess_customer()方法source code):
add_filter( 'woocommerce_checkout_update_customer_data', 'checkout_update_customer_data_callback', 10, 2 );
function checkout_update_customer_data_callback( $boolean, $checkout ) {
if ( get_current_user_id() > 0 ) {
$customer = new WC_Customer( get_current_user_id() );
$first_name = $customer->get_first_name();
// When customer data already exist, don't update it when an order is processed
if ( ! empty( $first_name ) ) {
return false;
}
}
return $boolean;
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试并且可以工作。
【讨论】: