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 ); }