WC_Product::__construct
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.
Method of the class: WC_Product{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Product = new WC_Product(); $WC_Product->__construct( $product );
- $product(int|WC_Product|object)
- Product to init.
WC_Product::__construct() WC Product:: construct code WC 10.5.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 );
}
}