wc_body_class()
Adds WooCommerce classes related to the current page to the <body> tag.
The function is automatically called on the body_class filter. Therefore, there is no need to use this function directly anywhere - everything is done through the body_class hook.
In addition to other classes, the function always adds the class woocommerce-no-js and triggers the wc_no_js() function in the footer, which in turn changes this class to woocommerce-js. Thus, WC determines whether JS is working in the browser.
No Hooks.
Returns
Array. Enhanced array of classes for the body tag.
Usage
wc_body_class( $classes );
- $classes(array) (required)
- Array of classes passed to the body_class hook.
Examples
#1 Add a body class of the product type for the product page
add_filter( 'body_class', 'add_class_to_product_page' );
function add_class_to_product_page( $classes ){
if ( is_product() ) {
$product = wc_get_product();
$classes[] = 'product-type-' . $product->get_type();
}
return $classes;
}