Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More โConditionally hide WooCommerce products using ACF True/False custom fields and woocommerce_product_query hook. Control product visibility based on custom field values without permanently deleting products. Implement flexible show/hide logic for seasonal products, exclusive items, or temporary unavailability. Includes meta query examples for single or multiple field conditions with advanced filtering options.
If you'd like to conditionally hide WooCommerce products using custom field values created with ACF (Advanced Custom Fields), you're in luck. In this guide, we’ll show how to filter WooCommerce queries using ACF fields to control product visibility.
Step 1: Install Required Plugins
Before proceeding, make sure you have these installed:
Step 2: Create a Custom ACF Field
Set up a field to determine if a product should be hidden:
hide_product.Step 3: Add Query Filter in functions.php
Add this snippet to your theme’s functions.php file to modify WooCommerce queries:
function custom_hide_products_based_on_acf_value($q)
{
if (!is_admin() && is_shop()) {
$meta_query = $q->get('meta_query');
$meta_query[] = array(
'key' => 'hide_product',
'value' => '1',
'compare' => '!=',
);
$q->set('meta_query', $meta_query);
}
}
add_action('woocommerce_product_query', 'custom_hide_products_based_on_acf_value');
Step 4: Verify Product Visibility
Set the hide_product field to "true" for any product you want hidden. These will no longer show on shop/archive pages.
Step 5: Optional Advanced Conditions
You can also combine multiple ACF fields using this structure:
function custom_hide_products_based_on_acf_value($q)
{
if (!is_admin() && is_post_type_archive('product') && $q->is_main_query()) {
$meta_query = $q->get('meta_query');
$meta_query[] = array(
'key' => 'hide_product',
'value' => '1',
'compare' => '!=',
);
$meta_query[] = array(
'key' => 'another_custom_field',
'value' => 'some_value',
'compare' => '=',
);
$meta_query['relation'] = 'OR';
$q->set('meta_query', $meta_query);
}
}
add_action('woocommerce_product_query', 'custom_hide_products_based_on_acf_value');
Step 6: Save & Test
Once the code is in place, update your products with the custom field values. Hidden products will no longer appear in listings.
Conclusion
This approach allows you to control product visibility in WooCommerce using ACF fields. It's ideal for hiding specific products based on any condition you define with custom fields.
Additional Resources

Search our archives or reach out to our team for solutions and expert advice.