Skip Navigation

[Resolved] Featured Product

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

Problem:

Display woocommerce featured product using views.

Solution:

In order to do this you will need to use the following hook


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

Add the above to your functions.php file and then change the 10 to the id of your view. Once you have done this then you should be able to display your featured product.

This support ticket is created 6 years, 2 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 27 replies, has 2 voices.

Last updated by CharlesB2907 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1136096

EXCELLENT!!!

Exactly what I need, assuming that only one star can be selected at a time, that is a perfect solution and I like it much better than posting a new featured project from the front'ed form.

Please share the process so I can keep it in my work notes.

THANK YOU!

#1136106

Shane
Supporter

Languages: English (English )

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

Hi Charles,

Awesome.

I was checking to see if it was possible with woocommerce to have only 1 star checked at a time, however it doesn't seem possible to do.

You can however limit view to displaying only 1 featured product at a time.

Please let me know if this would help.

Thanks,
Shane

#1136109

I would be able to manage it but the client who does not view the admin area critically might have some difficulty keeping track of what is checked and what isn't.

For the sake of time, been at this nearly 9 months now, I think it would be a great starting point. In time, perhaps a more efficient and error-proof solution might develop.

Yes.

#1136152

Shane,

Is this something that is ready to use now?

#1136223

Shane
Supporter

Languages: English (English )

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

Hi Charles,

Yes this is now working.

The final thing I did was to just add this filter so that the view will filter only the 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;
}

Thanks,
Shane

#1136253
Screenshot_10-29-2.jpg

Hi Shane,

I've tested this several times and the only problem there is which does not have to be resolved now, is when we want to check a new product to feature that is one page of products and have to go back to find the original checked product to uncheck it.

There are currently 18 pages of products and I have another 40 pages yet to add (roughly 700+ products). Finding the previously checked product to uncheck it will soon be difficult to locate for the client to manage.

Unless you have a final suggestion, this is great for now.

Also, do I need the field group panel on the home pages? see screenshot

#1136261

Is there a command available that would allow us to search "featured" in the Search Products field?

#1136286

Shane
Supporter

Languages: English (English )

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

Hi Charles,

I did a little searching for you on this and it seems that this was removed from woocommerce when they moved from using a custom field for featured items to a taxonomy.

hidden link

Now It seems that this plugin below should be able to help you with the sorting of the columns
https://wordpress.org/plugins/codepress-admin-columns/

Please let me know if this helps.

Thanks,
Shane

#1136300

Thank you for the referral. It doesn't fix the problem entirely, but it's an interesting plugin and it does help to organize the UI.

#1136830

Shane
Supporter

Languages: English (English )

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

Hi Charles,

Happy to assist so far.

Is there any other queries on this that you'll like me to clear up ?

Thanks,
Shane

#1136846

Thank you for asking Shane,

As far as this specific ticket issue is, I think you've provided excellent support and the matter appears to be resolved. Although, I wanted to keep this open for a few more days while I complete the site.

I wanted to circle back to make sure I record exactly how everything was accomplished so I can duplicate it or something similar in another project.

#1136912

Shane
Supporter

Languages: English (English )

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

Hi Charles,

No problem. If you get the notification about this ticket is being closed for inactivity just send a message to keep it open.

Thanks,
Shane

#1190403

Hi Shane - I have a question regarding this thread subject that you helped me with, specifically reply dated October 29, 2018 at 8:12 pm #1136223

Can you please let me know if you can receive this message?

Thank you.