How to save recurring tracking updates in json format in wordpress database

Viewed 10

I want to save tracking updates in wordpress db. I want whenever there is a new tracking it will append with previous tracking. I want to save in wpdb as json format. Here is the code

// GET PREVIOUS TRACKING
$get_tracking_row = $wpdb->get_row( "SELECT * FROM courier_logs WHERE courier_tracking = $tracking " );
$get_courier_finance = $get_tracking_row->courier_finance;
$decoded_courier_finance = json_decode($get_courier_finance, false) ;

// CREATE NEW TRACKING
$finance_array = array(
    "order" => $order,
    "courier" => $courier,
    "tracking" => $tracking,
    "status" => $status,
    "cod" => $cod,
    "fee" => $fee
);

// ENCODE IN JSON
$dvs_courier_finance = json_encode($finance_array);

// SAVE IN WPDB
$dbData = array();
$dbData['courier_finance'] = $dvs_courier_finance;
$wpdb->update('courier_logs', $dbData, array('courier_tracking' => $tracking));

I am also enable to get the previous tracking but The issue is it will only save latest tracking in db and didnot append the old tracking. I am stuck here please help.

0 Answers
Related