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.
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.