Jump to content

reset() expects parameter 1 to be array, null given

Recommended Posts


Am hoping someone can please help.

I've the following code:

$chosen_methods    = WC()->session->get( 'chosen_shipping_methods' ); 
$chosen_method     = explode(':', reset($chosen_methods) );

The first line returns the warning:
"Warning: reset() expects parameter 1 to be array, null given in"

I've tried the following:

$chosen_method     = '';
$chosen_method     = NULL;
$chosen_methods     = array();

Sadly, none have worked. What am I missing?


Link to post
Share on other sites
$chosen_methods    = WC()->session->get( 'chosen_shipping_methods' );

Apparently there is no "chosen_shipping_methods" value in the session. You need to provide a default - an array of shipping method values to use when that session value isn't present.

Guessing based on the code, you can do so with

$chosen_methods    = WC()->session->get( 'chosen_shipping_methods' ) ?? ['suitable:set:of:values'];


  • Great Answer 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.