Hide Child Categories

This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 years, 11 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #18502
    diegomoreno
    diegomoreno
    Participant

    Hello

    We want to see only the parent categories at the beginning, but when the parent category is selected then the child categories are visible. That’s possible?

    We would also like to add a specific style for each child category, in order to change the color of the selection box to the color to which the category refers.

    I am looking forward to your response.

    #18509
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Well, this might be possible with a custom script code. I have constructed a small custom code snippet, and placed it into the functions.php file in your child theme directory. This should hide the child checkboxes until they are checked. For reference, here is the custom code:

    Please note that I cannot guarantee this is going to work with every single case, but it should do the trick in most of them.

    Coloring the checkbox background could be possible via custom CSS. For example this will color the background of the category id = 1 to red:

    label[for$=termset_1] {
        background-color: red !important;
        background-image: none !important;
    }

    You can use this as a template to create as many different colorings as you need.

    I hope this helps!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #18512
    diegomoreno
    diegomoreno
    Participant

    Hi, thanks for your quick response.

    I will make other configurations regarding this and in case of needing any help I will let you know. Good work in your support.

    #18573
    diegomoreno
    diegomoreno
    Participant

    Greetings. I hope you are well.

    I need a little more of your help.

    I have the filter configuration options ready as it should behave.

    But I would like that when a parent category is selected, the children are not automatically selected, I would like to add a link only to select all the child categories.

    I would also like that when a child category is selected, the parent category is selected.

    (Example in the attached GIF)

    Attachments:
    You must be logged in to view attached files.
    #18588
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Well, to prevent the auto checking, and to check the parents, try this:

    Please note, that these qualify as customization requests, so I cannot guarantee any working solution.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #18589
    diegomoreno
    diegomoreno
    Participant

    I placed the code in the functions.php but the behavior remains the same. What can I be doing wrong?

    #18590
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Sorry about that, there was a mistake in the code. It should be ok now.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #18591
    diegomoreno
    diegomoreno
    Participant

    Oh, sir, excuse me. But it still does not work.

    Remember the code we implemented earlier, which was to display the child categories when checking parents. Is interfering this?

    Can you see again the .gif that I shared?

    The point is that I want to be able to select the category “Azul” and “Por Color” and that the filter ignores those that are not selected.

    If only the “Azul” category is selected and not its parent category, no results appear!. That’s the problem.

    #18601
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Indeed, it was working on my console, but not as a separate script. I have made a few modifications to it, and placed it to the functions.php file in your theme child directory.

    Please note, that this is probably not a full solution, but it should work in most cases.

    For future reference, this is the modified code:

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


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

You must be logged in to reply to this topic.