How to use SKU in WooCommerce permalinks?

In this short article I will describe two possible ways how to add SKU number to WooCommerce product permalinks. The first one is available to all Permalink Manager Pro users (it is not included in free version of plugin) and the second one can be added to your website with a provided snippet.

How to easily include SKU in WooCommerce permalinks?

This should be quite easy – all you need to is to go to “Tools -> Permalink Manager -> Permastructures” section and use “%__sku%” tag inside permastructure settings for Product.

Sample WooCommerce product permastructure settings with SKU tag:

%product%-%__sku%
%product%/%__sku%
products/%product%-%__sku%
%product_cat%/%product%-%__sku% 
%product_cat%/%__sku%
%__sku%

You can insert SKU anywhere you want, but if you would like to use it instead of product slug you will also need to disable appending the slug to the end of permalink with additional code snippet.

After the new settings are saved, you will also need to regenerate the old product permalinks (here you can find more detailed instructions).

Product permalinks with SKU after they are regenerated.

The new permastructures will be automatically applied to new products.

WooCommerce SKU shortlinks

In some specific cases it may be very useful to allow the visitors to access your product pages using shortlinks based on SKU number.

Unfortunately, it is not possible with Permalink Manager at this moment but this feature can be added with a simple code snippet. Although, you do not need to install Permalink Manager if you need to utilize only this feature.

In short, after the following snippet is added to your child theme functions.php file, visitors trying to access http://example.com/SKU-NUMBER will be automatically redirected to the actual product permalink.

For example:
http://example.com/9780451452733/ will redirect to: http://example.com/product/2001-a-space-odyssey-25th-anniversary-edition.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Wait!!! Before you go...

Still not convinced? Use following discount code during Gumroad checkout and get 10% off!

BLOG

If you have any questions or need further information, please feel free to contact me via email: