Automattic\WooCommerce\Internal\DataStores\StockNotifications

StockNotificationsDataStore::readpublicWC 1.0

Read a stock notification.

Method of the class: StockNotificationsDataStore{}

No Hooks.

Returns

null. Nothing (null).

Usage

$StockNotificationsDataStore = new StockNotificationsDataStore();
$StockNotificationsDataStore->read( $notification );
$notification(Notification) (required) (passed by reference — &)
The data object to read.

StockNotificationsDataStore::read() code WC 10.3.6

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

	if ( 0 === $notification->get_id() ) {
		throw new \Exception( 'Invalid notification ID.' );
	}

	$data = $wpdb->get_row(
		$wpdb->prepare(
			'SELECT * FROM %i WHERE id = %d',
			$this->get_table_name(),
			$notification->get_id()
		)
	);

	if ( ! $data ) {
		throw new \Exception( 'Stock notification not found' );
	}

	$notification->set_props(
		array(
			'id'                  => $data->id,
			'product_id'          => $data->product_id,
			'user_id'             => $data->user_id,
			'user_email'          => $data->user_email,
			'status'              => $data->status,
			'date_created'        => wc_string_to_timestamp( $data->date_created_gmt ),
			'date_modified'       => wc_string_to_timestamp( $data->date_modified_gmt ),
			'date_confirmed'      => wc_string_to_timestamp( $data->date_confirmed_gmt ),
			'date_last_attempt'   => wc_string_to_timestamp( $data->date_last_attempt_gmt ),
			'date_notified'       => wc_string_to_timestamp( $data->date_notified_gmt ),
			'date_cancelled'      => wc_string_to_timestamp( $data->date_cancelled_gmt ),
			'cancellation_source' => $data->cancellation_source,
		)
	);

	$notification->read_meta_data();
	$notification->set_object_read( true );
}