Skip Navigation

[Resolved] How to filter a View by WooCommerce Featured Product

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Anthony 3 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2113695

I'm using WooCommerce. I want to have a View that only shows Featured Products - that doesn't seem to be an available Query Filter? Am I missing something, or do I have to create my own separate Custom Field for the WooCommerce CPT?

#2114051

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes - there is no GUI option available to filters the featured products but there is workaround.

You can create your view and configure the loop editor to display whatever content you would like to display and add the following code to the "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpv_filter_query', 'func_featured_products',99,3 );
function func_featured_products( $query_args,$views_settings, $view_id) {
       
if ($view_id == 99999){
$query_args['tax_query'] = array(
    array(
      'taxonomy'     => 'product_visibility',
      'field'   => 'name',
      'terms' => 'featured',
      'operator' => 'IN'
    ),
  );
}
    return $query_args;
}

Where:
- Replace 99999 with your original view ID.

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#2114095

Minesh has provided a code snippet that resolved this issue. Thank you again, Minesh, and the whole Toolset support team for always providing clear explanations and excellent help!