Automattic\WooCommerce\StoreApi\Utilities

CartController::get_product_idprotectedWC 1.0

For a given product, get the product ID.

Method of the class: CartController{}

No Hooks.

Returns

Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_product_id( $product );
$product(WC_Product) (required)
Product object associated with the cart item.

CartController::get_product_id() code WC 10.5.0

protected function get_product_id( \WC_Product $product ) {
	return $product->is_type( ProductType::VARIATION ) ? $product->get_parent_id() : $product->get_id();
}