Automattic\WooCommerce\Internal\DataStores\StockNotifications
StockNotificationsDataStore::notification_exists_by_email
Check if a notification exists by email.
Метод класса: StockNotificationsDataStore{}
Хуков нет.
Возвращает
bool. True if the notification exists, false otherwise.
Использование
$StockNotificationsDataStore = new StockNotificationsDataStore(); $StockNotificationsDataStore->notification_exists_by_email( $product_id, $email ): bool;
- $product_id(int) (обязательный)
- The product ID.
- $email(строка) (обязательный)
- The email address.
Код StockNotificationsDataStore::notification_exists_by_email() StockNotificationsDataStore::notification exists by email WC 11.2.2
public function notification_exists_by_email( int $product_id, string $email ): bool {
$email = EmailNormalizer::normalize( $email );
if ( ! is_email( $email ) ) {
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_email = %s AND status IN (%s, %s) LIMIT 1', // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
array( $table, $product_id, $email, NotificationStatus::ACTIVE, NotificationStatus::PENDING )
);
return (int) $wpdb->get_var( $sql ) > 0; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}