[Resolved] Disable selected woocommerce product categories from showing on shop page

Home Forums Support Disable selected woocommerce product categories from showing on shop page

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1344297
    Nicola

    Hi, I’d like to be able to temporarily disable one or two categories from showing on my woocommerce shop page whilst the products are out of stock. There are plugins available that allow me to do this but I would much rather use code, are you able to help please? And is using code or a plugin better than just deleting the category and creating again once I have more stock? I’d be grateful for any help and advice. Thank you, Nicola

    #1344548
    David
    Staff
    Customer Support
    #1344679
    Nicola

    Hi, thanks for your reply but unfortunately woocommerce have made a mistake here. Their page title is “exclude a category from the product page” however the info given is headed “Exclude products from a particular category on the shop page” which is what it does, and it works, but the category is still showing on the product page. Can this code be amended so the category itself doesn’t show? Or is it easier to just delete it? thanks, Nicola

    #1344690
    Nicola

    Update: Ok managed to find the following code which works for me:

    add_filter( ‘get_terms’, ‘exclude_category’, 10, 3 );
    function exclude_category( $terms, $taxonomies, $args ) {
    $new_terms = array();
    if ( is_shop() ){
    foreach ( $terms as $key => $term ) {
    if( is_object ( $term ) ) {
    if ( ‘books’ == $term->slug && $term->taxonomy = ‘product_cat’ ) {
    unset($terms[$key]);
    }
    }
    }
    }
    return $terms;
    }

    #1344736
    David
    Staff
    Customer Support

    Glad to hear you found the answer – and thanks for sharing

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.