Automattic\WooCommerce\Internal\DataStores\StockNotifications
StockNotificationsDataStore::product_has_active_notifications
Check if the product has active notifications.
Method of the class: StockNotificationsDataStore{}
No Hooks.
Returns
true|false. True if the product has active notifications, false otherwise.
Usage
$StockNotificationsDataStore = new StockNotificationsDataStore(); $StockNotificationsDataStore->product_has_active_notifications( $product_ids ): bool;
- $product_ids(array
) (required) - The product IDs.
StockNotificationsDataStore::product_has_active_notifications() StockNotificationsDataStore::product has active notifications code WC 10.3.6
public function product_has_active_notifications( array $product_ids ): bool {
global $wpdb;
$product_ids = array_filter( array_map( 'absint', $product_ids ) );
if ( empty( $product_ids ) ) {
return false;
}
$table = $this->get_table_name();
$format = array_fill( 0, count( $product_ids ), '%d' );
$query_in = '(' . implode( ',', $format ) . ')';
$sql = $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
"SELECT 1 FROM %i WHERE product_id IN $query_in AND status = %s LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
array( $table, ...$product_ids, NotificationStatus::ACTIVE )
);
return (int) $wpdb->get_var( $sql ) > 0; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}