WC_Product_Factory::get_product_id()
Get the product ID depending on what was passed.
Method of the class: WC_Product_Factory{}
No Hooks.
Return
Int|true|false
. false on failure
Usage
// private - for code of main (parent) class only $result = $this->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. |
WC_Product_Factory::get_product_id() WC Product Factory::get product id code WC 9.4.2
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; } }