Skip Navigation

[Resolved] How to filter woo products that are hidden

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 1 year, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2430591

I'm trying to follow the instructions in this thread (https://toolset.com/forums/topic/exclude-products-from-view-if-woocommerce-catalog-visibility-is-set-to-hidden/).

I don't see the option for "Product visibility" in the dropdown. How can I enable that option in the Query Filter?

Thanks in advance.

#2430989

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

To filter the products using view and exclude the hidden products:

What if you try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

add_filter( 'wpv_filter_query', 'func_filter_hidden_products',99,3 );
function func_filter_hidden_products( $query_args,$views_settings, $view_id) {
       
if ($view_id == 99999) {

$query_args['tax_query'] = array(
    array(
      'taxonomy'     => 'product_visibility',
      'field'   => 'name',
      'terms' => 'hidden',
      'operator' => 'IN'
    ),
  );
}
    return $query_args;
}

Where:
- replace the 99999 with your original view ID

#2431367

Hi I tried that and it didn't work. Can I provide login details for you to check?

#2431693

Minesh
Supporter

Languages: English (English )

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

Sure, can you please share admin access details as well as problem URL and what products should not be displayed.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2441041

Shane
Supporter

Languages: English (English )

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

Hi Amin,

Minesh is on vacation so I will be having a look at this for you ?

I tried to access the site however it would appear that you have Two Factor authentication enabled. Unfortunately because of this i'm unable to log in.

Can you disable the 2FA and let me know.

Thanks,
Shane

#2441067

I have disabled 2FA

#2443537

Can I get an update on this, please?

#2443663

Shane
Supporter

Languages: English (English )

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

Hi Amin,

I'm still looking into this one for you. Currently i'm not able to get the custom code to work as the option for the hidden products isn't responding as expected.

But will provide an update as soon as possible.

Thanks,
Shane

#2443905

Minesh
Supporter

Languages: English (English )

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

I've adjusted the code to "Custom Code" section with code snippet "hide-hidden-woo-products" as given under:

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

if(!empty($products)){  
	$query_args['post__not_in'] = $products;
} 
  
}
    return $query_args;
}

Can you please confirm it works as expected.

#2444201

I tried adding that code and am now getting this error:

hidden link

#2444329

Minesh
Supporter

Languages: English (English )

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

Please use the following code:

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

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

if(!empty($products)){  
	$query_args['post__not_in'] = $products;
} 


  
}
    return $query_args;
}

You should add the line of the code after the following line:

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

Also make sure you activate the code snippet.

#2444347

I'm still getting the same error.

#2444349

Minesh
Supporter

Languages: English (English )

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

Can you please share admin access details and tell me where exactly you added the code.

I have set the next reply to private which means only you and I have access to it.

#2444399

Minesh
Supporter

Languages: English (English )

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

You missed the php opening tag within the code snippet.

<?php

I've added it as first line to your code snippet.

It should be ok now.

#2445019

Hi. Can you confirm if the code is checking the default WP visibility?

If so, can you change it to be checking the Woocommerce Catalog Visibility, please?

Here's a screenshot: hidden link

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