Automattic\WooCommerce\Internal\DataStores\StockNotifications
StockNotificationsDataStore::notification_exists_by_user_id
Check if a notification exists by user ID.
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_user_id( $product_id, $user_id ): bool;
- $product_id(int) (required)
- The product ID.
- $user_id(int) (required)
- The user ID.
StockNotificationsDataStore::notification_exists_by_user_id() StockNotificationsDataStore::notification exists by user id code WC 10.3.6
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
}