$update_options['order']['delivery']['no_delivery'] = $defaultOptions['order']['delivery']['no_delivery']; } /*add delivery charges per item if it does not exist yet (as wppizza_merge_options -> wppizza_traverse_list only looks for first dimansion in array. should maybe be made recursive one day though.....)*/ if (!isset($options['order']['delivery']['per_item'])) { $update_options['order']['delivery']['per_item'] = $defaultOptions['order']['delivery']['per_item']; } if (!isset($options['order']['delivery']['minimum_total']['deliverycharges_below_total'])) { $update_options['order']['delivery']['minimum_total']['deliverycharges_below_total'] = $defaultOptions['order']['delivery']['minimum_total']['deliverycharges_below_total']; } /**************************************************************************** $update_options now holds the old options plus the added new defaults options *****************************************************************************/ /********************************************** [now lets remove obsolete options] ***********************************************/ $removed_options = wppizza_compare_options($options, $defaultOptions); /*get obsolete options**/ /*ini array*/ $arr1_flat = array(); $arr2_flat = array(); /*flatten*/ $arr1_flat = wppizza_flatten($update_options); $arr2_flat = wppizza_flatten($removed_options); /*get difference*/ $ret = array_diff_assoc($arr1_flat, $arr2_flat); /**unflatten->final options**/ $update_options = wppizza_inflate($ret); /****************************************************************************************************** * * $update_options now holds old options plus the added new defaults options minus the removed options *
function wppizza_compare_options($a1, $a2) { $r = array(); if (is_array($a1)) { foreach ($a1 as $k => $v) { if (isset($a2[$k])) { $diff = wppizza_compare_options($a1[$k], $a2[$k]); if (!empty($diff)) { $r[$k] = $diff; } } else { $r[$k] = $v; } } } return $r; }