WC_Shipping_Zones::add_zone_order_conflict_warnings
Add warnings to zones that are fully covered by a higher-priority zone.
Method of the class: WC_Shipping_Zones{}
No Hooks.
Returns
array. Shipping zones with order conflict warnings.
Usage
$result = WC_Shipping_Zones::add_zone_order_conflict_warnings( $zones );
- $zones(array) (required)
- Shipping zones.
Changelog
| Since 11.1.0 | Introduced. |
WC_Shipping_Zones::add_zone_order_conflict_warnings() WC Shipping Zones::add zone order conflict warnings code WC 11.1.2
private static function add_zone_order_conflict_warnings( $zones ) {
$ordered_zones = $zones;
$higher_priority_zones = array();
uasort(
$ordered_zones,
function ( $zone_a, $zone_b ) {
$order_a = absint( $zone_a['zone_order'] ?? 0 );
$order_b = absint( $zone_b['zone_order'] ?? 0 );
if ( $order_a === $order_b ) {
return absint( $zone_a['zone_id'] ?? 0 ) <=> absint( $zone_b['zone_id'] ?? 0 );
}
return $order_a <=> $order_b;
}
);
foreach ( $ordered_zones as $zone ) {
$shadowing_zone = self::get_shadowing_zone( $zone, $higher_priority_zones );
if ( $shadowing_zone ) {
$zones[ $zone['zone_id'] ]['zone_order_conflict_warning'] = sprintf(
/* translators: %1$s: Higher-priority shipping zone name. */
__( 'This zone will not be matched because "%1$s" covers the same region earlier in the list. Move this zone above "%1$s" to make it available.', 'woocommerce' ),
$shadowing_zone['zone_name']
);
}
$higher_priority_zones[] = $zone;
}
return $zones;
}