Woocommerce sku product variations

Jorge
7 Posts
Jorge posted this 04 May 2017

Hi
I am trying to see the sku of the products, but when they are variables it does not show them.
In the product variations control, if sku variable is displayed.
I am using this code in a cms code:

<p><span>
    <?php if ( $product->is_type( array( 'simple', 'variable' ) ) && get_option('woocommerce_enable_sku') == 'yes' && $product->get_sku() ) : ?>
        <span itemprop="productID" class="sku"><?php _e('','qns' ); ?> <?php echo $product->get_sku(); ?>.</span>
    <?php endif; ?>- <?php  echo $product->get_title(); ?>
  </span> </p>

You can help me, thank you.

Hi I am trying to see the sku of the products, but when they are variables it does not show them. In the product variations control, if sku variable is displayed. I am using this code in a cms code: <p><span> <?php if ( $product->is_type( array( 'simple', 'variable' ) ) && get_option('woocommerce_enable_sku') == 'yes' && $product->get_sku() ) : ?> <span itemprop="productID" class="sku"><?php _e('','qns' ); ?> <?php echo $product->get_sku(); ?>.</span> <?php endif; ?>- <?php echo $product->get_title(); ?> </span> </p> You can help me, thank you.
Vote to pay developers attention to this features or issue.
6 Comments
Order By: Standard | Newest
Support Team
Support Team posted this 05 May 2017

Hi,

I've tested the provided code on my side with the blank Themler theme (T-Shirt product) and the SKU is visible.
Did you test this code on your side with non-Themler theme? Does it work?

Thank you,
Olivia

Hi, I've tested the provided code on my side with the blank Themler theme (T-Shirt product) and the SKU is visible. Did you test this code on your side with non-Themler theme? Does it work? Thank you, Olivia
Jorge
7 Posts
Jorge posted this 05 May 2017

Hi Olivia,
The code was only tested on a themler template.

The sku is shown if it does not have variations, if there are variations in the product the sku goes blank.

Can you use the product variations control code, and only show the sku?

Thank you

Hi Olivia, The code was only tested on a themler template. The sku is shown if it does not have variations, if there are variations in the product the sku goes blank. Can you use the product variations control code, and only show the sku? Thank you
Support Team
Support Team posted this 05 May 2017

Hi,

I have a product with variations and SKU is displayed:

woo-prod-sku.png

Please show us the settings of your product and try this code with the default WP theme.

Thank you,
Olivia

Hi, I have a product with variations and SKU is displayed: !woo-prod-sku.png! Please show us the settings of your product and try this code with the default WP theme. Thank you, Olivia
Jorge
7 Posts
Jorge posted this 05 May 2017

Hello,
I think I have not explained myself correctly, I'm sorry.
The original sku of the product if you show it, it is true. But if the variation has a sku of its own, this is not shown in the code I have used.
But in the control of product variations (Sku, categories, etc), the sku of the variation if shown.
Thank you

enter image description here

Hello, I think I have not explained myself correctly, I'm sorry. The original sku of the product if you show it, it is true. But if the variation has a sku of its own, this is not shown in the code I have used. But in the control of product variations (Sku, categories, etc), the sku of the variation if shown. Thank you ![enter image description here][1] [1]: https://preview.ibb.co/fgmHWQ/variations.jpg

Last edited 05 May 2017 by Jorge

Jorge
7 Posts
Jorge posted this 09 May 2017

Hi, any idea?

Thanks

Hi, any idea? Thanks
Jorge
7 Posts
Is Solution
Jorge posted this 09 May 2017

Hi, this code work properly :)

   <?php 
global $product;
?>
<div class>


    <?php do_action( 'woocommerce_product_meta_start' ); ?>


    <?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>


        <span class="sku_wrapper"><?php esc_html_e( '', 'woocommerce' ); ?> <span class="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' ); ?></span></span>


  <?php endif;?><span> <?php the_title();?></span>


  <?php do_action( 'woocommerce_product_meta_end' );?>

Thanks :)

Hi, this code work properly :) <?php global $product; ?> <div class> <?php do_action( 'woocommerce_product_meta_start' ); ?> <?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?> <span class="sku_wrapper"><?php esc_html_e( '', 'woocommerce' ); ?> <span class="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' ); ?></span></span> <?php endif;?><span> <?php the_title();?></span> <?php do_action( 'woocommerce_product_meta_end' );?> Thanks :)

Last edited 09 May 2017 by Jorge

You must log in or register to leave comments