Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Add SKU to Product URLs in WooCommerce?

In this WooCommerce customization, we will provide a simple solution that allows store owners and users to easily identify the product SKU directly from the URL. This way, store owners can improving tracking or identification of products quickly using it’s SKU found in the URL.

Solution: Add SKU to Product URLs in WooCommerce

This code appends the SKU (Stock Keeping Unit) of a WooCommerce product to its URL using the # symbol.

function ts_append_sku_string( $post_link, $post ) {
    if ( 'product' === $post->post_type ) {
        $sku = get_post_meta( $post->ID, '_sku', true );
        if ( $sku ) {
            $post_link .= '#' . $sku;
        }
    }
    return $post_link;
}
add_filter( 'post_type_link', 'ts_append_sku_string', 10, 2 );

Output

When the customer visits a product page, they will see the usual product URL with the SKU appended to the end of the URL.

How to Add SKU to Product URLs in WooCommerce? - Tyche Softwares

Similarly, you can add these Product SKU to your WooCommerce order numbers which makes it super easy to spot which products were sold and update your stock levels quickly.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.