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

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 4 replies, has 2 voices, and was last updated by  alisonC 2 months ago. The support staff assigned to this topic is Shane.

Viewing 5 posts - 1 through 5 (of 5 total)
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://wp-types.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
Forum moderator

Supporter languages: English (English )

Supporter 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
Forum moderator

Supporter languages: English (English )

Supporter 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!

Viewing 5 posts - 1 through 5 (of 5 total)