When I use the backend interface to add an array to the _wc_bookings_pricing
meta_key
I can see it gets saved like so:
a:1:{i:0;a:7:{s:4:"type";s:6:"custom";s:4:"cost";s:1:"5";s:8:"modifier";s:0:"";s:9:"base_cost";s:1:"5";s:13:"base_modifier";s:0:"";s:4:"from";s:10:"2021-10-26";s:2:"to";s:10:"2021-10-27";}}
I've written some code to change update that value from the frontend, but I'm having a hard time getting it to format correctly.
Here's my code (not the form, just the values from the form and the php to update that value)
$type = isset($_POST['input_1']) ? $_POST['input_1'] : null;
$cost = isset($_POST['input_25']) ? $_POST['input_25'] : null;
$modifyer = isset($_POST['input_20']) ? $_POST['input_20'] : null;
$base_cost = isset($_POST['input_24']) ? $_POST['input_24'] : null;
$base_modifyer = isset($_POST['input_20']) ? $_POST['input_20'] : null;
$date_from = isset($_POST['input_2']) ? $_POST['input_2'] : null;
$date_to = isset($_POST['input_3']) ? $_POST['input_3'] : null;
$response = array('type', $type, 'cost', $cost, 'modifyer', $modifyer, 'base_cost', $base_cost, 'base_modifyer', $base_modifyer, 'from', $date_from, 'to', $date_to);
update_field('_wc_booking_pricing', $response, 379);
I'm getting the right cell to update, but it's creating a new iteration for each parameter. This is what I'm getting when I use my front end form:
a:14:{i:0;s:4:"type";i:1;s:6:"custom";i:2;s:4:"cost";i:3;s:1:"5";i:4;s:8:"modifyer";i:5;s:1:"0";i:6;s:9:"base_cost";i:7;s:1:"0";i:8;s:13:"base_modifyer";i:9;s:1:"0";i:10;s:4:"from";i:11;s:10:"2021-10-26";i:12;s:2:"to";i:13;s:10:"2021-10-27";}
So I can see that I'm actually creating 14 iterations instead of just changing the values... not sure how to fix my code though. Any pointers would be greatly appreciated!