Hide product SKU to guest customers


Saturday, 07 September 2019

In some cases it is possible that you need to hide the identifier (SKU) of the products in your e-commerce catalog to guest customers and want to display it only if a customer is registered and logged in.

To do this, edit functions.php file that you find in your site’s FTP space in:


and insert this code:

// Hide product SKU
add_filter( 'wc_product_sku_enabled', function ( $enabled ) {
    if ( is_user_logged_in() ) {
        return true;
    return false;
} );
WARNING! Before making any changes, make sure you have made a complete backup of site files and database.
It is advisable not to edit the theme files directly, but to use a child theme.
For more information on child themes, please read: WordPress Official guide on Child Themes