WordPress at a glance
function is not described

WC_Product_Factory::get_product_id() WC 3.0.0

Get the product ID depending on what was passed.

This is a method of the class: WC_Product_Factory

No Hooks.

Return

Int/true/false. false on failure

Usage

$WC_Product_Factory = new WC_Product_Factory();
$var = $WC_Product_Factory->get_product_id( $product );
$product(WC_Product/WP_Post/int/true/false) (required)
Product instance, post instance, numeric or false to use global $post.

Changelog

Since 3.0.0 Introduced.

Code of WC Product Factory::get product id: woocommerce/includes/class-wc-product-factory.php WC 3.7.0

<?php
private function get_product_id( $product ) {
	global $post;

	if ( false === $product && isset( $post, $post->ID ) && 'product' === get_post_type( $post->ID ) ) {
		return absint( $post->ID );
	} elseif ( is_numeric( $product ) ) {
		return $product;
	} elseif ( $product instanceof WC_Product ) {
		return $product->get_id();
	} elseif ( ! empty( $product->ID ) ) {
		return $product->ID;
	} else {
		return false;
	}
}