I'm facing the folloiwng problem:
I would like my products and product categories to have the same url base. E.g. www.example.com/products/product-category
www.example.com/products/sample-product
Trying to do this through the Permalinks section causes a 404 for all products. I know I can use a different name as a category base, e.g. 'foo' (www.example.com/foo/product-category), and then use the following code to re-write it to 'products':
add_filter('product_cat_rewrite_rules','update_base_category_rewrite_rule');
function update_base_category_rewrite_rule($category_rewrite){
$new_category_rewrite = $category_rewrite;
foreach($category_rewrite as $key => $value){
$xyz = str_replace('foo', 'products', $key);
$new_category_rewrite[$xyz] = $value;
}
return $new_category_rewrite;
}
The problem with the above is that -as expected- all category links on the website are still in the form of
www.example.com/foo/product-category
Any help with this would be highly appreciated.