WC_Product::__construct() – Get the product if ID is passed, otherwise the product is new and empty.

You appear to be a bot. Output may be restricted

Description

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.

Usage

WC_Product::__construct( $product );

Parameters

$product
( int|WC_Product|object ) optional – Product to init.

Returns

void

Source

File name: woocommerce/includes/abstracts/abstract-wc-product.php
Lines:

1 to 17 of 17
  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 );
    }
  }
 

 View on GitHub View on Trac