#[CLOSED] I'm trying to make more than one request in my php code and it's returning the response o

12 messages · Page 1 of 1 (latest)

ancient hornet
#
        $price = isset($order_total['price']) ? $order_total['price'] : null;
        if ($price === '') {
            return ['error' => true, 'message' => 'Order total is not defined or is empty'];
        }
        $response = wp_remote_post('https://api.sellsmart.pro/checkPrice', [
            'method' => 'POST', 
            'headers' => [
                'Content-Type' => 'application/json; charset=utf-8',
                'Cache-Control' => 'no-cache, no-store, must-revalidate',
                'Pragma' => 'no-cache', 
                'Expires' => '0',
            ],
            'body' => json_encode(['order_total' => $order_total]),
            'data_format' => 'body',
        ]);
    
        if (is_wp_error($response)) {
            return ['error' => true, 'message' => $response->get_error_message()];
        } else {
            return json_decode(wp_remote_retrieve_body($response), true);
        }
    }```

So this is my code and it does a request at first when I'm loading the website so the $price variable will equal '' then it will return an error then when another request happens that actually has a price it sends the request to the server with the correct body but it won't give that requests response it will only return the first request response I made sure from my api endpoint and everything.

Please help if you have the required knowledge
feral harbor
ancient hornet
#

It's supposed to do more than one request

#

but when one request happens and then the value returned wont change

#

like even if I do a second one its gonna do the api request

feral harbor
ancient hornet
#

I use this function in the enque_scripts function

ancient hornet
feral harbor
ancient hornet
feral harbor