Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::is_offline_group_last
Check if the offline payment methods group is the last non-offline entry in an order map.
This is used to detect whether the merchant has customized the provider ordering. If the offline group is still at the bottom (its default position), new gateways should be inserted above it. If the merchant has moved it, we respect their layout and append new gateways at the end.
Method of the class: PaymentsProviders{}
No Hooks.
Returns
true|false. True if the offline group is the last non-offline entry, false otherwise.
Usage
$PaymentsProviders = new PaymentsProviders(); $PaymentsProviders->is_offline_group_last( $order_map ): bool;
- $order_map(array) (required)
- The payment providers order map.
PaymentsProviders::is_offline_group_last() PaymentsProviders::is offline group last code WC 10.7.0
public function is_offline_group_last( array $order_map ): bool {
if ( ! isset( $order_map[ self::OFFLINE_METHODS_ORDERING_GROUP ] ) ) {
return false;
}
$offline_group_order = $order_map[ self::OFFLINE_METHODS_ORDERING_GROUP ];
// Check if any non-offline, non-suggestion entry has an order higher than the offline group.
foreach ( $order_map as $id => $order ) {
if ( self::OFFLINE_METHODS_ORDERING_GROUP === $id ) {
continue;
}
if ( $this->is_offline_payment_method( $id ) ) {
continue;
}
if ( $this->is_suggestion_order_map_id( $id ) ) {
continue;
}
if ( $order > $offline_group_order ) {
return false;
}
}
return true;
}