Is there a way to display the current product SKU and GTIN in a variable product page? Right now I'm using the following code, but it only works for simple products without variations:
add_action('woocommerce_single_product_summary', 'show_sku_and_gtin');
function show_sku_and_gtin() {
global $product, $post;
echo '<p>SKU: '.$product->sku.'</p>';
// In my case, GTIN is a custom field called "barcode"
echo '<p>GTIN: '.get_post_meta($post->ID, 'barcode', 1).'</p>';
}
I'd like it to update the SKU and GTIN dynamically whenever I choose a different product variation in the product page.