I'm using WooCommerce on a WordPress. I would like my products and product categories to have the same url base. E.g.
www.example/shop/product-category
www.example/shop/sample-product
Using this code here:
add_filter( 'rewrite_rules_array', function( $rules )
{
$new_rules = array(
'shop/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
'shop/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
);
return $new_rules + $rules;
} );
I changed the permalinks in Settings > permalink:
Custom Structure: /shop/%postname%/
Product category base: shop
Custom base: shop
then when visit each of the following pages, I get the following result:
Custom Structure: works
Product category base: works
Custom base: 404 error
Anybody have any insight on how to get the single product pages to not throw the 404 error?
Thanks!
I'm using WooCommerce on a WordPress. I would like my products and product categories to have the same url base. E.g.
www.example.com/shop/product-category
www.example.com/shop/sample-product
Using this code here:
add_filter( 'rewrite_rules_array', function( $rules )
{
$new_rules = array(
'shop/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
'shop/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
);
return $new_rules + $rules;
} );
I changed the permalinks in Settings > permalink:
Custom Structure: /shop/%postname%/
Product category base: shop
Custom base: shop
then when visit each of the following pages, I get the following result:
Custom Structure: works
Product category base: works
Custom base: 404 error
Anybody have any insight on how to get the single product pages to not throw the 404 error?
Thanks!
Lots of people dealing with the same issue and I haven't found a solution yet either. It's like the whole thing is broken and most people just don't care?
It worked for me by also adding this:
add_action( 'init', function() {
flush_rewrite_rules();
} );