WordPress at Your Fingertips
function is not described

WC_Payment_Tokens::get() public WC 2.6.0

Get a token object by ID.

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

No Hooks.

Return

null|WC_Payment_Token. Returns a valid payment token or null if no token can be found.

Usage

$result = WC_Payment_Tokens::get( $token_id, $token_result );
$token_id(int) (required)
Token ID.
$token_result(object)
Token result.
Default: null

Changelog

Since 2.6.0 Introduced.

Code of WC_Payment_Tokens::get() WC 5.6.0

public static function get( $token_id, $token_result = null ) {
	$data_store = WC_Data_Store::load( 'payment-token' );

	if ( is_null( $token_result ) ) {
		$token_result = $data_store->get_token_by_id( $token_id );
		// Still empty? Token doesn't exist? Don't continue.
		if ( empty( $token_result ) ) {
			return null;
		}
	}

	$token_class = self::get_token_classname( $token_result->type );

	if ( class_exists( $token_class ) ) {
		$meta        = $data_store->get_metadata( $token_id );
		$passed_meta = array();
		if ( ! empty( $meta ) ) {
			foreach ( $meta as $meta_key => $meta_value ) {
				$passed_meta[ $meta_key ] = $meta_value[0];
			}
		}
		return new $token_class( $token_id, (array) $token_result, $passed_meta );
	}

	return null;
}