• Resolved RGM71

    (@rgm71)


    Hi – I have used the code below to remove the ‘ACB’ product category on https://artchilli.com/gallery/. That works fine, however the ‘ACB’ product category still shows on the product category & tag pages e.g. https://artchilli.com/product-category/paintings/ & https://artchilli.com/product-tag/abstract/. How do I remove it from these pages?

    /**
    * Show products only of selected category.
    */
    function get_subcategory_terms( $terms, $taxonomies, $args ) {

    $new_terms = array();
    $hide_category = array( 131 ); // Ids of the category you don’t want to display on the shop page

    // 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->term_id, $hide_category ) ) {
    $new_terms[] = $term;
    }
    }
    $terms = $new_terms;
    }
    return $terms;
    }
    add_filter( ‘get_terms’, ‘get_subcategory_terms’, 10, 3 );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • if ( in_array( ‘product_cat’, $taxonomies ) && !is_admin() && is_shop() ) {

    try with this:

    if ( in_array( ‘product_cat’, $taxonomies ) && !is_admin() && is_shop() || is_product_category() ) {

    Plugin Support Riaan K.

    (@riaanknoetze)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter RGM71

    (@rgm71)

    Many thanks Ahir – that works perfectly to hide the category on the product-category page. To also make it work on the product-tag pages I’ve added to your code as follows:

    if ( in_array( ‘product_cat’, $taxonomies ) && !is_admin() && is_shop() || is_product_category() || is_product_tag() ) {

    However, I have just noticed that the category has now reappeared on https://artchilli.com/gallery/

    • This reply was modified 5 years, 3 months ago by RGM71.
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Hide Product Category on’ is closed to new replies.