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:
vedanshujain 2020-06-24 18:53:52 +05:30
parent 86c6db0913
commit b753189f64
1 changed files with 8 additions and 2 deletions

View File

@ -10,6 +10,8 @@
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Models\CacheHydration;
/**
* Standard way of retrieving orders based on certain parameters.
*
@ -71,15 +73,19 @@ function wc_get_orders( $args ) {
*
* @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
*/
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' ) ) {
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;
}
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 );
}