wc_get_product( mixed $the_product = false, array $deprecated = array() )

Main function for returning products, uses the WC_Product_Factory class.


Description Description

This function should only be called after ‘init’ action is finished, as there might be taxonomies that are getting registered during the init action.


Parameters Parameters

$the_product

(Optional) Post object or post ID of the product.

Default value: false

$deprecated

(Optional) Previously used to pass arguments to the factory, e.g. to force a type.

Default value: array()


Top ↑

Return Return

(WC_Product|null|false)


Top ↑

Source Source

File: includes/wc-product-functions.php

function wc_get_product( $the_product = false, $deprecated = array() ) {
	if ( ! did_action( 'woocommerce_init' ) || ! did_action( 'woocommerce_after_register_taxonomy' ) || ! did_action( 'woocommerce_after_register_post_type' ) ) {
		/* translators: 1: wc_get_product 2: woocommerce_init 3: woocommerce_after_register_taxonomy 4: woocommerce_after_register_post_type */
		wc_doing_it_wrong( __FUNCTION__, sprintf( __( '%1$s should not be called before the %2$s, %3$s and %4$s actions have finished.', 'woocommerce' ), 'wc_get_product', 'woocommerce_init', 'woocommerce_after_register_taxonomy', 'woocommerce_after_register_post_type' ), '3.9' );
		return false;
	}
	if ( ! empty( $deprecated ) ) {
		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.' );
	}
	return WC()->product_factory->get_product( $the_product, $deprecated );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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