New Landing How can we help? Themeforest Theme Support Dante Snippet to hide a specific category from everywhere in the shop

Viewing 4 posts - 1 through 4 (of 4 total)
  • Posted in: Dante
  • #140571
    alemarengo
    Member
    Post count: 695

    Hi guys.
    I’d like you to suggest me a snippet to hide a specific category from the shop.

    I tried these unsuccessfully:

    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
      if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
    
        foreach ( $terms as $key => $term ) {
    
          if ( ! in_array( $term->slug, array( 'cat-to-remove' ) ) ) {
            $new_terms[] = $term;
          }
    
        }
    
        $terms = $new_terms;
      }
    
      return $terms;
    }
    add_filter( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    function custom_pre_get_posts_query( $q ) {
    
        if ( ! $q->is_main_query() ) return;
        if ( ! $q->is_post_type_archive() ) return;
    
        $q->set( 'tax_query', array(array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'cat-to-remove' ),
            'operator' => 'NOT IN'
        )));
    
        remove_filter( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    and

    function exclude_categories($args){
        $exclude = "123";
        $args["exclude"] = $exclude;
        return $args;
    }
    
    add_filter("woocommerce_product_subcategories_args","exclude_categories");
    

    My need is to have a nth category that shouldn’t appear anywhere – shop and product pages – in the shop but that works effectively: I have to apply a specific coupon discount.
    Have you ever had to manage this?

    I hope so, that’s why I asked for your help.

    #140666
    laranz – SUPPORT
    Member
    Post count: 3186

    Hi,

    Did you try this official snippet? http://docs.woothemes.com/document/exclude-a-category-from-the-shop-page/

    Let us know,

    Thanks,
    laranz.

    #140667
    alemarengo
    Member
    Post count: 695

    Yes, of course… 🙁 no way though

    Anyway, just to let you know: the purpose to check if two or more categories are in the cart at the same time is NOT possible. I thought to manage it through a nth category, but it’s treated like any other else. That was what my request was for.

    #140684
    laranz – SUPPORT
    Member
    Post count: 3186

    Hi,

    While using this query? http://docs.woothemes.com/document/exclude-a-category-from-the-shop-page/ Did you try logout and check? Because that query checks the is_admin()

    Can you explain the situation briefly? Although, this is not a support question, I try to answer you, but if I can’t I suggest you to find someone to do so other than support.

    Let us know,

    Thanks,
    laranz.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register