WC_Order_Item_Product::set_product
Aggregate and set properties based on passed in product object.
Method of the class: WC_Order_Item_Product{}
No Hooks.
Returns
void. Nothing (null).
Usage
$WC_Order_Item_Product = new WC_Order_Item_Product(); $WC_Order_Item_Product->set_product( $product );
- $product(WC_Product) (required)
- Product instance.
WC_Order_Item_Product::set_product() WC Order Item Product::set product code WC 11.1.2
public function set_product( $product ) {
if ( ! ( $product instanceof \WC_Product ) ) {
$this->error( 'order_item_product_invalid_product', __( 'Invalid product', 'woocommerce' ) );
}
if ( $product->is_type( ProductType::VARIATION ) ) {
$this->set_product_id( $product->get_parent_id() );
$this->set_variation_id( $product->get_id() );
$this->set_variation( is_callable( array( $product, 'get_variation_attributes' ) ) ? $product->get_variation_attributes() : array() );
} else {
$this->set_product_id( $product->get_id() );
$this->set_variation_id( 0 );
// Any variation attribute meta written by a previous set_variation() call is left in
// place on purpose: it is stored with the `attribute_` prefix stripped, so a key like
// `color` is indistinguishable from a merchant's own custom meta and clearing it here
// risks deleting real data. Removing that stale display meta is tracked in #66733.
}
$this->set_name( $product->get_name() );
$this->set_tax_class( $product->get_tax_class() );
}