• Hi all,

    I had a perfectly working code that stopped working after upgrade to Woo and WP (currently running WP 5.7 and Woo 5.1.0)

    function rl_save_extra_register_fields($customer_id){
        if(isset($_POST['billing_first_name'])){  update_user_meta($customer_id,'first_name',sanitize_text_field($_POST['billing_first_name']));
            
    
        // Update user role
        $user = new WP_User($customer_id);  
        $user->set_role('customer_pending');   
    
    }
    add_action('woocommerce_created_customer','rl_save_extra_register_fields');

    I extended normal user registration form with extra fields and want to change user role.
    Code used to work, now user data is not updated.

    What I checked/tested:
    1. Made sure my function fires
    2. Made sure correct $customer_id is used
    3. Made sure there is nothing else uses same action and overrides my changes (dumped $wp_filter[‘woocommerce_created_customer’])

    I then looked through the Woo code — nothing out of ordinary.(function wc_create_new_customer()) Standard WP function to create user and id of user inserted in database is passed to action. Should work, but it does not.
    I tried to change user role via ‘woocommerce_created_customer’ filter and that works.

    I also tried to create an WC_Customer object instead of WP_User:

    $user = new WC_Customer($customer_id);
    $user->set_role('customer_pending');

    Same!

    Any ideas why my code stopped working and user data can not be changed via ‘woocommerce_created_customer’ action?

    Thanks,
    Rudolf

    • This topic was modified 3 years, 11 months ago by rudolfl.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘‘woocommerce_new_customer_data’ hook not saving customer info’ is closed to new replies.