Automattic\WooCommerce\Internal\StockNotifications\Utilities

EligibilityService::should_skip_notificationpublicWC 1.0

Check if a notification is eligible for sending.

Method of the class: EligibilityService{}

Returns

true|false. True if the notification is eligible for sending, false otherwise.

Usage

$EligibilityService = new EligibilityService();
$EligibilityService->should_skip_notification( $notification, $product ): bool;
$notification(Notification) (required)
The notification to check.
$product(WC_Product) (required)
The product to check.

EligibilityService::should_skip_notification() code WC 10.3.6

public function should_skip_notification( Notification $notification, WC_Product $product ): bool {
	$is_throttled         = $this->is_notification_throttled( $notification );
	$is_product_published = in_array( $product->get_status(), Config::get_supported_product_statuses(), true );
	$should_skip          = $is_throttled || ! $is_product_published;

	// Bypass for privileged users.
	if ( $should_skip ) {
		$user_id = $notification->get_user_id();
		if ( $user_id ) {
			$user = get_user_by( 'id', $user_id );
			if ( $user && ( user_can( $user, 'manage_woocommerce' ) || user_can( $user, 'manage_options' ) ) ) {
				$should_skip = false;
			}
		}
	}

	/**
	 * Filter: woocommerce_customer_stock_notification_should_skip_sending
	 *
	 * @since 10.2.0
	 *
	 * Prevent or manage sending a specific notification.
	 *
	 * @param bool $should_skip Whether to skip sending.
	 * @param int  $notification_id The notification ID.
	 * @return bool
	 */
	return (bool) apply_filters( 'woocommerce_customer_stock_notification_should_skip_sending', $should_skip, $notification->get_id() );
}