wc_set_customer_auth_cookie

Login a customer (set auth cookie and set global user object).

Description

wc_set_customer_auth_cookie( (int) $customer_id ); 

Parameters (1)

0. $customer_id (int)
The customer id.

Usage

  1. if ( !function_exists( 'wc_set_customer_auth_cookie' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-user-functions.php'; 
  3.  
  4. // The customer id. 
  5. $customer_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_set_customer_auth_cookie($customer_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-user-functions.php  
  1. function wc_set_customer_auth_cookie( $customer_id ) { 
  2. global $current_user; 
  3.  
  4. $current_user = get_user_by( 'id', $customer_id ); 
  5.  
  6. wp_set_auth_cookie( $customer_id, true );