Woocommerce - Get SKU in product single page
Asked Answered
W

1

29

I want go get the SKU in my product single pages in Woocommerce. I tried <?php get_sku(); ?> which is a featured function according to the Woocommerce docs (http://docs.woothemes.com/wc-apidocs/class-WC_Product.html) but it will just break the loop. What to do?

Watchmaker answered 30/9, 2013 at 7:35 Comment(0)
I
69

get_sku() is a method of the WC_Product class, so you need to have a product on which to call it, like this:

<?php echo $product->get_sku(); ?>

This should work if you are inside the WooCommerce product loop, and is what is used in the WooCommerce template files. If you don't already have a reference to the product object, you may need to add the following line at the top of the file in order to access it:

global $product;
Initial answered 30/9, 2013 at 10:9 Comment(1)
Thanks, that did the job! I had tried the first of these without result but when I add the global $product; line it works just fine!Watchmaker

© 2022 - 2024 — McMap. All rights reserved.