wc_body_class

Add body classes for WC pages.

Description

(array) wc_body_class( (array) $classes ); 

Returns (array)

Parameters (1)

0. $classes (array)
The classes.

Usage

  1. if ( !function_exists( 'wc_body_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The classes. 
  5. $classes = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_body_class($classes); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function wc_body_class( $classes ) { 
  2. $classes = (array) $classes; 
  3.  
  4. if ( is_woocommerce() ) { 
  5.  
  6. $classes[] = woocommerce; 
  7. $classes[] = 'woocommerce-page'; 
  8.  
  9. } elseif ( is_checkout() ) { 
  10.  
  11. $classes[] = 'woocommerce-checkout'; 
  12. $classes[] = 'woocommerce-page'; 
  13.  
  14. } elseif ( is_cart() ) { 
  15.  
  16. $classes[] = 'woocommerce-cart'; 
  17. $classes[] = 'woocommerce-page'; 
  18.  
  19. } elseif ( is_account_page() ) { 
  20.  
  21. $classes[] = 'woocommerce-account'; 
  22. $classes[] = 'woocommerce-page'; 
  23.  
  24.  
  25. $classes[] = 'woocommerce-demo-store'; 
  26.  
  27. foreach ( WC()->query->query_vars as $key => $value ) { 
  28. if ( is_wc_endpoint_url( $key ) ) { 
  29. $classes[] = 'woocommerce-' . sanitize_html_class( $key ); 
  30.  
  31. return array_unique( $classes );