How to Output the WooCommerce SKU via Function or Shortcode

We use WooCommerce for many of the simple e-commerce websites we build. It’s a simple yet powerful WordPress plugin, and a pleasure to develop with.

Here’s a handy tip for anyone wanting to create a function and shortcode to display a product’s SKU code.

Simply copy and paste the following code into your functions.php file:

function display_woo_sku() {

	global $product;
	return $product->get_sku();

}
add_shortcode( 'woo_sku', 'display_woo_sku' );

Usage

This function can either be used in a template file or within an actual product/post.

To use it within a template:

echo display_woo_sku();

To use it within a post, just use the shortcode: [woo_sku]

Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358