Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\PaymentGateways\Schema
AbstractPaymentGatewaySettingsSchema::get_settings
Return settings associated with this payment gateway.
Note: Some gateways may conditionally populate the 'options' array for select/multiselect fields based on context (e.g., only when accessing settings pages) for performance reasons. For example, the COD gateway's enable_for_methods field loads shipping method options only when is_accessing_settings() returns true. This means the options array may be empty when accessed via the REST API, even though the field type is multiselect.
Method of the class: AbstractPaymentGatewaySettingsSchema{}
No Hooks.
Returns
Array.
Usage
$AbstractPaymentGatewaySettingsSchema = new AbstractPaymentGatewaySettingsSchema(); $AbstractPaymentGatewaySettingsSchema->get_settings( $gateway ): array;
- $gateway(WC_Payment_Gateway) (required)
- Gateway instance.
AbstractPaymentGatewaySettingsSchema::get_settings() AbstractPaymentGatewaySettingsSchema::get settings code WC 10.4.3
public function get_settings( WC_Payment_Gateway $gateway ): array {
$settings = array();
$gateway->init_form_fields();
foreach ( $gateway->form_fields as $id => $field ) {
// Make sure we at least have a title and type.
if ( empty( $field['title'] ) || empty( $field['type'] ) ) {
continue;
}
// Ignore 'enabled' and 'description' which get included elsewhere.
if ( in_array( $id, array( 'enabled', 'description' ), true ) ) {
continue;
}
$data = array(
'id' => $id,
'label' => empty( $field['label'] ) ? $field['title'] : $field['label'],
'description' => empty( $field['description'] ) ? '' : $field['description'],
'type' => $field['type'],
'value' => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ],
'default' => empty( $field['default'] ) ? '' : $field['default'],
'tip' => empty( $field['description'] ) ? '' : $field['description'],
'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'],
);
if ( ! empty( $field['options'] ) ) {
$data['options'] = $field['options'];
}
$settings[ $id ] = $data;
}
return $settings;
}