Hide specific - by Alvaro Cercos - on WordPress WooCommerce support

This topic has 7 replies, 3 voices, and was last updated 5 years, 7 months ago ago by Rose Tyler

  • Avatar: Alvaro_Cercos
    Alvaro Cercos
    Participant
    May 6, 2020 at 15:37

    Thanks in advance for the help.

    I have been looking how to disable products of a specific category but haven´t yet get how. There is the option to hide visibility of the product in the single product editor but then I can’t use a ADD TO CART button (it simply doesn’t show). With the same task I will like to be able to hide also the category from shop filters and disable from entering the products from the cart or by link but yet be able to use a add to cart button.

    Many thanks in advance.

    Site: http://www.mamasmateas.atac.cl

    One of the products of the category “Plan”: https://mamasmateas.atac.cl/product/plan-personalizado-sin-seguimiento/

    Please, contact administrator
    for this information.
    6 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    May 6, 2020 at 15:55

    Hello,

    There is no such possibility, by default.
    Maybe the support of Woocommerce will be able to give you some advice.

    Regards

    Avatar: Alvaro_Cercos
    Alvaro Cercos
    Participant
    May 6, 2020 at 17:41

    ok, thanks.

    I have tried to find answers in other pages but haven´t found it yet.

    let you know what comes up

    Avatar: Olga Barlow
    Olga Barlow
    Participant
    May 6, 2020 at 20:02

    Hello,

    Ok, sure.

    Regards

    Avatar: Alvaro_Cercos
    Alvaro Cercos
    Participant
    May 7, 2020 at 16:14

    Hi Olga,

    I have been asking in https://stackoverflow.com/questions/61643598/hide-from-all-site-and-single-page-product-of-a-whole-specific-category-in-wooco about the hiding code of a specific category and they have send me the following one:

    // Hide products that belongs to a specific category from catalog (archive pages…)
    add_filter( 'woocommerce_product_is_visible', 'remove_products_from_a_category_on_catalog', 100, 2 );
    function remove_products_from_a_category_on_catalog( $is_visible, $product_id ){
        // HERE define your product category IDs, slugs or names
        $terms = array(43);
    
        if( ! is_admin() && has_term( $terms, 'product_cat', $product_id ) ) {
           $is_visible = false; 
        }
    
        return $is_visible;
    }
    
    // Hide products that belongs to a specific category from single product pages
    add_action( 'template_redirect', 'hide_single_products_from_a_category' );
    function hide_single_products_from_a_category() {
        if( is_product() && has_term( array( 43 ), 'product_cat', get_the_id() ) ) {
            // Shop redirection
            wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
            exit;
        }
    }
    
    // Hide products that belongs to a specific category from search
    add_action( 'pre_get_posts', 'hide_products_from_search_for_a_category' );
    function hide_products_from_search_for_a_category( $query ) {
        if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) 
        {
            $query->set( 'tax_query', array( array(
                'taxonomy' => 'product_cat',
                'field'    => 'term_id',
                'terms'    => array( 43 ),
                'operator' => 'NOT_IN'
            ) ) );
        }
    }

    I have check that the ID I want to hide is 43, done this also with my slug name but it doesn’t work. Could you check in your end why it doesn’t work? I have paste de code in function.php of xstrore child theme in the WordPress editor, after

    <?php
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    	etheme_child_styles();
    }
    

    Could love to get some help from you. From Stackoverflow they have tested the same code and no problem from their end.

    Many thanks in advance

    Please contact administrator
    for this information.
    Avatar: Alvaro_Cercos
    Alvaro Cercos
    Participant
    May 7, 2020 at 23:12

    Hi again,
    I did try the code in other woocommerce that I had access and it did work identifying correctly the ID or the name of the Slug of the category.

    Then i realice that there was a plugin active that was making problem with the code.
    Now is working, but the ¨add to cart¨ button from wp bakery for woocommerce have disapper in the page https://www.mamasmateas.com/servicios/

    Could I enable only a add to cart button for this hidden category.

    Many thanks

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    May 8, 2020 at 09:19

    Hello,

    We are able to help you with only existing options. If you need additional customization then submit a request here to get a quote. Our basic support does not include customization service https://themeforest.net/page/item_support_policy

    Regards

  • Viewing 7 results - 1 through 7 (of 7 total)

The issue related to '‘Hide specific’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.