Automattic\WooCommerce\Internal\DataStores\StockNotifications
StockNotificationsDataStore::notification_exists_by_email
Check if a notification exists by email.
Method of the class: StockNotificationsDataStore{}
No Hooks.
Returns
true|false. True if the notification exists, false otherwise.
Usage
$StockNotificationsDataStore = new StockNotificationsDataStore(); $StockNotificationsDataStore->notification_exists_by_email( $product_id, $email ): bool;
- $product_id(int) (required)
- The product ID.
- $email(string) (required)
- The email address.
StockNotificationsDataStore::notification_exists_by_email() StockNotificationsDataStore::notification exists by email code WC 10.3.6
public function notification_exists_by_email( int $product_id, string $email ): bool {
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
}