Home » Php » php – Creating multiple metafields with different key showing Error

php – Creating multiple metafields with different key showing Error

Posted by: admin July 12, 2020 Leave a comment

Questions:

I want to Create multiple Meta fields with different key but it displaying me following error:

‘metafield’ => ‘expected Array to be a Hash’,

This is my code:

    $prodcut_variant = array(

    'metafield'=>array(
       array('namespace'=>'orbital_response',
             'key'=>'Os Purchases',
             'value'=>'0',
             'value_type'=>integer,),
       array('namespace'=>'orbital_response',
             'key'=>'Stock Status',
             'value'=>'C',
             'value_type'=>integer,)

));

$request_update = $shopify('POST /admin/products/{#ID}/metafields.json',array(),$prodcut_variant);
How to&Answers:

If you are adding metafields with a new record you can pass an array of metafields. Otherwise you have to create them one at a time at the url ‘/admin/variant/#id/metafields.json

Your value ‘C’ is not an integer. I suspect the quoted ‘0’ won’t go through either. It is likely these that are throwing the first error. Do you mean 0 or 0xC?

Answer:

Remove the comma from key

'value_type'=>integer,),

like as

'value_type'=>integer),