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.
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
Hi I tried that and it didn't work. Can I provide login details for you to check?
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.
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
Can I get an update on this, please?
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
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.
I tried adding that code and am now getting this error:
hidden link
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.
I'm still getting the same error.
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.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
You missed the php opening tag within the code snippet.
I've added it as first line to your code snippet.
It should be ok now.
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