Here’s the code that works.
$options = [
'title' => $this->name,
'options' => [
[
'id' => 'home_delivery',
'icon' => $this->settings['icon'],
'name' => 'Delivery Fee',
'description' => 'weight:'.$weight,
'fields' => $note,
'cost' => $price1,
'tax_class_id' => $this->settings['tax_class_id'],
],
[
'id' => 'option_2',
'icon' => $this->settings['icon'],
'name' => $cparray[0],
'description' => 'This is the description for option 2',
'fields' => '',
'cost' => $price2,
'tax_class_id' => $this->settings['tax_class_id'],
],
],
];
The number of different options (different id’s) varies, so I just want to add another id with its variables afterwards, like maybe add this if there’s a 3rd option:
[
'id' => 'option_3',
'icon' => $this->settings['icon'],
'name' => $cparray[1],
'description' => 'This is the description for option 3',
'fields' => '',
'cost' => $price3,
'tax_class_id' => $this->settings['tax_class_id'],
],
I’m thinking something like this afterwards, but it’s not quite right:
$options['options'] += ['id' => 'option_3','icon' => $this->settings['icon'],'name' => $cparray[4],'description' => 'This is the description for option 3','fields' => '','cost' => $price2,'tax_class_id' => $this->settings['tax_class_id'],];
I’m finding several options of adding to an array. I’m obviously not doing something right because I don’t fully understand the array construction being made originally. I think it’s creating an array 2 levels deep and I need to add an element to the inner one.