Notice if called early.

Closes #9923
This commit is contained in:
Mike Jolley 2016-01-04 10:43:48 +00:00
parent 8b9bdbb228
commit 9890c18b5d
2 changed files with 8 additions and 0 deletions

View File

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

View File

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