Search code examples
wordpressurl-rewritingtaxonomy

Include Product category base and %product_cat% in rewrite taxonomy


I would like to have the Product category base and %product_cat% in the new taxonomys i added to woocomerce, any ideas ?

    $flavour_labels = array(
    'name'                       => 'Flavours',
    'singular_name'              => 'Flavour',
    'menu_name'                  => 'Flavour',
    'all_items'                  => 'All Flavours',
    'parent_item'                => 'Parent Flavour',
    'parent_item_colon'          => 'Parent Flavour:',
    'new_item_name'              => 'New Flavour Name',
    'add_new_item'               => 'Add New Flavour',
    'edit_item'                  => 'Edit Flavour',
    'update_item'                => 'Update Flavour',
    'separate_items_with_commas' => 'Separate Flavour with commas',
    'search_items'               => 'Search Flavours',
    'add_or_remove_items'        => 'Add or remove Flavours',
    'choose_from_most_used'      => 'Choose from the most used Flavours',
);

$flavour_args = array(
    'labels'             => $flavour_labels,
    'hierarchical'       => true,
    'public'             => true,
    'show_ui'            => true,
    'show_admin_column'  => true,
    'show_in_nav_menus'  => true,
    'show_tagcloud'      => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'flavour'),
);

register_taxonomy( 'product_flavour', 'product', $flavour_args );
register_taxonomy_for_object_type( 'product_flavour', 'product' );

This is the url i have http://site.local/flavour/name/

And this is what i want http://site.local/gear/product_cat/flavour/name/

I dont wanna hard code anything in the rewrite


Solution

    1. Make sure your .htaccess file is writable.
    2. In the "category base" write your base string "product_cat" with no percentage signs (%)

    enter image description here