I have this code that works for simple product type but not for variable products in WooCommerce:
add_shortcode( \'product_sku_div\', \'wc_product_sku_div\'
You need to use get_available_variations();
.
add_shortcode( 'product_sku_div', 'wc_product_sku_div');
function wc_product_sku_div() {
global $product;
$variants_array = $product->get_available_variations();
for ($i = 0; $i < count($variants_array); $i++ ) {
return sprintf( '', $variants_array[$i]['sku'] );
}
}
Reference:
get_available_variations()
~ https://docs.woocommerce.com/wc-apidocs/class-WC_Product_Variable.html