January 13, 2019 at 11:08 am
Hi Ben,
i filter the shop page to hide a whole category because it’s displayed separatelly on the site:
// Hide Category from Shop page
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on the shop page
// to hide from shop page, replace is_page('YOUR_PAGE_SLUG') with is_shop()
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'praktische-kurse, practical-courses' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
/** * Exclude products from a particular category on the shop page
*/
function custom_pre_get_posts_query( $q ) {
if ( ! is_admin() && is_shop()){
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'praktische-kurse, practical-courses' ), // Don't display products in this category on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Works perfect in first language.
After installing WPML and translating Taxonomies i added the english slug of the same category to the code, but with no effect.
Can you please tell me what i’m missing?
Thank you