woocommerce_product_class

Gets a product classname and allows filtering.

Description

(string) apply_filters( 'woocommerce_product_class', (string) $self, (unknown) $product_type, (string) $var, (unknown) $product_id ); 

Returns WC_Product_Simple if the class does not exist.

Returns (string)

Parameters (4)

0. $self (string) => self::get_classname_from_product_type( $product_type )
The self.
1. $product_type (unknown)
The product type.
2. $var — Optional. (string) => 'variation' === $product_type ? 'product_variation' : 'product'
The variation product type product variation product.
3. $product_id (unknown)
The product id.

Usage

To run the hook, copy the example below.
  1. $self = apply_filters( 'woocommerce_product_class', $self, $product_type, $var, $product_id ); 
  2.  
  3. if ( !empty( $self ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the woocommerce_product_class callback 
  2. function filter_woocommerce_product_class( $self, $product_type, $var, $product_id ) { 
  3. // make filter magic happen here... 
  4. return $self
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'woocommerce_product_class', 'filter_woocommerce_product_class', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'woocommerce_product_class', 'filter_woocommerce_product_class', 10, 4 ); 

Defined (1)

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

/includes/class-wc-product-factory.php  
  1. $classname = apply_filters( 'woocommerce_product_class', self::get_classname_from_product_type( $product_type ), $product_type, 'variation' === $product_type ? 'product_variation' : 'product', $product_id );