1

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.

1 Answer 1

1

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):

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). Tested and works.

Related: Disable woocommerce_checkout_update_customer_data

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.