WC_Product_Factory::get_product() public WC 1.0
Get a product.
{} Это метод класса: WC_Product_Factory{}
Хуков нет.
Возвращает
WC_Product/true/false. Product object or false if the product cannot be loaded.
Использование
$WC_Product_Factory = new WC_Product_Factory(); $WC_Product_Factory->get_product( $product_id, $deprecated );
- $product_id(разное)
- WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
- $deprecated(массив)
- Previously used to pass arguments to the factory, e.g. to force a type.
Код WC_Product_Factory::get_product() WC Product Factory::get product WC 5.0.0
public function get_product( $product_id = false, $deprecated = array() ) {
$product_id = $this->get_product_id( $product_id );
if ( ! $product_id ) {
return false;
}
$product_type = $this->get_product_type( $product_id );
// Backwards compatibility.
if ( ! empty( $deprecated ) ) {
wc_deprecated_argument( 'args', '3.0', 'Passing args to the product factory is deprecated. If you need to force a type, construct the product class directly.' );
if ( isset( $deprecated['product_type'] ) ) {
$product_type = $this->get_classname_from_product_type( $deprecated['product_type'] );
}
}
$classname = $this->get_product_classname( $product_id, $product_type );
try {
return new $classname( $product_id, $deprecated );
} catch ( Exception $e ) {
return false;
}
}