• Resolved backpackingseries

    (@backpackingseries)


    Hello,

    I am trying to integrate the WooCommerce checkout workflow with Auth0, such that whenever a new WooCommerce customer account is created during checkout, it should automatically create an Auth0 user too.

    I have tested the following code (source) but it doesn’t work:

    function auth0_wp_test_hook_create_auth0_user_from_wp_admin( $wp_user_id ) {
    
    	// WordPress user was not created so do not proceed.
    	if ( is_wp_error( $wp_user_id ) ) {
    		return;
    	}
    
    	$a0_options = WP_Auth0_Options::Instance();
    	$payload    = array(
    		'client_id'  => $a0_options->get( 'client_id' ),
    		// This is run during a POST request to create the user so pull the data from global.
    		'email'      => $_POST['email'],
    		'password'   => $_POST['pass1'],
    		// Make sure this Database Connection is correct for your Auth0 configuration.
    		'connection' => 'Username-Password-Authentication',
    	);
    
    	$new_auth0_user = WP_Auth0_Api_Client::signup_user( $a0_options->get( 'domain' ), $payload );
    
    	// Returns false and logs an error in the plugin if this fails.
    	// The WP user was still created but the Auth0 was not.
    	if ( ! $new_auth0_user ) {
    		return;
    	}
    
    	// Auth0 user created; now update the usermeta to connect the two accounts.
    	$new_auth0_user->sub = 'auth0|' . $new_auth0_user->_id;
    	unset( $new_auth0_user->_id );
    	$user_repo = new WP_Auth0_UsersRepo( $a0_options );
    	$user_repo->update_auth0_object( $wp_user_id, $new_auth0_user );
    }
    add_action( 'edit_user_created_user', 'auth0_wp_test_hook_create_auth0_user_from_wp_admin', 10 );

    After adding this code, WooCommerce checkout continues to work normally, but an Auth0 user is not added at https://manage.auth0.com/dashboard/us/tenant/users . Even if it adds Auth0 data in WordPress users database, I guess it should work – as it wont ask for email verification the next login?

    Has someone tried this integration and can offer a working snippet? Would be really thankful!

    Kind regards,

    • This topic was modified 4 years, 1 month ago by backpackingseries.
    • This topic was modified 4 years, 1 month ago by Yui.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to Create Auth0 User Accounts for WooCommerce Customers during Checkout?’ is closed to new replies.