Skip to main content
Login Join
Snippet · PHP

Add a Custom Body Class to WooCommerce Product Pages

Shared by Amit Dholiya · August 25, 2026 · @body_class

2 views
Back to Snippets

Adding a custom CSS class to WooCommerce product pages makes it easier to apply page-specific styling without affecting the rest of your website.

Steps

  1. Open your theme’s functions.php file.
  2. Add the code below.
  3. Save the file.
  4. Open any WooCommerce product page and inspect the <body> tag.

Done — the class single-product-custom will be added to WooCommerce single product pages.

function add_custom_product_body_class( $classes ) {

    if ( is_product() ) {
        $classes[] = 'single-product-custom';
    }

    return $classes;
}

add_filter(
    'body_class',
    'add_custom_product_body_class'
);
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments