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' );
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]