Last active
June 24, 2017 11:48
-
-
Save vishalck/46fd7ba162912ebc059485b7b70fe677 to your computer and use it in GitHub Desktop.
wc_orders_count() from includes/wc-order-functions.php file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Return the orders count of a specific order status. | |
* | |
* @param string $status | |
* @return int | |
*/ | |
function wc_orders_count( $status ) { | |
$count = 0; | |
$status = 'wc-' . $status; | |
$order_statuses = array_keys( wc_get_order_statuses() ); | |
if ( ! in_array( $status, $order_statuses ) ) { | |
return 0; | |
} | |
$cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . $status; | |
$cached_count = wp_cache_get( $cache_key, 'counts' ); | |
if ( false !== $cached_count ) { | |
return $cached_count; | |
} | |
foreach ( wc_get_order_types( 'order-count' ) as $type ) { | |
$data_store = WC_Data_Store::load( 'shop_order' === $type ? 'order' : $type ); | |
if ( $data_store ) { | |
$count += $data_store->get_order_count( $status ); | |
} | |
} | |
wp_cache_set( $cache_key, $count, 'counts' ); | |
return $count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment