[英]Disable user profile update when data already exist after Woocommerce checkout
I have a store where users have data registered in the profile.我有一个商店,用户在配置文件中注册了数据。 In the checkout page there is the possibility to change the data that is automatically filled (pull of the profile).
在结帐页面中,可以更改自动填充的数据(拉取个人资料)。
I would like: if for example the customer enters another address or another email, that this data would NOT be saved in the profile.我想:例如,如果客户输入另一个地址或另一个电子邮件,则该数据不会保存在配置文件中。
The following will disable the user profile to be updated if the data already exist when an order is placed (see in WC_Checkout
process_customer()
method source code ) :如果下订单时数据已经存在,以下将禁止更新用户配置文件(参见
WC_Checkout
process_customer()
方法源代码) :
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;
}
Code goes in functions.php file of the active child theme (or active theme).代码位于活动子主题(或活动主题)的 functions.php 文件中。 Tested and works.
测试和工作。
Related: Disable woocommerce_checkout_update_customer_data相关: 禁用 woocommerce_checkout_update_customer_data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.