Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
WooPayments::has_wcpay
Check if the WooPayments payment gateway is active and set up or was at some point, or there are orders processed with it, at some moment.
Метод класса: WooPayments{}
Хуков нет.
Возвращает
true|false. Whether the store has WooPayments.
Использование
// private - только в коде основоного (родительского) класса $result = $this->has_wcpay(): bool;
Код WooPayments::has_wcpay() WooPayments::has wcpay WC 10.4.3
private function has_wcpay(): bool {
// First, get the stored value, if it exists.
// This way we avoid costly DB queries and API calls.
// Basically, we only want to know if WooPayments was in use in the past.
// Since the past can't be changed, neither can this value.
$had_wcpay = get_option( $this->store_had_woopayments_option_name );
if ( false !== $had_wcpay ) {
return filter_var( $had_wcpay, FILTER_VALIDATE_BOOLEAN );
}
// We need to determine the value.
// Start with the assumption that the store didn't have WooPayments in use.
$had_wcpay = false;
// We consider the store to have WooPayments if there is meaningful account data in the WooPayments account cache.
// This implies that WooPayments was active at some point and that it was connected.
// If WooPayments is active right now, we will not get to this point since the plugin is active check is done first.
if ( $this->has_wcpay_account_data() ) {
$had_wcpay = true;
}
// If there is at least one order processed with WooPayments, we consider the store to have WooPayments.
if ( false === $had_wcpay && ! empty(
wc_get_orders(
array(
'payment_method' => 'woocommerce_payments',
'return' => 'ids',
'limit' => 1,
'orderby' => 'none',
)
)
) ) {
$had_wcpay = true;
}
// Store the value for future use.
update_option( $this->store_had_woopayments_option_name, $had_wcpay ? 'yes' : 'no' );
return $had_wcpay;
}