wc_setup_product_data()WC 1.0

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

No Hooks.

Return

WC_Product.

Usage

wc_setup_product_data( $post );
$post(mixed) (required)
Post Object.

wc_setup_product_data() code WC 8.7.0

function wc_setup_product_data( $post ) {
	unset( $GLOBALS['product'] );

	if ( is_int( $post ) ) {
		$post = get_post( $post );
	}

	if ( empty( $post->post_type ) || ! in_array( $post->post_type, array( 'product', 'product_variation' ), true ) ) {
		return;
	}

	$GLOBALS['product'] = wc_get_product( $post );

	return $GLOBALS['product'];
}