Automattic\WooCommerce\Admin\Settings

SettingsSectionRegistry::is_reserved_checkout_section_idprivateWC 1.0

Check whether a checkout section id is reserved by an existing payment gateway.

Method of the class: SettingsSectionRegistry{}

No Hooks.

Returns

true|false.

Usage

// private - for code of main (parent) class only
$result = $this->is_reserved_checkout_section_id( $parent_page_id, $section_id ): bool;
$parent_page_id(string) (required)
Parent settings page id.
$section_id(string) (required)
Section id.

SettingsSectionRegistry::is_reserved_checkout_section_id() code WC 10.9.1

private function is_reserved_checkout_section_id( string $parent_page_id, string $section_id ): bool {
	if ( 'checkout' !== $parent_page_id || ! function_exists( 'WC' ) ) {
		return false;
	}

	try {
		$wc = WC();
		if ( ! $wc || ! is_callable( array( $wc, 'payment_gateways' ) ) ) {
			return false;
		}

		$payment_gateways = $wc->payment_gateways();
		if ( ! $payment_gateways || ! is_callable( array( $payment_gateways, 'payment_gateways' ) ) ) {
			return false;
		}

		foreach ( $payment_gateways->payment_gateways() as $gateway ) {
			if ( ! is_object( $gateway ) ) {
				continue;
			}

			$gateway_id = '';
			if ( isset( $gateway->id ) && is_scalar( $gateway->id ) ) {
				$gateway_id = $this->normalize_id( (string) $gateway->id );
			}

			$gateway_class_id = $this->normalize_id( get_class( $gateway ) );
			if ( in_array( $section_id, array( $gateway_id, $gateway_class_id ), true ) ) {
				return true;
			}
		}
	} catch ( \Throwable $e ) {
		wc_get_logger()->debug(
			sprintf(
				'Payment gateway section ids could not be checked while registering settings section "%1$s/%2$s": %3$s: %4$s',
				$parent_page_id,
				$section_id,
				get_class( $e ),
				$e->getMessage()
			),
			array( 'source' => 'settings-ui' )
		);

		if ( $e instanceof \Exception ) {
			wc_caught_exception( $e, __CLASS__ . '::' . __FUNCTION__ );
		}
	}

	return false;
}