WC_Product_Factory
in package
Product factory class.
Table of Contents
- get_classname_from_product_type() : string|false
- Create a WC coding standards compliant class name e.g. WC_Product_Type_Class instead of WC_Product_type-class.
- get_product() : WC_Product|bool
- Get a product.
- get_product_classname() : string
- Gets a product classname and allows filtering. Returns WC_Product_Simple if the class does not exist.
- get_product_type() : string|false
- Get the product type for a product.
- get_product_id() : int|bool
- Get the product ID depending on what was passed.
Methods
get_classname_from_product_type()
Create a WC coding standards compliant class name e.g. WC_Product_Type_Class instead of WC_Product_type-class.
public
static get_classname_from_product_type(string $product_type) : string|false
Parameters
- $product_type : string
-
Product type.
Return values
string|false —get_product()
Get a product.
public
get_product([mixed $product_id = false ][, array<string|int, mixed> $deprecated = array() ]) : WC_Product|bool
Parameters
- $product_id : mixed = false
-
WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
- $deprecated : array<string|int, mixed> = array()
-
Previously used to pass arguments to the factory, e.g. to force a type.
Return values
WC_Product|bool — Product object or false if the product cannot be loaded.get_product_classname()
Gets a product classname and allows filtering. Returns WC_Product_Simple if the class does not exist.
public
static get_product_classname(int $product_id, string $product_type) : string
Parameters
- $product_id : int
-
Product ID.
- $product_type : string
-
Product type.
Tags
Return values
string —get_product_type()
Get the product type for a product.
public
static get_product_type(int $product_id) : string|false
Parameters
- $product_id : int
-
Product ID.
Tags
Return values
string|false —get_product_id()
Get the product ID depending on what was passed.
private
get_product_id(WC_Product|WP_Post|int|bool $product) : int|bool
Parameters
- $product : WC_Product|WP_Post|int|bool
-
Product instance, post instance, numeric or false to use global $post.