I know that I should be able to add custom fields, including the WooCommerce "Featured" field, to the Views GUI so that I can filter by them, etc.
Currently, the WooCommerce "Featured" field doesn't display in the list of custom fields in the Views settings.
I see someone else has already reported this problem: https://toolset.com/forums/topic/toolset-views-not-showing-_featured-in-view-gui-for-woocommerce/
The fix suggested there does work for now, but this is obviously something that should be on the bug list.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Alison,
Thank you for contacting our support forum.
Unfortunately the for the featured items you will need to use a custom hook to achieve this.
Add the following to your functions.php file and it should only display the featured products.
/* --------------------------------------------- */
// WooCommerce 3+ featured products filter
// Only include "featured" products
add_filter( 'wpv_filter_query', 'featured_products',99,3 );
function featured_products( $query_args,$views_settings, $view_id) {
if ($view_id == 10){
$query_args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
}
return $query_args;
}
Just change the $view_id to the id of your view and it should work.
Thanks,
Shane
Thanks Shane. Like I said, that solution does work for me, but I wanted to file a bug report, given that WooCommerce custom fields are something Views typically supports.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Alison,
Actually this was the reason why this filter is being used because woocommerce moved from using a hidden custom field to a hidden taxonomy so the only way to filter for that term is by using the hook.
We found this out after doing some investigation on the field itself.
Thanks,
Shane
Ah, that makes sense. Thanks for the explanation!