WC_Payment_Token_Data_Store::read()publicWC 3.0.0

Read a token from the database.

Method of the class: WC_Payment_Token_Data_Store{}

Hooks from the method

Return

null. Nothing (null).

Usage

$WC_Payment_Token_Data_Store = new WC_Payment_Token_Data_Store();
$WC_Payment_Token_Data_Store->read( $token );
$token(WC_Payment_Token) (required) (passed by reference — &)
Payment token object.

Changelog

Since 3.0.0 Introduced.

WC_Payment_Token_Data_Store::read() code WC 9.4.2

public function read( &$token ) {
	global $wpdb;

	$data = $wpdb->get_row(
		$wpdb->prepare(
			"SELECT token, user_id, gateway_id, is_default FROM {$wpdb->prefix}woocommerce_payment_tokens WHERE token_id = %d LIMIT 1",
			$token->get_id()
		)
	);

	if ( $data ) {
		$token->set_props(
			array(
				'token'      => $data->token,
				'user_id'    => $data->user_id,
				'gateway_id' => $data->gateway_id,
				'default'    => $data->is_default,
			)
		);
		$this->read_extra_data( $token );
		$token->read_meta_data();
		$token->set_object_read( true );
		do_action( 'woocommerce_payment_token_loaded', $token );
	} else {
		throw new Exception( __( 'Invalid payment token.', 'woocommerce' ) );
	}
}