WordPress at Your Fingertips
function is not described

WC_Product::__construct() public WC 1.0

Get the product if ID is passed, otherwise the product is new and empty. This class should NOT be instantiated, but the wc_get_product() function should be used. It is possible, but the wc_get_product() is preferred.

{} It's a method of the class: WC_Product{}

No Hooks.

Return

null. Nothing.

Usage

$WC_Product = new WC_Product();
$WC_Product->__construct( $product );
$product(int|WC_Product|object)
Product to init.

Code of WC_Product::__construct() WC 5.8.0

public function __construct( $product = 0 ) {
	parent::__construct( $product );
	if ( is_numeric( $product ) && $product > 0 ) {
		$this->set_id( $product );
	} elseif ( $product instanceof self ) {
		$this->set_id( absint( $product->get_id() ) );
	} elseif ( ! empty( $product->ID ) ) {
		$this->set_id( absint( $product->ID ) );
	} else {
		$this->set_object_read( true );
	}

	$this->data_store = WC_Data_Store::load( 'product-' . $this->get_type() );
	if ( $this->get_id() > 0 ) {
		$this->data_store->read( $this );
	}
}