How to remove SKU display from WooCommerce product page with code? Complete Practical Guide

exist WooCommerce By default, the SKU (Stock Unit) field is displayed on the product detail page to distinguish the product inventory. But in many scenarios, merchants don't want to show SKU directly to users, for example:

  • Products are customized and do not need to disclose the number
  • Page visual design requires minimalism
  • SKUs have no real reference value to customers

The following will introduce how to hide the SKU display content of WooCommerce product page with a simple code, without plugin and with quick effect.

Image [1] - How to remove SKU display from WooCommerce product page with code? Complete Practical Guide

I. How to hide SKU display

Want to hide the SKU display on WooCommerce product pages? It's easy! WooCommerce is designed to hide the SKUs on the product page by using thehooks(hook) mechanism to display SKU's, you can easily remove it by simply unhooking it. Here's how to do it:

1. Open the theme's functions.php file

The file can be found at the following path:

WordPress Backend → Appearance → Theme File Editor → functions.php

Image [2] - How to remove SKU display from WooCommerce product page with code? Complete Practical Guide

It is recommended to use a child theme or code snippet plugin (such as Code Snippets) to make changes to avoid being overwritten after a theme update.

2. Add the following code

add_filter( 'wc_product_sku_enabled', '__return_false' );

The meaning of this code is: putWooCommerce The filter used to control the SKU display in wc_product_sku_enabled set to falseThe SKU display function in the frontend is disabled.

Add the code before:

Image [3] - How to remove SKU display from WooCommerce product page with code? Complete Practical Guide

II. Verification of effectiveness

After adding the code:

Image [4] - How to remove SKU display from WooCommerce product page with code? Complete Practical Guide

Save and Refreshofferingspage, you will find that SKUs are no longer displayed in the product summary information and will not affect the management of SKUs in the backend edit page. This means:

  • SKU information can also be entered and saved in the backend
  • SKUs can be used for order management, inventory control
  • SKU field will not be visible to front-end visitors

Third, add: Hide SKUs for simple items only?

If you only want to hide SKUs for a certain category of products (e.g. "Simple Products" only), you can use the following more complex code to implement the conditional judgment:

add_filter( 'wc_product_sku_enabled', 'custom_hide_sku_for_simple_products', 10, 2 );
function custom_hide_sku_for_simple_products( $enabled, $product ) {
    if ( is_product() && $product->is_type( 'simple' ) ) {
        return false; }
    }
    return $enabled;
}

The logic of this code is that only a single product page (is_product()SKU display is disabled when the product type is "simple", but other product types remain.

IV. Frequently asked questions

Image [5] - How to remove SKU display from WooCommerce product page with code? Complete Practical Guide

Q1: Is this code valid for variant items as well?

default add_filter( 'wc_product_sku_enabled', '__return_false' ); It affects all commodity types, including variable, grouped, etc.

If you only want to block certain types, refer to the second code provided above and adjust the judgment conditions as needed.

Q2: How to restore SKU display?

Just remove or comment out the added code and refresh the page to restore the default display.

V. Conclusion

No need to install plugins, no need to modify the template, just add a line of code to the functions.php file of the theme to make the WooCommerce Product pages are cleaner. This is the first step in optimizing your product pages, and we'll be sharing more WooCommerce customization tips to create a professional-grade e-commerce site.


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
Customer Service
Customer Service
Tel: 020-2206-9892
QQ咨詢:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
? Reprint statement
Author: linxiulian
THE END
If you like it, support it.
kudos127 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments