Filter Products By Gender - by rj - on WordPress WooCommerce support

This topic has 3 replies, 2 voices, and was last updated 5 years, 2 months ago ago by Olga Barlow

  • Avatar: FastFormations
    rj
    Participant
    September 23, 2020 at 10:41

    Hi

    I have seen there are MEN and WOMEN categories in default theme. Is there a way to add a filter on sidebar to choose gender?

    For gender, I want a separate column like “brands” and “product category” on add product page https://prnt.sc/umcue7

    How can I achieve this?
    Do you recommend adding an attribute or taxonomy?

    2 Answers
    Avatar: FastFormations
    rj
    Participant
    September 23, 2020 at 11:15

    I found this somewhere..

    // Register Custom Taxonomy
    function gender_taxonomy() {
    
    	$labels = array(
    		'name'                       => _x( 'Genders', 'Taxonomy General Name', 'text_domain' ),
    		'singular_name'              => _x( 'Gender', 'Taxonomy Singular Name', 'text_domain' ),
    		'menu_name'                  => __( 'Gender', 'text_domain' ),
    		'all_items'                  => __( 'All Genders', 'text_domain' ),
    		'parent_item'                => __( 'Parent Gender', 'text_domain' ),
    		'parent_item_colon'          => __( 'Parent Gender:', 'text_domain' ),
    		'new_item_name'              => __( 'New Gender Name', 'text_domain' ),
    		'add_new_item'               => __( 'Add New Gender', 'text_domain' ),
    		'edit_item'                  => __( 'Edit Gender', 'text_domain' ),
    		'update_item'                => __( 'Update Gender', 'text_domain' ),
    		'view_item'                  => __( 'View Gender', 'text_domain' ),
    		'separate_items_with_commas' => __( 'Separate genders with commas', 'text_domain' ),
    		'add_or_remove_items'        => __( 'Add or remove genders', 'text_domain' ),
    		'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
    		'popular_items'              => __( 'Popular genders', 'text_domain' ),
    		'search_items'               => __( 'Search Genders', 'text_domain' ),
    		'not_found'                  => __( 'Not Found', 'text_domain' ),
    		'no_terms'                   => __( 'No genders', 'text_domain' ),
    		'items_list'                 => __( 'Genders list', 'text_domain' ),
    		'items_list_navigation'      => __( 'Genders list navigation', 'text_domain' ),
    	);
    	$args = array(
    		'labels'                     => $labels,
    		'hierarchical'               => true,
    		'public'                     => true,
    		'show_ui'                    => true,
    		'show_admin_column'          => true,
    		'show_in_nav_menus'          => true,
    		'show_tagcloud'              => true,
    		'show_in_rest'               => true,
    	);
    	register_taxonomy( 'pet-gender', array( 'pet' ), $args );
    
    }
    add_action( 'init', 'gender_taxonomy', 0 );

    Would this be enough to add a new gender taxonomy?

    More importantly, will I be able to add filter in sidebar? Can you help me with that?

    Avatar: Olga Barlow
    Olga Barlow
    Participant
    September 24, 2020 at 13:02

    Hello,

    In your case, I would not recommend adding the new taxonomy but better to create the new attribute – Gender – with terms https://docs.woocommerce.com/document/managing-product-taxonomies/#section-6
    Then add this attribute for your product and DON’T choose “Use for variations”.

    After that you’ll be able to use the Attribute filter widget in the shop sidebar and choose the gender attribute.

    Regards

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

The issue related to '‘Filter Products By Gender’' 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.