Loop through each package to check if the chosen rate for it is valid (#47716)

* Loop through each package to check if the chosen rate for it is valid

* Add changelog
This commit is contained in:
Thomas Roberts 2024-05-22 20:55:31 +01:00 committed by GitHub
parent 5e6bce3334
commit e6bd07d465
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Check each pacakge's chosen shipping rate against each valid rate for that package

View File

@ -556,14 +556,20 @@ class OrderController {
throw $exception;
}
$valid_methods = array_keys( WC()->shipping()->get_shipping_methods() );
$packages = WC()->shipping()->get_packages();
foreach ( $packages as $package_id => $package ) {
$chosen_rate_for_package = wc_get_chosen_shipping_method_for_package( $package_id, $package );
$valid_rate_ids_for_package = array_map(
function ( $rate ) {
return $rate->id;
},
$package['rates']
);
foreach ( $chosen_shipping_methods as $chosen_shipping_method ) {
if (
false === $chosen_shipping_method ||
! is_string( $chosen_shipping_method ) ||
! ArrayUtils::string_contains_array( $chosen_shipping_method, $valid_methods )
) {
false === $chosen_rate_for_package ||
! is_string( $chosen_rate_for_package ) ||
! ArrayUtils::string_contains_array( $chosen_rate_for_package, $valid_rate_ids_for_package ) ) {
throw $exception;
}
}