Skip Navigation

[Resolved] Display featured products

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user has a view that is listing their products but wanted to filter this view to only list the featured woocommerce products.

Solution:

For this to work you must first create a view that would list all the products.

Then you would add the following to your functions.php file

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;
}

Then you need to change the view_id to the ID of your view. Once you have done this then your view should only list the featured items.

0% of people find this useful.

This support ticket is created 6 years, 3 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 23 replies, has 3 voices.

Last updated by mouneebS-2 6 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1128312

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

The solution here:

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;
}

I've tested it and it works fine here hidden link

I created a test view and as you can see only the featured one shows up.

Thanks,
Shane

#1128885

.

#1128894
2.png
1.png

Hi Shane,

Thanks for the work. Are you referring the result shown in image 1?
I'm so sorry to say but do not want just a name for featured image I want to use featured products in slider with clickable url image. Just like the featured product section on home page. (see image 2)
I've developed this section but it's not dynamic. I have to add the product each time in this section manually.

#1129340

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

The page was just an example. I created the view and only set it to list out the product title.

What you need to do is create a view that will display the products how you want it. It was just an example to show that the code to allow the view to display the featured product is working.

Have you already setup a view on how you want the products to display?

Please let me know.

Thanks,
Shane

#1129561

Hi Shane,

This work is already done by me long ago. Featured products are showing up but only title not pictures.

Thank you

#1130030

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

But from my observation below there are no views on this
hidden link

Could you let me know where you have setup this so that I can have a look ? This way I can let you know how to add the images?

Thanks,
Shane

#1130608

Because I constantly update website. I need the solution for this so I have temporary show featured products on my home page.
You have all the scenario and even access to webpage kindly provide the solution for this problem.

Thank you

If you are not able to resolve it kindly transfer me to NIGEl from Europe, so far one of the best supporter in your team.

#1130713

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I've provided the solution multiple times.

To display the featured items with views you need to use the following filter.

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;
}

This code is to be added to your functions.php file after you've created your view to display the products. Once this custom filter has been added then replace the view id in the code with the ID of your created view. This will cause that view to ONLY display your products that are marked as featured.

Is it that you're not sure how to create this view ? Please let me know so that I can provide assistance with this as well.

I'm was under the impression that you've already created this view but just wanted to filter for the featured items.

Looking forward to hearing from you soon.

Thanks,
Shane

#1131822

My issue is resolved now. Thank you!