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:
parent
25fae0cc27
commit
fc31f0c77d
|
@ -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`.
|
|
@ -16,7 +16,7 @@ class ArrayUtils {
|
|||
public static function natural_language_join( $array, $enclose_items_with_quotes = false ) {
|
||||
if ( true === $enclose_items_with_quotes ) {
|
||||
$array = array_map(
|
||||
function( $item ) {
|
||||
function ( $item ) {
|
||||
return '"' . $item . '"';
|
||||
},
|
||||
$array
|
||||
|
@ -33,4 +33,21 @@ class ArrayUtils {
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -562,7 +562,7 @@ class OrderController {
|
|||
if (
|
||||
false === $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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue