WC_Payment_Tokens::get()public staticWC 2.6.0

Get a token object by ID.

Метод класса: WC_Payment_Tokens{}

Хуков нет.

Возвращает

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

Использование

$result = WC_Payment_Tokens::get( $token_id, $token_result );
$token_id(int) (обязательный)
Token ID.
$token_result(объект)
Token result.
По умолчанию: null

Список изменений

С версии 2.6.0 Введена.

Код WC_Payment_Tokens::get() WC 8.7.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;
}