WordPress at Your Fingertips
function is not described

WC_Payment_Tokens::set_users_default() public WC 2.6.0

Loops through all of a users payment tokens and sets is_default to false for all but a specific token.

{} It's a method of the class: WC_Payment_Tokens{}

Return

null. Nothing.

Usage

$result = WC_Payment_Tokens::set_users_default( $user_id, $token_id );
$user_id(int) (required)
User to set a default for.
$token_id(int) (required)
The ID of the token that should be default.

Changelog

Since 2.6.0 Introduced.

Code of WC_Payment_Tokens::set_users_default() WC 5.6.0

public static function set_users_default( $user_id, $token_id ) {
	$data_store   = WC_Data_Store::load( 'payment-token' );
	$users_tokens = self::get_customer_tokens( $user_id );
	foreach ( $users_tokens as $token ) {
		if ( $token_id === $token->get_id() ) {
			$data_store->set_default_status( $token->get_id(), true );
			do_action( 'woocommerce_payment_token_set_default', $token_id, $token );
		} else {
			$data_store->set_default_status( $token->get_id(), false );
		}
	}
}