Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders
WooPayments::has_orders
Check if the store has any paid orders.
Currently, we look at the past 90 days and only consider orders with status wc-completed, wc-processing, or wc-refunded.
Метод класса: WooPayments{}
Хуков нет.
Возвращает
true|false. Whether the store has any paid orders.
Использование
// private - только в коде основоного (родительского) класса $result = $this->has_orders(): bool;
Код WooPayments::has_orders() WooPayments::has orders WC 10.5.2
private function has_orders(): bool {
$store_has_orders_transient_name = self::PREFIX . 'store_has_orders';
// First, get the stored value, if it exists.
// This way we avoid costly DB queries and API calls.
$has_orders = get_transient( $store_has_orders_transient_name );
if ( false !== $has_orders ) {
return wc_string_to_bool( $has_orders );
}
// We need to determine the value.
// Start with the assumption that the store doesn't have orders in the timeframe we look at.
$has_orders = false;
// By default, we will check for new orders every 6 hours.
$expiration = 6 * HOUR_IN_SECONDS;
// Get the latest completed, processing, or refunded order.
$latest_order = wc_get_orders(
array(
'status' => array( OrderInternalStatus::COMPLETED, OrderInternalStatus::PROCESSING, OrderInternalStatus::REFUNDED ),
'limit' => 1,
'orderby' => 'date',
'order' => 'DESC',
)
);
if ( ! empty( $latest_order ) ) {
$latest_order = reset( $latest_order );
// If the latest order is within the timeframe we look at, we consider the store to have orders.
// Otherwise, it clearly doesn't have orders.
if ( $latest_order instanceof WC_Abstract_Order
&& strtotime( (string) $latest_order->get_date_created() ) >= strtotime( '-90 days' ) ) {
$has_orders = true;
// For ultimate efficiency, we will check again after 90 days from the latest order
// because in all that time we will consider the store to have orders regardless of new orders.
$expiration = strtotime( (string) $latest_order->get_date_created() ) + 90 * DAY_IN_SECONDS - time();
}
}
// Store the value for future use.
set_transient( $store_has_orders_transient_name, $has_orders ? 'yes' : 'no', $expiration );
return $has_orders;
}