Add support to use `cache_hydration` in wc_get_order.
This can be used to pre-load expensive to compute caches.
This commit is contained in:
parent
86c6db0913
commit
b753189f64
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Models\CacheHydration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard way of retrieving orders based on certain parameters.
|
* Standard way of retrieving orders based on certain parameters.
|
||||||
*
|
*
|
||||||
|
@ -72,14 +74,18 @@ function wc_get_orders( $args ) {
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*
|
*
|
||||||
* @param mixed $the_order Post object or post ID of the order.
|
* @param mixed $the_order Post object or post ID of the order.
|
||||||
|
* @param CacheHydration $cache_hydration Optional, cache_hydration to initialize cache data from if available.
|
||||||
*
|
*
|
||||||
* @return bool|WC_Order|WC_Order_Refund
|
* @return bool|WC_Order|WC_Order_Refund
|
||||||
*/
|
*/
|
||||||
function wc_get_order( $the_order = false ) {
|
function wc_get_order( $the_order = false, $cache_hydration = null ) {
|
||||||
if ( ! did_action( 'woocommerce_after_register_post_type' ) ) {
|
if ( ! did_action( 'woocommerce_after_register_post_type' ) ) {
|
||||||
wc_doing_it_wrong( __FUNCTION__, 'wc_get_order should not be called before post types are registered (woocommerce_after_register_post_type action)', '2.5' );
|
wc_doing_it_wrong( __FUNCTION__, 'wc_get_order should not be called before post types are registered (woocommerce_after_register_post_type action)', '2.5' );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if ( is_a( $cache_hydration, CacheHydration::class ) ) {
|
||||||
|
return WC()->order_factory->get_order_from_hydration( $the_order, $cache_hydration );
|
||||||
|
}
|
||||||
return WC()->order_factory->get_order( $the_order );
|
return WC()->order_factory->get_order( $the_order );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue