• Resolved Lori Boone

    (@pleazo)


    Hello,

    I was hoping someone could help me with a css code.

    I am trying to remove “membership plan” from product the drop down filter when searching for all categories. This subscription plan should not be visible to users/shoppers. Only the shopping categories should show here.

    I was given the following code (however it is not working):
    .woocommerce.widget_product_categories #product_cat [value=”membership-plan”]{
    display: none !important;
    }

    (as you can see here)

    Does anyone know why this code does not work?

    Best,
    Chris

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • MayKato

    (@maykato)

    Hello,

    You can try the following code to exclude a specific category from the category widget dropdown:

    add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'woo_product_cat_widget_args' );
    function woo_product_cat_widget_args( $cat_args ) {
                    $cat_args['exclude'] = array('10'); // Insert the product category IDs you wish to exclude
                    return $cat_args;
    }

    [Code Source]

    I would recommend using a plugin like?Code Snippets?to add the snippet to your site.

    • This reply was modified 3 years ago by MayKato.
    Thread Starter Lori Boone

    (@pleazo)

    Hi @maykato

    I tried the code (product category ID is 162) but still not working and the code shows up red when entered:

    add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'woo_product_cat_widget_args' );
    function woo_product_cat_widget_args( $cat_args ) {
                    $cat_args['exclude'] = array('10'); // 162
                    return $cat_args;
    }

    Any idea what I am doing wrong?

    Best,
    Chris

    Mirko P.

    (@rainfallnixfig)

    Hi @pleazo,

    If your product category ID is 162 you may want to use this snippet:

    add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'woo_product_cat_widget_args' );
    function woo_product_cat_widget_args( $cat_args ) {
                    $cat_args['exclude'] = array('162'); // Insert the product category IDs you wish to exclude
                    return $cat_args;
    }

    To avoid creating problems for anyone who is trying to help here, please add NSFW to the topic title of the post. As per the forum guidelines, this can be used when the content on the site is not suitable for a general audience or for viewing while at work.

    If you’re not able to update it you can get assistance from a moderator using the options on the right to report the topic.

    Cheers.

    Thread Starter Lori Boone

    (@pleazo)

    Hi @rainfallnixfig

    Thanks for your response. Unfortunately, this code is not working.
    Some of the code is red (as seen here). This means there’s a problem with the code?

    I will set NSFW next time.

    Best.
    Chris

    Abiola Ogodo

    (@oaoyadeyi)

    @pleazo

    Kindly confirm if you’re adding the code using CSS customization or the code snippets plugin recommended above. Kindly note the latter is required in this case.

    Thread Starter Lori Boone

    (@pleazo)

    Hi @oaoyadeyi
    I am using the CSS customization.

    Best,
    Chris

    Mirko P.

    (@rainfallnixfig)

    Hi Chris @pleazo

    This is actually a PHP snippet so we recommend using a plugin like Code Snippets to add custom PHP code into your site without directly accessing the functions.php file.

    Here is a link on how to use the Code Snippets plugin:

    https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/

    Hope this helps!

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We haven’t heard from you in a while, so I’m going to mark this as resolved. Feel free to start a new thread if you have any more questions.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘CSS code to hide category is not working’ is closed to new replies.