wc_setup_product_data()WC 1.0

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

Хуков нет.

Возвращает

WC_Product.

Использование

wc_setup_product_data( $post );
$post(разное) (обязательный)
Post Object.

Код wc_setup_product_data() WC 9.4.2

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