WC_Product::__construct PHP Method

__construct() public method

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.
public __construct ( integer | WC_Product | object $product )
$product integer | WC_Product | object Product to init.
    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);
        }
    }

Usage Example

 function __construct($bundle_id)
 {
     $this->product_type = 'composite';
     parent::__construct($bundle_id);
     $this->composite_data = get_post_meta($this->id, '_bto_data', true);
     $this->per_product_pricing = get_post_meta($this->id, '_per_product_pricing_bto', true);
     $this->per_product_shipping = get_post_meta($this->id, '_per_product_shipping_bto', true);
     $this->composite_layout = get_post_meta($this->id, '_bto_style', true);
     $this->selections_style = get_post_meta($this->id, '_bto_selection_mode', true);
     $this->contains_nyp = false;
     $this->has_discounts = false;
     $this->min_price = get_post_meta($this->id, '_min_composite_price', true);
     $this->max_price = get_post_meta($this->id, '_max_composite_price', true);
     $this->price_meta = (double) get_post_meta($this->id, '_price', true);
     $base_price = get_post_meta($this->id, '_base_price', true);
     $base_regular_price = get_post_meta($this->id, '_base_regular_price', true);
     $base_sale_price = get_post_meta($this->id, '_base_sale_price', true);
     $this->base_price = empty($base_price) ? 0.0 : (double) $base_price;
     $this->base_regular_price = empty($base_regular_price) ? 0.0 : (double) $base_regular_price;
     $this->base_sale_price = empty($base_sale_price) ? 0.0 : (double) $base_sale_price;
     $this->hide_price_html = get_post_meta($this->id, '_bto_hide_shop_price', true) == 'yes' ? true : false;
     if ($this->is_priced_per_product()) {
         $this->price = $this->get_base_price();
     }
 }
All Usage Examples Of WC_Product::__construct
WC_Product