Skip Navigation

[Resolved] WooCommerce "Featured" field is not available in Views list of custom fields.

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

Last updated by alisonC 6 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#569687

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.

#569763

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

#569782

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.

#569796

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

#569976

Ah, that makes sense. Thanks for the explanation!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.