Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WC_Product_Factory::get_product_id( WC_Product|WP_Post|int|bool $product )

Get the product ID depending on what was passed.


Description Description


Parameters Parameters

$product

(WC_Product|WP_Post|int|bool) (Required) Product instance, post instance, numeric or false to use global $post.


Top ↑

Return Return

(int|bool) false on failure


Top ↑

Source Source

File: includes/class-wc-product-factory.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;
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.