Rewrite product and shop base the same

By default, Woocommerce uses a different base permalink structure for product and shop. But suppose you want to be able to use the following URLs

Shop: /products

Shop category: /products/product-category/

Product: /products/product-category/product-name

…then add the following permalinks programmatically to your functions.php

add_filter( 'rewrite_rules_array', function( $rules ) {
    $new_rules = [
        'products/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
        'products/([^/]*?)/([^/]*?)?$' => 'index.php?product_cat=$matches[1]&product=$matches[2]',
        'products/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
    return $new_rules + $rules;
Robbert Vermeulen

Need help from a WordPress expert?

I would love to hear about your project and how I can help you achieve your goals