Skip Navigation

[Resolved] How to filter woo products that are hidden

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

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 17 replies, has 3 voices.

Last updated by Minesh 3 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2445399

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Following products are removed with the following product IDs:

Array
(
    [0] => 25659
    [1] => 21748
    [2] => 19799
    [3] => 19778
    [4] => 16998
    [5] => 16996
    [6] => 16994
    [7] => 16992
    [8] => 16990
    [9] => 16988
)

When I checked all those products are set as hidden products. Can you please verify and let me know if its not working as expected.

#2447747

Hi Minesh, the code seems to be working sometimes and not other times.

How can I see the array like you showed in the previous message. This will help me troubleshoot further.

#2448335

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

within the code I shared:

add_filter( 'wpv_filter_query', 'func_filter_hidden_products',10,3 );
function func_filter_hidden_products( $query_args,$views_settings, $view_id) {
         
if ($view_id == 14162) {
   
  $args = array(
  'visibility' => 'hidden',
   'return' => 'ids',
);
$products = wc_get_products( $args );
  
echo "<pre>";
print_r($products);
exit;
 
if(!empty($products)){  
    $query_args['post__not_in'] = $products;
} 
 
 
   
}
    return $query_args;
}

I've added the following debug code as you can see with the above code:

echo "<pre>";
print_r($products);
exit;
 

It will return you the product IDs, you can debug with this and check once you done with debug you should remove the above debug code.