wc_get_product

Main function for returning products, uses the WC_Product_Factory class.

Description

(WC_Product|null) wc_get_product( (constant) $the_product = false, (array) $deprecated = array() ); 

Returns (WC_Product|null)

Parameters (2)

0. $the_product — Optional. (constant) => false
Post object or post ID of the product.
1. $deprecated — Optional. (array) => array()
Previously used to pass arguments to the factory, e.g. to force a type.

Usage

  1. if ( !function_exists( 'wc_get_product' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4. // Post object or post ID of the product. 
  5. $the_product = false; 
  6.  
  7. // Previously used to pass arguments to the factory, e.g. to force a type. 
  8. $deprecated = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_get_product($the_product, $deprecated); 
  12.  

Defined (1)

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

/includes/wc-product-functions.php  
  1. function wc_get_product( $the_product = false, $deprecated = array() ) { 
  2. if ( ! did_action( 'woocommerce_init' ) ) { 
  3. wc_doing_it_wrong( __FUNCTION__, __( 'wc_get_product should not be called before the woocommerce_init action.', woocommerce ), '2.5' ); 
  4. return false; 
  5. if ( ! empty( $deprecated ) ) { 
  6. wc_deprecated_argument( 'args', '3.0', 'Passing args to wc_get_product is deprecated. If you need to force a type, construct the product class directly.' ); 
  7. return WC()->product_factory->get_product( $the_product, $deprecated );