P
P
PaySeq2020-06-11 18:32:12
PHP
PaySeq, 2020-06-11 18:32:12

How to get POST-REQUEST response in JSON format and change order details in WooCommerce?

There is the following code:

function check_ipn_response(){
global $woocommerce;
if (isset($_GET['dastavista']) AND $_GET['dastavista'] == 'success'){
//Получаем принятые данные в формате JSON
$jsone = json_decode(file_get_contents("php://input"), true);

//Проверяем имеются ли какие либо данные
if(isset($jsone)){
//Извлекаем статус транзакции из JSON
$order_status = $jsone->status;
//Извлекаем ID заказа из JSON
$order_info = $jsone->OrderId;
//Извлекаем Номер телефона клиента из JSON
$customer_info = $jsone->ClientPhone;

//Выполняем события (тут получается только одно статус заказа меняется на - выполнено)
$update_order_id = (int)$order_info;
$order_object = wc_get_order($update_order_id);
$order_object->update_status('completed');
WC()->cart->empty_cart();
wp_redirect( $this->get_return_url( $order ) );
}
}
}

1) Am I accepting a JSON POST request from another server correctly?
2) How, after receiving a json response from the partner's server, not only change the status of the order, but also change the order data, i.e. change the client's phone number in the order (WooCommerce platform)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Dagaev, 2020-06-12
@sodope_69

If you accept POST then why in the $_GET condition?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question