wc_product_post_class

Adds extra post classes for products.

Description

(array) wc_product_post_class( (array) $classes, (string) $class = '', (string) $post_id = '' ); 

Returns (array)

Parameters (3)

0. $classes (array)
The classes.
1. $class — Optional. (string) => ''
The class.
2. $post_id — Optional. (string) => ''
The post id.

Usage

  1. if ( !function_exists( 'wc_product_post_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The classes. 
  5. $classes = array(); 
  6.  
  7. // The class. 
  8. $class = ''; 
  9.  
  10. // The post id. 
  11. $post_id = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wc_product_post_class($classes, $class, $post_id); 
  15.  

Defined (1)

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

/includes/wc-template-functions.php  
  1. function wc_product_post_class( $classes, $class = '', $post_id = '' ) { 
  2. if ( ! $post_id || ! in_array( get_post_type( $post_id ), array( 'product', 'product_variation' ) ) ) { 
  3. return $classes; 
  4.  
  5. $product = wc_get_product( $post_id ); 
  6.  
  7. if ( $product ) { 
  8. $classes[] = 'product'; 
  9. $classes[] = wc_get_loop_class(); 
  10. $classes[] = $product->get_stock_status(); 
  11.  
  12. if ( $product->is_on_sale() ) { 
  13. $classes[] = 'sale'; 
  14. if ( $product->is_featured() ) { 
  15. $classes[] = 'featured'; 
  16. if ( $product->is_downloadable() ) { 
  17. $classes[] = 'downloadable'; 
  18. if ( $product->is_virtual() ) { 
  19. $classes[] = 'virtual'; 
  20. if ( $product->is_sold_individually() ) { 
  21. $classes[] = 'sold-individually'; 
  22. if ( $product->is_taxable() ) { 
  23. $classes[] = 'taxable'; 
  24. if ( $product->is_shipping_taxable() ) { 
  25. $classes[] = 'shipping-taxable'; 
  26. if ( $product->is_purchasable() ) { 
  27. $classes[] = 'purchasable'; 
  28. if ( $product->get_type() ) { 
  29. $classes[] = "product-type-" . $product->get_type(); 
  30. if ( $product->is_type( 'variable' ) ) { 
  31. if ( ! $product->get_default_attributes() ) { 
  32. $classes[] = 'has-default-attributes'; 
  33. if ( $product->has_child() ) { 
  34. $classes[] = 'has-children'; 
  35.  
  36. if ( false !== ( $key = array_search( 'hentry', $classes ) ) ) { 
  37. unset( $classes[ $key ] ); 
  38.  
  39. return $classes;