YordanSoares

[WooCommerce] Quitar categorías de producto de los resultados

Jun 29th, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function remove_wc_cats($terms, $taxonomies, $args) {
  2.  
  3.   $new_terms = array();
  4.  
  5.   // Si es una categoría de producto, la tienda o la página de inicio.
  6.   if (in_array('product_cat', $taxonomies) && !is_admin() && is_shop() || is_front_page()) {
  7.  
  8.     foreach ($terms as $key => $term) {
  9.  
  10.       if (!in_array($term->slug, array('categoria-1', 'categoria-2'))) {  // Slugs de las categorias a quitar
  11.         $new_terms[] = $term;
  12.       }
  13.     }
  14.     $terms = $new_terms;
  15.   }
  16.  
  17.   return $terms;
  18. }
  19. add_filter('get_terms', 'remove_wc_cats', 10, 3);
Add Comment
Please, Sign In to add comment