Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders\WooPayments
WooPaymentsService::get_onboarding_payment_methods_state
Get the payment methods state for onboarding.
Method of the class: WooPaymentsService{}
No Hooks.
Returns
Array. The onboarding payment methods state.
Usage
// private - for code of main (parent) class only $result = $this->get_onboarding_payment_methods_state( $location, ?array $recommended_pms ): array;
- $location(string) (required)
- The location for which we are onboarding. This is an ISO 3166-1 alpha-2 country code.
- ?array $recommended_pms(required)
- .
WooPaymentsService::get_onboarding_payment_methods_state() WooPaymentsService::get onboarding payment methods state code WC 10.7.0
private function get_onboarding_payment_methods_state( string $location, ?array $recommended_pms ): array {
// First, get the recommended payment methods details from the provider.
// We will use their enablement state as the default.
// Note: The list is validated and standardized by the provider, so we don't need to do it here.
if ( null === $recommended_pms ) {
$recommended_pms = $this->get_onboarding_recommended_payment_methods( $location );
}
if ( empty( $recommended_pms ) ) {
// If there are no recommended payment methods, return an empty array.
return array();
}
// Grab the stored payment methods state
// (a key-value array of payment method IDs and if they should be automatically enabled or not).
$step_pms_data = (array) $this->get_nox_profile_onboarding_step_data_entry( self::ONBOARDING_STEP_PAYMENT_METHODS, $location, 'payment_methods' );
$payment_methods_state = array();
$apple_pay_enabled = false;
$google_pay_enabled = false;
foreach ( $recommended_pms as $recommended_pm ) {
$pm_id = $recommended_pm['id'];
/**
* We need to handle Apple Pay and Google Pay separately.
* They are not stored in the same way as the other payment methods.
*/
if ( 'apple_pay' === $pm_id ) {
$apple_pay_enabled = $recommended_pm['enabled'];
continue;
}
if ( 'google_pay' === $pm_id ) {
$google_pay_enabled = $recommended_pm['enabled'];
continue;
}
// Start with the recommended enabled state.
$payment_methods_state[ $pm_id ] = $recommended_pm['enabled'];
// Force enable if required.
if ( $recommended_pm['required'] ) {
$payment_methods_state[ $pm_id ] = true;
continue;
}
// Check the stored state, if any.
if ( isset( $step_pms_data[ $pm_id ] ) ) {
$payment_methods_state[ $pm_id ] = wc_string_to_bool( $step_pms_data[ $pm_id ] );
}
}
// Combine Apple Pay and Google Pay into a single `apple_google` entry.
// First check if apple_google is explicitly stored, otherwise fallback to combining individual states.
if ( isset( $step_pms_data['apple_google'] ) ) {
$apple_google_enabled = wc_string_to_bool( $step_pms_data['apple_google'] );
} else {
// Fallback to OR logic for backward compatibility.
$apple_google_enabled = $apple_pay_enabled || $google_pay_enabled;
}
$payment_methods_state['apple_google'] = $apple_google_enabled;
return $payment_methods_state;
}