Home Forums WoodMart support forum Show only SKU on product page (not other meta)

Show only SKU on product page (not other meta)

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #690583

    SZenko
    Participant

    Hello,
    I would like to display only the SKU on the product page, without showing any other meta information.

    Is there a built-in setting for this, or would it require custom code?

    br
    S

    Attachments:
    You must be logged in to view attached files.
    #690643

    Hello,

    Can you please share the page URL so I can check and give you custom CSS code?

    Best Regards,

    #690792

    SZenko
    Participant

    Hello, thank you for your response.

    I thought that maybe there is an option to set this directly in the theme.

    I ended up doing it via functions.php. Is this an okay approach? Here’s what I used:

    
    /**
     * Display SKU on the WooCommerce single product page (below the product title)
     */
    add_action( 'woocommerce_single_product_summary', 'display_sku_below_title', 6 );
    
    function display_sku_below_title() {
        global $product;
    
        // Exit if $product is not defined or not a valid WC_Product object
        if ( ! is_a( $product, 'WC_Product' ) ) {
            return;
        }
    
        // Get the product SKU
        $sku = $product->get_sku();
    
        // Only display if SKU exists and is not empty
        if ( ! empty( $sku ) ) {
            // Translatable label - WPML
            $label = __( 'SKU', 'woocommerce' );
    
            // Output
            printf(
                '<p class="product-sku" style="margin-bottom:10px;"><strong>%s:</strong> %s</p>',
                esc_html( $label ),
                esc_html( $sku )
            );
        }
    }
    

    brS

    #690853

    Hello,

    You don’t need to add custom PHP code to the functions.php file for this.

    It’s possible to achieve the same result with a small CSS snippet instead.

    Please share the product page URL, and I’ll check and provide you with the exact CSS code to display only the SKU while hiding the other meta information.

    Best Regards,

Tagged: , ,

Viewing 4 posts - 1 through 4 (of 4 total)