If I make a View listing WooCommerce products, the view filter settings include the ability to filter using Woo's built-in product visibility settings.
The same filter is not available when using a WordPress Archive to list Products. How can I achieve the same filtering result in the WordPress Archive?
Thanks, Simon

Minesh
Colaborador
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Can you please confirm - are you using Toolset Block view or legacy version?
In addition to that - can you please tell me what where you added your archive and where you created the view that shows product visibility and with what product visibility you want to filter the view.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.
Hi. I'm talking about a legacy WordPress Archive, not a Block.
I want to _exclude_ Products where the visibility status is set to Hidden.

Minesh
Colaborador
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
To exclude hidden products from the product archive:
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_action( 'pre_get_posts', 'func_exclude_hidden_products_product_visibility', 999 );
function func_exclude_hidden_products_product_visibility( $query ) {
if ( $query->is_main_query() && ! is_admin() && is_post_type_archive('product') ) {
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => array( 'exclude-from-catalog', 'exclude-from-search','hidden'),
'operator' => 'NOT IN',
);
$query->set('tax_query', $tax_query);
}
}
That doesn't seem to work, I'm afraid, either added to Toolset Custom Code or directly to the theme's functions.php.

Minesh
Colaborador
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
Can you please share problem URL and admin access details and also tell me few products that you set as hidden products.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

Minesh
Colaborador
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
Can you please check now: enlace oculto
The issue was you are on taxonomy archive product_cat so I've adjusted the code added to functions.php file as given under:
add_action( 'pre_get_posts', 'func_exclude_hidden_products_product_visibility', 999 );
function func_exclude_hidden_products_product_visibility( $query ) {
if ( $query->is_main_query() && ! is_admin() && $query->is_tax( 'product_cat' ) ) {
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => array( 'exclude-from-catalog', 'exclude-from-search'),
'operator' => 'NOT IN',
);
$query->set('tax_query', $tax_query);
}
return $query;
}
Can you please confirm - it works as expected now.
Great, that's done the job, thank you!