WC_Product_Factory::get_product()publicWC 1.0

Get a product.

Method of the class: WC_Product_Factory{}

No Hooks.

Return

WC_Product|true|false. Product object or false if the product cannot be loaded.

Usage

$WC_Product_Factory = new WC_Product_Factory();
$WC_Product_Factory->get_product( $product_id, $deprecated );
$product_id(mixed)
WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
Default: false
$deprecated(array)
Previously used to pass arguments to the factory, e.g. to force a type.
Default: array()

WC_Product_Factory::get_product() code WC 9.4.2

public function get_product( $product_id = false, $deprecated = array() ) {
	$product_id = $this->get_product_id( $product_id );

	if ( ! $product_id ) {
		return false;
	}

	$product_type = self::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 = self::get_classname_from_product_type( $deprecated['product_type'] );
		}
	}

	$classname = self::get_product_classname( $product_id, $product_type );

	try {
		return new $classname( $product_id, $deprecated );
	} catch ( Exception $e ) {
		return false;
	}
}