Archived topic
SKU is not displayed correctly when using variants
1 reply · Started by Sophia on June 27, 2020
Hey!
We have a webshop for medical products, and there it is very important to show the SKU for all products. As far as I could see, it is not shown by default, so I added this snippet:
add_action('woocommerce_single_product_summary', 'display_product_sku_and_gtin');
function display_product_sku_and_gtin() {
global $product;
if ($product->get_sku()){
echo 'Artikelnummer: ' .$product->get_sku();
}
}
This is working great for normal products, but when I have a page with variants (see this one: Link it always just shows the SKU of the main product (FG 001-1-1) instead of the one of the variants (e.g. for 010 it would be FG 001-G-010). Is there a way how I could set it up that for variants it is showing the variants-SKU?
Thanks in advance!
Hi there,
that would require woocommerce development which is out of our scope.
I did find this stack:
https://stackoverflow.com/a/60274464
it explains the method of getting the varient SKU's and points the Ajax and jQuery methods of updating them.