For store owners managing hundreds of products, setting featured items manually is inefficient. A dynamic approach can save admin time by automatically marking products as featured based on specific conditions, such as category, price, or custom logic.
Normally, you’d mark WooCommerce products as featured by logging into wp-admin and clicking the “star” icon in the Products table. But what if you could automate this without clicking anything?
Thankfully, WooCommerce provides a filter hook that allows you to override the featured status on the fly. This means you can apply rules programmatically while keeping your admin time at zero.
Here’s how you can achieve this with a simple PHP snippet!

PHP Snippet #1: Conditionally Mark WooCommerce Product IDs as Featured
This function uses a WooCommerce filter to automatically mark certain products as featured without changing their data in the database. Here’s a breakdown:
add_filter
: This tells WooCommerce to apply the custom function whenever it checks whether a product is featured.bbloomer_mark_products_as_featured
: This is the custom function that checks the featured status.- Product Check: Inside the function, we check if the product’s ID is one of the specified IDs (
123
,456
,789
). If it is, the product will be marked as featured. - Return Featured Status: If the product ID matches, it returns
true
, marking the product as featured. Otherwise, it keeps the original status ($featured
).
In simple terms, this function automatically marks certain products as featured based on their ID without manual actions.
/**
* @snippet Set WooCommerce Featured Products Programmatically
* @tutorial https://businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_product_get_featured', 'bbloomer_mark_products_as_featured', 9999, 2 );
function bbloomer_mark_products_as_featured( $featured, $product ) {
if ( in_array( $product->get_id(), [ 123, 456, 789 ] ) ) {
return true;
}
return $featured;
}
PHP Snippet #2: Conditionally Mark a Whole WooCommerce Product Category as Featured
add_filter
: This adds a filter that hooks into WooCommerce’s process of determining whether a product is featured.bbloomer_mark_products_as_featured
: This is the custom function that will decide whether a product is featured based on category.has_term
: This checks if the product belongs to the ‘yoga’ category.- Return
true
: If the product is in the ‘yoga’ category, the function marks it as featured. - Return original status: If the product isn’t in the ‘yoga’ category, the original featured status is kept.
This code will automatically mark all products in the ‘yoga’ category as featured, without modifying the database.
/**
* @snippet Set WooCommerce Featured Products Programmatically
* @tutorial https://businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_product_get_featured', 'bbloomer_mark_products_as_featured', 9999, 2 );
function bbloomer_mark_products_as_featured( $featured, $product ) {
if ( has_term( 'yoga', 'product_cat', $product->get_id() ) ) {
return true;
}
return $featured;
}