<?php
$method_filters = [
'exists' => [
'full pallet' => [
171 => [
'pakkelabels_shipping_gls_private',
'pakkelabels_shipping_postnord_private',
'pakkelabels_shipping_gls',
'pakkelabels_shipping_pdk',
'flat_rate:15',
'flat_rate:14'
],
],
'half pallet' => [
169 => [
'pakkelabels_shipping_gls_private',
'pakkelabels_shipping_postnord_private',
'pakkelabels_shipping_gls',
'pakkelabels_shipping_pdk',
'flat_rate:15'
],
],
'quarter pallet' => [
211 => [
'pakkelabels_shipping_gls_private',
'pakkelabels_shipping_postnord_private',
'pakkelabels_shipping_gls',
'pakkelabels_shipping_pdk'
],
]
],
'not exists' => [
'full pallet' => [
171 => [
'flat_rate:12'
]
],
'half pallet' => [
169 => [
'flat_rate:14'
]
],
'quarter pallet' => [
211 => [
'flat_rate:15'
]
]
]
];
$class_ids[170] = '';
$class_ids[171] = '';
$available_shipping_methods['flat_rate:12'] = 'something';
$available_shipping_methods['flat_rate:14'] = 'somethingelse';
foreach ($method_filters as $filter_type => $pallet_filters) { // iterate exists/not exists level
foreach ($pallet_filters as $pallet_type => $shipping_methods) { // iterate different pallets level
if ($filter_type == 'exists') {
$qualifiers = array_intersect_key($shipping_methods, $class_ids);
} else {
$qualifiers = array_diff_key($shipping_methods, $class_ids);
}
foreach ($qualifiers as $class_id => $method_names) { // only iterate if there are qualifying class ids
foreach ($method_names as $method_name) {
echo "unsetting $method_name\n";
unset($available_shipping_methods[$method_name]);
}
}
}
}
var_export($available_shipping_methods);
- Output for 7.1.25 - 7.1.27, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- unsetting pakkelabels_shipping_gls_private
unsetting pakkelabels_shipping_postnord_private
unsetting pakkelabels_shipping_gls
unsetting pakkelabels_shipping_pdk
unsetting flat_rate:15
unsetting flat_rate:14
unsetting flat_rate:14
unsetting flat_rate:15
array (
'flat_rate:12' => 'something',
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
unsetting pakkelabels_shipping_gls_private
unsetting pakkelabels_shipping_postnord_private
unsetting pakkelabels_shipping_gls
unsetting pakkelabels_shipping_pdk
unsetting flat_rate:15
unsetting flat_rate:14
unsetting flat_rate:14
unsetting flat_rate:15
array (
'flat_rate:12' => 'something',
)
preferences:
175.7 ms | 402 KiB | 160 Q