Automattic\WooCommerce\Internal\DataStores\StockNotifications

StockNotificationsDataStore::notification_exists_by_user_id │ public │ WC 1.0

Check if a notification exists by user ID.

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

Хуков нет.

Возвращает

bool. True if the notification exists, false otherwise.

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

$StockNotificationsDataStore = new StockNotificationsDataStore();
$StockNotificationsDataStore->notification_exists_by_user_id( $product_id, $user_id ): bool;
$product_id(int) (обязательный)
The product ID.
$user_id(int) (обязательный)
The user ID.

Код StockNotificationsDataStore::notification_exists_by_user_id() WC 11.2.2

public function notification_exists_by_user_id( int $product_id, int $user_id ): bool {

	if ( 0 === $user_id ) {
		return false;
	}

	global $wpdb;

	$table = $this->get_table_name();
	$sql   = $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
		'SELECT 1 FROM %i WHERE product_id = %d AND user_id = %d AND status IN (%s, %s) LIMIT 1', // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		array( $table, $product_id, $user_id, NotificationStatus::ACTIVE, NotificationStatus::PENDING )
	);
	return (int) $wpdb->get_var( $sql ) > 0; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}