wc_setup_product_data( mixed $post )

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


Description Description


Parameters Parameters

$post

(Required) Post Object.


Top ↑

Return Return

(WC_Product)


Top ↑

Source Source

File: includes/wc-template-functions.php

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'];
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.