L
L
ligisayan2019-04-19 10:09:05
WordPress
ligisayan, 2019-04-19 10:09:05

How to repack an object in json for writing to the database?

Hello!
There is a site on wordpress in which I need to extract information from the database at the price of $totalprice, make the transformations I need with it and update the data in the database.
The data is stored in the json object and I can decode it, but I have a problem with the reverse conversion process.
Can you help?
The code:

global $wpdb;
foreach ( $getcart as $cart_item_key => $cart_item ) {
//извлекаю данные
$reservations = $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$DOPBSPWooCommerce->tables->woocommerce.' WHERE cart_item_key="%s" AND token="%s" AND product_id=%d', $cart_item["key"], $cart_item["dopbsp_token"], $cart_item["product_id"]));
$js = json_decode($reservations[0]->data);
$totalprice = round($js->price_total,2);
}
$totalprice+= 100;

//как поместить $totalprice внутрь $data и закодировать?
//обновить данные
$wpdb->update($DOPBSPWooCommerce->tables->woocommerce, array('data' => $data),
array('cart_item_key' => $cart_item_key, 'token' => $values['dopbsp_token'], 'product_id' => $values['product_id']));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2019-04-19
@ligisayan

$js->pricetotal = $totalprice;
$data = json_encode($js);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question