Disable WooCommerce SKU on Product Page

I have a WooCommerce store and I don’t want to display the SKU on any single product page. Looking at their code, I found this filter:

/**
 * Returns whether or not SKUS are enabled.
 * @return bool
 */
function wc_product_sku_enabled() {
    return apply_filters( 'wc_product_sku_enabled', true );
}

and I attempted to override it with this line of code I placed in a custom plugin:

Read More
apply_filters( 'wc_product_sku_enabled', false );

I also tried placing the apply_filter inside an action function for woocommerce_product_meta_start which fires right before but it still renders the SKU on the product page. Any ideas?

Related posts

Leave a Reply

5 comments

  1. I think you shoul try with this:

    add_filter( 'wc_product_sku_enabled', '__return_false' );
    

    That will remove sku from all woo, back and front end. You can always hide it just by CSS if need it on admin.

  2. The easiest way is with CSS:

    .sku_wrapper {
        display:none;
    }
    

    A more robust approach is to recreate the woocommerce template woocommerce/templates/single-product/meta.php in your own theme and simply comment out the line:

    <span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>
    

    To recreate a woocommerce template in your own theme, see:

    http://docs.woothemes.com/document/template-structure/

  3. Hiding the SKU/UGS by using cSS is not an efficient solution because it will be still part of the HTML code.
    In order to hide it from the product single page and keep it in the admin page, you have to add this code in the child (or parent if you don’t have the child) functions.php :

        // Remove the Product SKU from Product Single Page
    add_filter( 'wc_product_sku_enabled', 'woocustomizer_remove_product_sku' );
    
    function woocustomizer_remove_product_sku( $sku ) {
         // Remove only if NOT admin and is product single page
         if ( ! is_admin() && is_product() ) {
             return false;
         }
         return $sku;
     }
    

    Make sure also in the product php page (it can have a different name depending on the theme you use) to have this condition to show the SKU in the product single page:

    if (wc_product_sku_enabled() && $product->get_sku()) { // HTML code that shows the SKU in the product single page}
    
  4. Make Sure to remove it from the frontend only by using this code on function.php usually you can edit the function file on theme editor

    add_filter( 'wc_product_sku_enabled', 'my_remove_sku', 10 );
    function my_remove_sku( $return, $product ) {
        if ( !is_admin() && is_product() ) {
            return false;
        } else {
            return true;
        }
    }