Avoid fatal in `wc_get_chosen_shipping_method_ids` (#50774)
This ensures the WC() session object is initialized before attempting to get chosen shipping methods. If it's not initialized, `wc_get_chosen_shipping_method_ids` will return an empty array. Fixes #50283
This commit is contained in:
parent
0322426dce
commit
b430971093
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Ensure session object is initialized before attempting to get chosen shipping methods
|
|
@ -413,7 +413,12 @@ function wc_cart_round_discount( $value, $precision ) {
|
|||
*/
|
||||
function wc_get_chosen_shipping_method_ids() {
|
||||
$method_ids = array();
|
||||
$chosen_methods = WC()->session->get( 'chosen_shipping_methods', array() );
|
||||
$chosen_methods = array();
|
||||
|
||||
if ( is_callable( array( WC()->session, 'get' ) ) ) {
|
||||
$chosen_methods = WC()->session->get( 'chosen_shipping_methods', array() );
|
||||
}
|
||||
|
||||
foreach ( $chosen_methods as $chosen_method ) {
|
||||
if ( ! is_string( $chosen_method ) ) {
|
||||
continue;
|
||||
|
@ -421,6 +426,7 @@ function wc_get_chosen_shipping_method_ids() {
|
|||
$chosen_method = explode( ':', $chosen_method );
|
||||
$method_ids[] = current( $chosen_method );
|
||||
}
|
||||
|
||||
return $method_ids;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue