我有一个商店,用户在该商店中在个人资料中注册了数据。在结帐页面中,可以更改自动填充的数据(拉出配置文件)。
我想:例如,如果客户输入另一个地址或另一个电子邮件,则该数据将不会保存在配置文件中。
答案 0 :(得分:1)
如果下订单时数据已经存在,以下内容将禁止更新用户配置文件(请参见WC_Checkout
process_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文件中。经过测试并可以工作。