How to change permalink structure for Woocommerce

Like Tweet Pin it Share Share Email

You have just installed Woocommerce plugin. It is time to change the permalink structure.

In this article, you will know how to change default permalink structure. Therefore, you have will SEO friendly permalink structure.

How to set up permalink for Woocommerce

To change the permalink for Woocommerce, head over to Setting -> Permalinks.

Now you see the options which are categorized into three groups:

permalink structure Woocomerce 6

In the common settings, you choose Post name. It is the recommended setting for all WordPress websites.

Two next groups are reserved for Woocommerce.

As you know, by default, the URL of the product category is http://yourdomain.com/product-category/clothing. The ‘category-product’ word always shows up in the URL.

And the URL of the product page is http://yourdomain.com/product/happy-ninja. The ‘product’ word always shows up in the URL.

Now we change the default permalink using two nice URL patterns.

How to delete product and product-category in URL?

To delete the ‘product’ word, you need to add the code below to functions.php. Then go to Settings -> Permalinks and click Save Changes button.

//Remove product form url
function devvn_remove_slug( $post_link, $post ) {
   if ( !in_array( get_post_type($post), array( 'product' ) ) || 'publish' != $post->post_status ) {
       return $post_link;
if('product' == $post->post_type){
    $post_link = str_replace( '/san-pham/', '/', $post_link ); //Thay product bằng slug hiện tại của bạn
    $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
   return $post_link;
add_filter( 'post_type_link', 'devvn_remove_slug', 10, 2 );
function devvn_parse_request( $query ) {
   if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
   if ( ! empty( $query->query['name'] ) ) {
       $query->set( 'post_type', array( 'post', 'product', 'page' ) );
add_action( 'pre_get_posts', 'devvn_parse_request' );

To delete category-product, you install and activate WP Htaccess control plugin.

Once the plugin is activated, go to Settings -> htaccess Control. Click on Remove Taxonomies and Author Base section to view more options.

Now select Remove Categories Base. Remember to click on Save all changes to store your settings.

permalink structure Woocomerce 5

How to set up product category base which is the same as product base

Above, you know how to delete product and product-category from URL.

Now we will set up a new URL pattern for Woocommerce.

Specifically, we will have the following URL pattern:

URL of shop page: http://yourdomain.com/product

URL of product category page: http://yourdomain.com/name-of-product-category

URL of product details page: http://yourdomain.com/product/name-of-product-category/name-of-product

Here’s how to do it:

First, you need to create a page with the following slug: http://yourdomain.com/product

permalink structure Woocomerce 2

Then, go to Woocommerce -> Settings->Products->Display. Choose Product in the drop-down box of Shop page option.

permalink structure Woocomerce 3

Click save changes.

Next, go to Settings->Permalinks. At Optional section, enter product at Product category base option.

Scroll down to Product permalinks section. Enter /product/%product_category%/ at the custom base.

Click Save Changes button.

permalink structure Woocomerce 4

Finally, add the following code to functions.php. Then back to Settings -> Permalinks and click Save changes button to update new permalink structure.

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

That’s it.

You already know to have a nice permalink structure for Woocommerce.

If you have any trouble setting up permalink for Woocommerce, leave your comment below.

Disclosure: Some of the links in this website are “affiliate links.” This means if you click on the link and purchase the item, we will receive an affiliate commission (at no additional cost to you). All opinions are our own and we do not accept payments for positive reviews.

Leave a Reply

2 Comments on "How to change permalink structure for Woocommerce"

Notify of
Sort by:   newest | oldest | most voted
Uwe S
hey Joel, what a nice post I see you had posted on my birthday, hehe. Appreciate your work with this one. Delayed present (-: Followed your instructions, but am still slightly confused. This is what I have achieved with it on the current task at hand: Blog: Blog Page: https://mydomain.com.au/blog/ = working Categories: Clicking on a category link redirects me to Home Page ? Also, the category link when hovering looks like this: https://mydomain.com/business-security = missing the blog base Post: https://mydomain.com/blog/safes/new-vs-second-hand-safes/ Shop: Categories: https://mydomain.com/product-category/commercial-locks/ = still have that “product-category” in there rather than my /shop/ base Products: https://mydomain.com/shop/commercial-locks/abus-oval-570-cylinder/ = looks… Read more »
Scroll Up