Automattic\WooCommerce\Internal\StockNotifications\Utilities
EligibilityService::is_product_eligible
Validate product type and other basic criteria for notifications.
Method of the class: EligibilityService{}
Hooks from the method
Returns
true|false. True if the product is eligible for notifications, false otherwise.
Usage
$EligibilityService = new EligibilityService(); $EligibilityService->is_product_eligible( ?WC_Product $product ): bool;
- ?WC_Product $product(required)
- .
EligibilityService::is_product_eligible() EligibilityService::is product eligible code WC 10.3.6
public function is_product_eligible( ?WC_Product $product ): bool {
if ( ! $product instanceof WC_Product ) {
return false;
}
if ( ! $product->is_type( Config::get_supported_product_types() ) ) {
return false;
}
// Check for invalid product statuses.
if ( in_array( $product->get_status(), array( ProductStatus::TRASH, ProductStatus::AUTO_DRAFT, ProductStatus::PENDING, ProductStatus::FUTURE ), true ) ) {
return false;
}
/**
* Filter: woocommerce_customer_stock_notifications_product_is_valid
* Allows custom validation for whether a product is generally eligible for notifications.
*
* @since 10.2.0
*
* @param bool $is_valid True if the product is valid for notifications, false otherwise.
* @param WC_Product $product The product to check.
* @return bool True if the product is valid for notifications, false otherwise.
*/
return (bool) apply_filters( 'woocommerce_customer_stock_notifications_product_is_valid', true, $product );
}