WC_Customer_Download_Data_Store::read()publicWC 1.0

Method to read a download permission from the database.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WC_Customer_Download_Data_Store = new WC_Customer_Download_Data_Store();
$WC_Customer_Download_Data_Store->read( $download );
$download(WC_Customer_Download) (обязательный) (передается по ссылке — &)
WC_Customer_Download object.

Код WC_Customer_Download_Data_Store::read() WC 9.3.3

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

	if ( ! $download->get_id() ) {
		throw new Exception( __( 'Invalid download.', 'woocommerce' ) );
	}

	$download->set_defaults();
	$raw_download = $wpdb->get_row(
		$wpdb->prepare(
			"SELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE permission_id = %d",
			$download->get_id()
		)
	);

	if ( ! $raw_download ) {
		throw new Exception( __( 'Invalid download.', 'woocommerce' ) );
	}

	$download->set_props(
		array(
			'download_id'         => $raw_download->download_id,
			'product_id'          => $raw_download->product_id,
			'user_id'             => $raw_download->user_id,
			'user_email'          => $raw_download->user_email,
			'order_id'            => $raw_download->order_id,
			'order_key'           => $raw_download->order_key,
			'downloads_remaining' => $raw_download->downloads_remaining,
			'access_granted'      => strtotime( $raw_download->access_granted ),
			'download_count'      => $raw_download->download_count,
			'access_expires'      => is_null( $raw_download->access_expires ) ? null : strtotime( $raw_download->access_expires ),
		)
	);
	$download->set_object_read( true );
}