Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives

WooPayments::has_wcpay()privateWC 1.0

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.

Method of the class: WooPayments{}

No Hooks.

Return

true|false. Whether the store has WooPayments.

Usage

// private - for code of main (parent) class only
$result = $this->has_wcpay(): bool;

WooPayments::has_wcpay() code WC 9.6.1

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,
			)
		)
	) ) {
		$had_wcpay = true;
	}

	// Store the value for future use.
	update_option( $this->store_had_woopayments_option_name, $had_wcpay ? 'yes' : 'no' );

	return $had_wcpay;
}