From 9890c18b5d00b0f05cc01461b11ef1e18e6549e9 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 4 Jan 2016 10:43:48 +0000 Subject: [PATCH] Notice if called early. Closes #9923 --- includes/wc-order-functions.php | 4 ++++ includes/wc-product-functions.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index 9f4516f7d23..41d2a819121 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -51,6 +51,10 @@ function wc_is_order_status( $maybe_status ) { * @return WC_Order */ function wc_get_order( $the_order = false ) { + if ( ! did_action( 'woocommerce_init' ) ) { + _doing_it_wrong( __FUNCTION__, __( 'wc_get_order should not be called before the woocommerce_init action.', 'woocommerce' ), '2.5' ); + return false; + } return WC()->order_factory->get_order( $the_order ); } diff --git a/includes/wc-product-functions.php b/includes/wc-product-functions.php index ef3a332a0f3..51958723585 100644 --- a/includes/wc-product-functions.php +++ b/includes/wc-product-functions.php @@ -22,6 +22,10 @@ if ( ! defined( 'ABSPATH' ) ) { * @return WC_Product */ function wc_get_product( $the_product = false, $args = array() ) { + if ( ! did_action( 'woocommerce_init' ) ) { + _doing_it_wrong( __FUNCTION__, __( 'wc_get_product should not be called before the woocommerce_init action.', 'woocommerce' ), '2.5' ); + return false; + } return WC()->product_factory->get_product( $the_product, $args ); }