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