Automattic\WooCommerce\Internal\Admin\Settings\PaymentProviders

PaymentGateway::sort_recommended_payment_methodsprotectedWC 1.0

Sort the recommended payment methods.

Method of the class: PaymentGateway{}

No Hooks.

Returns

Array. The sorted recommended payment methods list. List keys are not preserved.

Usage

// protected - for code of main (parent) or child class
$result = $this->sort_recommended_payment_methods( $recommended_pms ): array;
$recommended_pms(array) (required)
The recommended payment methods list to sort.

PaymentGateway::sort_recommended_payment_methods() code WC 9.9.4

protected function sort_recommended_payment_methods( array $recommended_pms ): array {
	// Sort the recommended payment methods by order/priority, if available.
	usort(
		$recommended_pms,
		function ( $a, $b ) {
			// `order` takes precedence over `priority`.
			// Entries that don't have the order/priority are placed at the end.
			return array( ( $a['order'] ?? PHP_INT_MAX ), ( $a['priority'] ?? PHP_INT_MAX ) ) <=> array( ( $b['order'] ?? PHP_INT_MAX ), ( $b['priority'] ?? PHP_INT_MAX ) );
		}
	);

	return array_values( $recommended_pms );
}