SPECIAL OFFER: Only $59 for access to everything in OSTraining for 1 year! You save $85!  1
Join today and get access to 1,000's of books and videos. Learn WordPress, Drupal, Magento, Joomla and more! Sign up today!

Display SKU underneath Product Title (Variation)

3 years 6 months ago #123352 by nachumi_e
Alright, so i have this code to display SKU underneath the Product Title:
add_action( 'woocommerce_single_product_summary', 'product_sku' );
function product_sku(){
global $product;
echo '<div class="sku-product">' . $product->sku . '</div>';
}

And it works fantastic!

However, i wanna add that:
IF variation product = display the variation SKU and not the parent SKU.

I have the code in my theme, but since i am not a programer i cant get it to work with my code:
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
 
	<?php if ( $sku = $product->get_sku() ) : ?>
		<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo $sku; ?></span></span>
	<?php endif; ?>
 
<?php endif; ?>

Can you help me to get the is_type( 'variable' ) code migrate to my original code?

Please Log in to join the conversation.

3 years 5 months ago #123375 by Valentin
Hi nachumi_e,

One quick caveat before we start, please check out our Support FAQ on the limit of our support: Support FAQ

That being said, we’d be happy to point you in the right direction.

There is a discussion about it on this forum topic with example code that may help: wordpress.org/support/topic/condition-to...s-simple-or-variable

Kind regards,
Valentín

Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining

Please Log in to join the conversation.

3 years 5 months ago #124071 by nachumi_e
Replied by nachumi_e on topic Display SKU underneath Product Title (Variation)
I am still straggling with this .

Please Log in to join the conversation.

3 years 5 months ago - 3 years 5 months ago #124072 by Valentin
Hi nachumi_e,

Did the link above help you in any way?

Kind regards,
Valentín

Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining

Please Log in to join the conversation.

Join today and get access to 1,000's of books and videos. Learn WordPress, Drupal, Magento, Joomla and more! Sign up today!