Order Status Update Process
August 7, 2025 · AI Conversations
We will create a order section in admin area In which we will display ticket status based on 'order_status' attribute that we are already using.
Currently by default status is 0 for new orders and It will set to 1 whenever anyone scan from app
Correct above sentence
—
Below is my understanding of the above:
We will create an order section in the admin area where we will display the ticket status based on the `order_status` attribute, which we are already using.
Currently, the default status is `0` for new orders, and it will be set to `1` whenever someone scans the ticket using the app.
—
Let me know if you'd like it to sound more formal or technical.
add_action('wp_ajax_nopriv_google_reviews_action', 'handle_get_google_reviews');
function handle_get_google_reviews() {
// $reviews = get_stored_google_reviews(4); // Get 4 most recent reviews
// wp_send_json_success($reviews);
$api_key="AIzaSyDM9SOwi3SHRQ4j7KC_1Gge0W8tvY1L2HA";
$place_id="ChIJGxg_mWbvxUcRpgBT7VzAlo8";
$url = "https://maps.googleapis.com/maps/api/place/details/json?place_id=$place_id&key=$api_key";
$response = wp_remote_get($url);
if (is_wp_error($response)) return; // Check for errors in the response
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
update_option('site_google_reviews', $data);
wp_send_json_success($data);
wp_die();
}
is there any fatal error in code
—
### ✅ **Review of your code with comments:**
add_action('wp_ajax_google_reviews_action', 'handle_get_google_reviews');
add_action('wp_ajax_nopriv_google_reviews_action', 'handle_get_google_reviews');
function handle_get_google_reviews() {
$api_key = "AIzaSyDM9SOwi3SHRQ4j7KC_1Gge0W8tvY1L2HA"; // ⚠️ Don't expose real API keys in code
$place_id = "ChIJGxg_mWbvxUcRpgBT7VzAlo8";
$url = "https://maps.googleapis.com/maps/api/place/details/json?place_id=$place_id&key=$api_key";
$response = wp_remote_get($url);
if (is_wp_error($response)) {
wp_send_json_error('Failed to fetch Google reviews.');
wp_die();
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if (!is_array($data)) {
wp_send_json_error('Invalid response from Google API.');
wp_die();
}
update_option('site_google_reviews', $data);
wp_send_json_success($data);
wp_die();
}
—
### ✅ **Safe and Corrected Version Notes:**
1. ✅ `wp_ajax` and `wp_ajax_nopriv` are correctly used for logged-in and non-logged-in users.
2. ✅ `wp_remote_get()` usage is correct.
3. ⚠️ **Error handling for failed request** was missing a response for the client (fixed).
4. ⚠️ **`json_decode`** could return `null` — so a validity check was added.
5. ⚠️ `wp_die()` is a must after `wp_send_json_*` to end the Ajax call — you did it correctly.
6. ⚠️ **API Key Warning:** Avoid pushing your real API key to a public repo or frontend (consider moving it to a constant or settings field).
—
### ✅ No Fatal Error
**There is no fatal error**, but adding `wp_send_json_error()` on failure paths is a best practice so the frontend can handle it gracefully.
Let me know if you want help filtering only the review data from the API response.