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
#1125234
Screen Shot 2018-10-11 at 3.18.00 PM.png

I am trying to: create view loop for featured items in toolset. I have marked a couple of woocommerce products as featured, and went to toolset > settings > front-end content > select custom fields (From hidden custom fields) and the "_featured" field is not showing

Thank you

#1125271

Second thing is TOOLSET provide template for single product. Is there anyway I can customize product category page? (Which shows products when click to any category)
If yes please mention the steps.

#1125410

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for contacting our support forum.

Unfortunately we only handle 1 issue per thread so you will need to open a new ticket for your second issue.

For the featured products issue you can try the solution that i've previously provided in the link below.
https://toolset.com/forums/topic/woocommerce-is-featured-product-as-conditional-output/

Thanks,
Shane

#1125418

Thank you for the solution, but I do not wanted to check if a product is featured or not. My products are showing featured I just need to show featured product in FIELD and VIEW so that I can show featured products on any page.

#1125440

Shane
Supporter

Languages: English (English )

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

Hello,

You have defined these products as featured in woocommerce correct?

Perhaps i'm not understanding correctly. However since woocommerce have changed how featured products are defined, we needed to use a custom shortcode to know if a product is featured or not.

This solution is just to check if a product is featured. This way you can use our conditional code to display only those that are featured.

This is what the customer did in this ticket below.
https://toolset.com/forums/topic/woocommerce-is-featured-product-as-conditional-output/#post-636123

When you say " FIELD and VIEW " what exactly are your referring to ?

Please let me know.
Thanks,
Shane

#1125456
5.png
4.png
3.png
2.png
1.png

Hi,

Let me clear out.
1. I want to show featured products on a page designed in DIVI.
2. I seen that featured products tab is not in the Fields and Views shortcodes (see image 1). When I search for this issue this is the solution I've found https://toolset.com/forums/topic/toolset-views-not-showing-_featured-in-view-gui-for-woocommerce/.
3. But when I went to toolset > settings > front-end content > select custom fields (From hidden custom fields), I've noticed the "_featured" field is not showing up.(see image 2)
4. You are mentioning the ticket for the solution if I'm able to tell if a product is feature or not.
5. I've checked the product is featured and shown up in featured but by DIVI shop module. (see image 4)
6. It must be by shown by shortcodes or anything similar to it because I only have access to this see image 5.
7. I just want to show the product on my page that are ticked as Featured by using TOOLSET.(see image 3)

Thank you

#1125486
3.png
2.png
1.png

Furthermore, I have added code in the function.php that you have shared. (Image 1)
and then call for the featured Products (image 2)
but still not fetching the Featured products (image 3)

#1125542

Shane
Supporter

Languages: English (English )

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

Hello,

I think this solution here is better for you case.

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

If you already have a view that is listing products then you need to replace the 10 in this code to the ID of your view. This will cause the view to only list the products that are marked as featured.

Have you created a view to list out the products?

Thanks,
Shane

#1125875
Screen Shot 2018-10-12 at 10.56.57 AM.png

I added a VIEW and get the ID and paste that code with updated ID in function.PHP.
Then I call that VIEW from FILED & VIEWS tab still nothing.

#1126430

Shane
Supporter

Languages: English (English )

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

Hello,

Would you mind allowing me to have admin access to the site so that I can check on this for you ?

The private fields have been enabled for your next response.

Thanks,
Shane

#1126547

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for the credentials.

Could you send me a link to the page where you want the featured Items to show up or where you have been testing this ?

Thanks,
Shane

#1126831

hidden link

on home page

#1127380

I'm still waiting for you reply?

#1127577

Hi, Shane is on public holiday and will return tomorrow to continue assisting you. Thanks for your patience.

#1127588

Can you give me solution to this problem?