How to show sku on WooCommerce product page divi?

Displaying SKU on WooCommerce Product Page using Divi

Introduction

In this article, we will explore how to display the SKU (Stock Keeping Unit) on the WooCommerce product page using the Divi theme. Divi is a popular WordPress theme that offers a wide range of customization options, making it an ideal choice for businesses looking to create a professional-looking website.

Why Display SKU on WooCommerce Product Page?

Displaying the SKU on the product page is essential for several reasons:

  • Product Information: The SKU provides valuable information about the product, such as its stock status, quantity, and price.
  • Customer Experience: Displaying the SKU helps customers quickly identify the product they are purchasing, reducing the likelihood of errors or misunderstandings.
  • SEO: The SKU can also be used as a keyword in search engine optimization (SEO) to improve the product’s visibility in search results.

Step-by-Step Guide to Displaying SKU on WooCommerce Product Page using Divi

Step 1: Create a Custom Template

To display the SKU on the WooCommerce product page, you need to create a custom template. Here’s how to do it:

  • Log in to your Divi dashboard and navigate to Customize > Templates.
  • Click on Add New and select Custom Template.
  • Give your template a name, such as "WooCommerce SKU Template".
  • Click on Save Template.

Step 2: Add the SKU to the Product Page

To display the SKU on the product page, you need to add it to the product’s content area. Here’s how to do it:

  • Log in to your Divi dashboard and navigate to Customize > Templates.
  • Select the "WooCommerce SKU Template" you created earlier.
  • Click on Product and then click on Add Content.
  • In the Add Content section, click on Add HTML.
  • Paste the following code into the Add HTML field:
    <div class="sku">
    <span class="sku-number"></span>
    <span class="sku-unit"></span>
    <span class="sku-status"></span>
    <span class="sku-price"></span>
    </div>
  • Replace the class names with the ones that match your theme’s CSS.

Step 3: Add the SKU to the Product Page using CSS

To make the SKU display correctly, you need to add some CSS code. Here’s how to do it:

  • Log in to your Divi dashboard and navigate to Customize > Templates.
  • Select the "WooCommerce SKU Template" you created earlier.
  • Click on Product and then click on Add Content.
  • In the Add Content section, click on Add HTML.
  • Paste the following code into the Add HTML field:

    .sku {
    position: relative;
    width: 100%;
    height: 100px;
    margin: 20px auto;
    }

.sku-number {
position: absolute;
top: 10px;
left: 10px;
font-size: 24px;
font-weight: bold;
}

.sku-unit {
position: absolute;
top: 40px;
left: 10px;
font-size: 18px;
}

.sku-status {
position: absolute;
top: 70px;
left: 10px;
font-size: 16px;
}

.sku-price {
position: absolute;
top: 90px;
left: 10px;
font-size: 18px;
}

*   Replace the class names with the ones that match your theme's CSS.

### **Step 4: Add the SKU to the Product Page using PHP**

To make the SKU display correctly, you need to add some PHP code. Here's how to do it:

* Log in to your Divi dashboard and navigate to **Customize** > **Templates**.
* Select the "WooCommerce SKU Template" you created earlier.
* Click on **Product** and then click on **Add Content**.
* In the **Add Content** section, click on **Add HTML**.
* Paste the following code into the **Add HTML** field:
```php
<?php
$sku = get_post_meta(get_the_ID(), '_sku', true);
?>
<div class="sku">
<span class="sku-number"><?php echo $sku['sku_number']; ?></span>
<span class="sku-unit"><?php echo $sku['sku_unit']; ?></span>
<span class="sku-status"><?php echo $sku['sku_status']; ?></span>
<span class="sku-price"><?php echo $sku['sku_price']; ?></span>
</div>

  • Replace the class names with the ones that match your theme’s CSS.

Conclusion

Displaying the SKU on the WooCommerce product page using Divi is a simple and effective way to provide valuable information to customers. By following these steps, you can create a custom template, add the SKU to the product page, and use PHP to display the SKU correctly. With Divi’s flexibility and customization options, you can create a professional-looking website that meets your business needs.

Tips and Variations

  • You can customize the appearance of the SKU by modifying the CSS code.
  • You can add more information to the SKU, such as the product description or reviews.
  • You can use different classes to display different information, such as the product category or brand.
  • You can use JavaScript to animate the SKU or add interactive effects.

Troubleshooting

  • If the SKU is not displaying correctly, check the CSS code and make sure that the classes are correct.
  • If the SKU is not displaying at all, check the PHP code and make sure that the variables are being set correctly.
  • If the SKU is displaying incorrectly, check the theme’s CSS and make sure that the classes are correct.

Unlock the Future: Watch Our Essential Tech Videos!


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top