wc_setup_product_data

When the_post is called, put product data into a global.

Description

(WC_Product) wc_setup_product_data( (mixed) $post ); 

Returns (WC_Product)

Parameters (1)

0. $post (mixed)
The post.

Usage

  1. if ( !function_exists( 'wc_setup_product_data' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_setup_product_data($post); 
  9.  

Defined (1)

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

/includes/wc-template-functions.php  
  1. function wc_setup_product_data( $post ) { 
  2. unset( $GLOBALS['product'] ); 
  3.  
  4. if ( is_int( $post ) ) 
  5. $post = get_post( $post ); 
  6.  
  7. if ( empty( $post->post_type ) || ! in_array( $post->post_type, array( 'product', 'product_variation' ) ) ) 
  8. return; 
  9.  
  10. $GLOBALS['product'] = wc_get_product( $post ); 
  11.  
  12. return $GLOBALS['product'];