skip to Main Content

I enable WooCommerce rest API and generate consumer_key and consumer_secret. I am developing a WooCommerce shop native mobile application. I do research for the WooCommerce rest API for My Account page login and registration form but can’t see the solution. So if anyone has an idea about My Account page login and registration API then please suggest the solution for this.

Best regard,
Ketan.

2

Answers


  1. Chosen as BEST ANSWER

    ==> First install this https://wordpress.org/plugins/json-api-user/ plugin

    ==> Registration API:

    1. Before the registration call, following API for New nonce generate:

      https://site_URL/api/get_nonce/?controller=user&method=register

    2. After that use following API for registration:

      https://site_URL/api/user/register/?username=john&[email protected]&user_pass=123456789&nonce=HERE_INSERT_ABOVE_GENERATED_RANDOM_NONCE_STRING&display_name=username

    ==> Login API:

    1. Insert the following code in your child theme functions.php file:
    
    
    
        add_action( 'rest_api_init', 'register_api_hooks' );
        function register_api_hooks() {
          register_rest_route(
            'custom-plugin', '/login/',
            array(
              'methods'  => 'GET',
              'callback' => 'login',
            )
          );
        }
    
    
    
    function login($request){
        $creds = array();
        $creds['user_login'] = $request["username"];
        $creds['user_password'] =  $request["password"];
        $creds['remember'] = true;
        $user = wp_signon( $creds, false );
        if ( is_wp_error($user) )
          echo $user->get_error_message();
        return $user;
    }
    add_action( 'after_setup_theme', 'custom_login' );
    
    1. After that use following API for login:

      https://site_URL/wp-json/custom-plugin/login?username=USERNAME_OR_EMAIL-ID&password=PASSWORD


  2. add_action( ‘after_setup_theme’, ‘custom_login’ ); to add_action( ‘after_setup_theme’, ‘login’ );

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search