Be less aggressive on selected shipping rate logic for Checkout block (#46719)

* be less aggressive on selected shipping rate logic

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Seghir Nadir 2024-04-23 13:03:46 +02:00 committed by GitHub
parent 25fae0cc27
commit fc31f0c77d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Be less aggressive when checking for selected shipping rates in Store API. Reminder that shipping rate id should be on the shape of `method_id:instance_id`.

View File

@ -33,4 +33,21 @@ class ArrayUtils {
} }
return $last; return $last;
} }
/**
* Check if a string contains any of the items in an array.
*
* @param string $needle The string to check.
* @param array $haystack The array of items to check for.
*
* @return bool true if the string contains any of the items in the array, false otherwise.
*/
public static function string_contains_array( $needle, $haystack ) {
foreach ( $haystack as $item ) {
if ( false !== strpos( $needle, $item ) ) {
return true;
}
}
return false;
}
} }

View File

@ -562,7 +562,7 @@ class OrderController {
if ( if (
false === $chosen_shipping_method || false === $chosen_shipping_method ||
! is_string( $chosen_shipping_method ) || ! is_string( $chosen_shipping_method ) ||
! in_array( current( explode( ':', $chosen_shipping_method ) ), $valid_methods, true ) ! ArrayUtils::string_contains_array( $chosen_shipping_method, $valid_methods )
) { ) {
throw $exception; throw $exception;
} }