wc_get_product()
Main function for returning products, uses the WC_Product_Factory class.
This function should only be called after 'init' action is finished, as there might be taxonomies that are getting registered during the init action.
No Hooks.
Return
WC_Product|null|false
.
Usage
wc_get_product( $the_product, $deprecated );
- $the_product(mixed)
- Post object or post ID of the product.
Default: false - $deprecated(array)
- Previously used to pass arguments to the factory, e.g. to force a type.
Default: array()
Changelog
Since 2.2.0 | Introduced. |
wc_get_product() wc get product code WC 9.6.1
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 ); }