How to show product SKU on product page

I’m making a website and it seems that product sku is hidden from product page. I have found how to add it to the catalog (shop) page but I need it to show inside the product page.

So far, by altering the single-product.php, I managed to add it at the end of the page (something we do not want) or before the title on the top left of the page (something we also do not want).

I found no way to add it before the price and below the title of the product.

The code of the themes’ single-product.php:

    <?php
/**
 * Single Product title
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/title.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
 * will need to copy the new files to your theme to maintain compatibility. We try to do this.
 * as little as possible, but it does happen. When this occurs the version of the template file will.
 * be bumped and the readme will list any important changes.
 *
 * @see         http://docs.woothemes.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

?>
<?php echo '<div class="sku">' . $product->sku . '</div>'; ?>

I added the last line.

However, on the theme/woocommerce/single-product/meta.php I can see that sku should be displayed, which is not:

<?php
/**
 * Single Product Meta
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $post, $product;
?>
<div class="product_meta">

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

    <?php echo $product->get_categories( ', ', ' <span class="posted_in">'.__('Category:','qns' ).' ', '.</span>'); ?>

    <?php echo $product->get_tags( ', ', ' <span class="tagged_as">'.__('Tags:','qns' ).' ', '.</span>'); ?>

</div>

Any ideas of how I can show the product SKU number inside the product page?

Thanks in advance.

3 s
3

Add this to your functions.php

add_action( 'woocommerce_single_product_summary', 'dev_designs_show_sku', 5 );
function dev_designs_show_sku(){
    global $product;
    echo 'SKU: ' . $product->get_sku();
}

This will output the product SKU below the product title. See image below. The product SKU is VERTEX-SLVR.

enter image description here

Leave a Comment