WC_Payment_Tokens::get_customer_tokens PHP Method

get_customer_tokens() public static method

Returns an array of payment token objects associated with the passed customer ID.
Since: 2.6.0
public static get_customer_tokens ( integer $customer_id, string $gateway_id = '' ) : array
$customer_id integer Customer ID
$gateway_id string Optional Gateway ID for getting tokens for a specific gateway
return array Array of token objects
    public static function get_customer_tokens($customer_id, $gateway_id = '')
    {
        if ($customer_id < 1) {
            return array();
        }
        $tokens = self::get_tokens(array('user_id' => $customer_id, 'gateway_id' => $gateway_id));
        return apply_filters('woocommerce_get_customer_payment_tokens', $tokens, $customer_id, $gateway_id);
    }

Usage Example

 protected function get_users_token()
 {
     $customer_token = null;
     if (is_user_logged_in()) {
         $tokens = WC_Payment_Tokens::get_customer_tokens(get_current_user_id());
         foreach ($tokens as $token) {
             if ($token->get_gateway_id() === $this->id) {
                 $customer_token = $token;
                 break;
             }
         }
     }
     return $customer_token;
 }
All Usage Examples Of WC_Payment_Tokens::get_customer_tokens