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?
Once you click on the edit option, you find all the available settings for that individual product. Scroll down and click on the inventory and there will be the option to set a WooCommerce product SKU.
In the WordPress admin, go to WooCommerce > Settings > Products > Product tables. Add your license key and read through all the settings, choosing the ones that you want for your WooCommerce all products list. Now create a page where you want to list all products in a table (Pages > Add New.
$productId = 164; $product = wc_get_product( $productId ); echo $product->get_title(); echo $product->get_price_html(); Note, that the short description is merely the post's post_excerpt . If using outside of the loop (where $post is automatically defined) then you would need to get the post directly.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With