Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\PaymentGateways\Schema

CodGatewaySettingsSchema::get_custom_groups_for_gatewayprotectedWC 1.0

Get custom groups for the COD gateway.

Provides design-aligned labels and descriptions for the cash on delivery settings form fields. Derives fields from the gateway's form_fields to preserve any extension-injected settings.

Method of the class: CodGatewaySettingsSchema{}

No Hooks.

Returns

Array. Custom group structure.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_custom_groups_for_gateway( $gateway ): array;
$gateway(WC_Payment_Gateway) (required)
Gateway instance.

CodGatewaySettingsSchema::get_custom_groups_for_gateway() code WC 10.7.0

protected function get_custom_groups_for_gateway( WC_Payment_Gateway $gateway ): array {
	// Design-aligned overrides for core fields.
	$core_field_overrides = array(
		'enabled'            => array(
			'label' => __( 'Enable/Disable', 'woocommerce' ),
			'type'  => 'checkbox',
			'desc'  => __( 'Enable Cash on delivery at checkout', 'woocommerce' ),
		),
		'title'              => array(
			'label' => __( 'Checkout label', 'woocommerce' ),
			'type'  => 'text',
			'desc'  => __( 'Shown to customers on the payment methods list at checkout.', 'woocommerce' ),
		),
		'description'        => array(
			'label' => __( 'Checkout instructions', 'woocommerce' ),
			'type'  => 'text',
			'desc'  => __( 'Shown below the checkout label.', 'woocommerce' ),
		),
		'order'              => array(
			'label' => __( 'Order', 'woocommerce' ),
			'type'  => 'number',
			'desc'  => __( 'Determines the display order of payment gateways during checkout.', 'woocommerce' ),
		),
		'instructions'       => array(
			'label' => __( 'Order confirmation instructions', 'woocommerce' ),
			'type'  => 'text',
			'desc'  => __( 'Shown on the order confirmation page and in order emails.', 'woocommerce' ),
		),
		'enable_for_methods' => array(
			'label'   => __( 'Available for shipping methods', 'woocommerce' ),
			'type'    => 'multiselect',
			'desc'    => __( 'Choose which shipping methods support Cash on delivery.', 'woocommerce' ),
			'options' => $this->load_shipping_method_options(),
		),
		'enable_for_virtual' => array(
			'label' => __( 'Accept for virtual orders', 'woocommerce' ),
			'type'  => 'checkbox',
			'desc'  => __( 'Accept COD if the order is virtual', 'woocommerce' ),
		),
	);

	$fields = $this->build_fields_from_form_fields( $gateway, $core_field_overrides );

	$group = array(
		'title'       => __( 'Cash on delivery settings', 'woocommerce' ),
		'description' => __( 'Manage how Cash on delivery appears at checkout and in order emails.', 'woocommerce' ),
		'order'       => 1,
		'fields'      => $fields,
	);

	return array( 'settings' => $group );
}