How to Show Only the Woocommerce Sku Number?

6 minutes read

To show only the WooCommerce SKU number on your product pages, you can customize the WooCommerce template file for product pages. You would need to locate the product template file in your theme's directory (usually under /wp-content/themes/your-theme-name/woocommerce/single-product/) and open it in a code editor.


Look for the section of code that displays the product SKU, which is usually located near the product price. You can then adjust the code to display only the SKU number and remove any accompanying text or elements.


Save the changes to the template file and refresh your product pages to see the updated display showing only the WooCommerce SKU number. Remember to make a backup of the original file before making changes to avoid any accidental errors.

Best WooCommerce Cloud Hosting Providers of May 2024

1
Vultr

Rating is 5 out of 5

Vultr

  • Ultra-fast Intel Core
  • High Performance and Cheap Cloud Dedicated Servers
  • 1 click install Wordpress
  • Low Price and High Quality
2
Digital Ocean

Rating is 5 out of 5

Digital Ocean

  • Active Digital Community
  • Simple Control Panel
  • Starting from 5$ per month
3
AWS

Rating is 5 out of 5

AWS

4
Cloudways

Rating is 5 out of 5

Cloudways


How to disable all product details except the SKU in WooCommerce?

To disable all product details except the SKU in WooCommerce, you can use the following code snippet in your theme's functions.php file or in a custom plugin:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
add_filter( 'woocommerce_product_data_tabs', 'disable_product_data_tabs_except_sku', 10, 1 );
function disable_product_data_tabs_except_sku( $tabs ) {
    $tabs['inventory']['class'][] = 'hide_if_no_skus';
    $tabs['shipping']['class'][] = 'hide_if_no_skus';
    $tabs['advanced']['class'][] = 'hide_if_no_skus';
    
    return $tabs;
}

add_action( 'admin_head', 'disable_product_data_panel_except_sku' );
function disable_product_data_panel_except_sku(){
    echo '<style>
    .hide_if_no_skus {
        display: none;
    }
    </style>';
}


This code will hide the inventory, shipping, and advanced tabs in the product details page in WooCommerce, leaving only the SKU visible. Just add this code snippet to your theme's functions.php file or in a custom plugin, and the product details will be disabled accordingly.


What is the shortcode to show only the SKU in WooCommerce product listings?

To display only the SKU in WooCommerce product listings, you can use the following shortcode:

1
<?php echo $product->get_sku(); ?>


You can add this shortcode to your theme's template files such as content-product.php in the WooCommerce plugin folder to display the SKU on product listing pages.


How to use a plugin to automatically show only the SKU in WooCommerce?

To automatically show only the SKU in WooCommerce, you can use a plugin called "WooCommerce Show SKU". Here's how you can use it:

  1. Install and activate the "WooCommerce Show SKU" plugin on your WordPress website.
  2. Once activated, go to your WooCommerce settings by navigating to WooCommerce > Settings > Products.
  3. In the Product tab, you will see an option for "Show SKU". Check the box next to "Show SKU" to enable the feature.
  4. Save your changes and go to your product pages on your website. You should now see only the SKU displayed for each product instead of the full product title or other information.
  5. If you want to further customize the display of the SKU, you can go to the plugin's settings and adjust the styling or position of the SKU on your product pages.


By following these steps, you can use the "WooCommerce Show SKU" plugin to automatically show only the SKU in WooCommerce.


What is the code snippet to display only the SKU in WooCommerce?

To display only the SKU in WooCommerce, you can use the following code snippet:

1
2
3
4
5
global $product;

if ( $product->get_sku() ) {
    echo 'SKU: ' . $product->get_sku();
}


You can place this code snippet in your theme's PHP files, such as single-product.php or content-product.php, where you want to display the SKU. This code checks if the product has a SKU associated with it and only displays the SKU if it exists.


How to create a custom template to show only the SKU in WooCommerce?

To create a custom template to show only the SKU in WooCommerce, you can follow these steps:

  1. Create a new folder in your theme folder called "woocommerce" if it doesn't already exist.
  2. Inside the "woocommerce" folder, create a new file called "single-product-sku.php".
  3. Add the following code to the "single-product-sku.php" file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php
/**
 * The template for displaying product SKU.
 */

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

global $product;

if ( $product->get_sku() ) : ?>
    <div class="product-sku">
        <?php echo esc_html( $product->get_sku() ); ?>
    </div>
<?php endif; ?>


  1. Save the file and go to your WordPress admin area.
  2. Navigate to Appearance > Theme Editor and select your theme from the list of available themes.
  3. Open the "functions.php" file and add the following code to include the custom template file:
1
2
3
4
5
// Add custom template for SKU
add_action( 'woocommerce_single_product_summary', 'wc_custom_template_sku', 20 );
function wc_custom_template_sku() {
    wc_get_template( 'single-product-sku.php' );
}


  1. Save the changes and refresh your product page on the front end. You should now see the SKU displayed on the product page.


By following these steps, you can create a custom template to show only the SKU in WooCommerce. You can further customize the styling of the SKU display by adding CSS styles to your theme's stylesheet.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To import products in WooCommerce, you can follow these steps:Prepare product data: Gather all the product data in a spreadsheet or CSV format. Include details like product name, description, price, SKU, category, tags, images, and any other relevant informati...
To configure a downloadable product in WooCommerce, you first need to create a new product in your WooCommerce dashboard. Select the product type as &#34;Simple product&#34; and check the box that says &#34;Virtual&#34; and &#34;Downloadable&#34;.Next, upload ...
To show the image of a WooCommerce product attribute, you can use the &#34;Variation Swatches for WooCommerce&#34; plugin or a similar plugin that allows you to add images to product attributes.Once you have installed the plugin, you can go to the product vari...