WC_Product_Factory::get_product_classname
Gets a product classname and allows filtering. Returns WC_Product_Simple if the class does not exist.
Method of the class: WC_Product_Factory{}
Hooks from the method
Returns
String.
Usage
$result = WC_Product_Factory::get_product_classname( $product_id, $product_type );
- $product_id(int) (required)
- Product ID.
- $product_type(string) (required)
- Product type.
Changelog
| Since 3.0.0 | Introduced. |
WC_Product_Factory::get_product_classname() WC Product Factory::get product classname code WC 10.4.3
public static function get_product_classname( $product_id, $product_type ) {
/**
* Filter the product class name.
*
* @param string $classname Classname.
* @param string $product_type Product type.
* @param string $context Context.
* @param int $product_id Product ID.
*
* @since 3.0.0
*/
$classname = apply_filters( 'woocommerce_product_class', self::get_classname_from_product_type( $product_type ), $product_type, ProductType::VARIATION === $product_type ? 'product_variation' : 'product', $product_id );
if ( ! $classname || ! class_exists( $classname ) ) {
$classname = 'WC_Product_Simple';
}
return $classname;
}