yit_get_base_product_id

New way to retrieve the $product->id as it was before WC 2.7.

Description

yit_get_base_product_id( (WC_Product) $product ); 

Retrieve the parent product id for WC_Product_Variation instances or the product id in the other cases.

Parameters (1)

0. $product (WC_Product)
The product.

Usage

  1. if ( !function_exists( 'yit_get_base_product_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-compare/plugin-fw/yit-woocommerce-compatibility.php'; 
  3.  
  4. // The product. 
  5. $product = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = yit_get_base_product_id($product); 
  9.  

Defined (1)

The function is defined in the following location(s).

/plugin-fw/yit-woocommerce-compatibility.php  
  1. function yit_get_base_product_id( $product ) { 
  2.  
  3. return $product instanceof WC_Data && $product->is_type( 'variation' ) ? 
  4. yit_get_prop( $product, 'parent_id' ) : 
  5. yit_get_prop( $product, 'id' );