function ajax_price()
{
$product_id = $_GET['product_id'];
$weight = $_GET['weight'];
$gold_price_karats = get_post_meta($product_id, 'gold_price_karats', true);
$extra_fee = get_post_meta($product_id, 'gold_price_product_fee', true);
$extra_fee = empty($extra_fee) ? 0 : $extra_fee;
$latest_id = get_latest_id_from_gold_table();
$record_last = get_gold_record_by_id($latest_id);
if ($record_last) {
$weight = empty($weight) ? 1 : $weight;
$id = $record_last['id'];
$price_gram_24k = $record_last['price_gram_24k'] * $weight + $extra_fee;
$price_gram_22k = $record_last['price_gram_22k'] * $weight + $extra_fee;
$price_gram_21k = $record_last['price_gram_21k'] * $weight + $extra_fee;
$price_gram_20k = $record_last['price_gram_20k'] * $weight + $extra_fee;
$price_gram_18k = $record_last['price_gram_18k'] * $weight + $extra_fee;
$price_gram_16k = $record_last['price_gram_16k'] * $weight + $extra_fee;
$price_gram_14k = $record_last['price_gram_14k'] * $weight + $extra_fee;
$price_gram_10k = $record_last['price_gram_10k'] * $weight + $extra_fee;
$timestamp = $record_last['timestamp'];
$gold_price_karats = get_post_meta($product_id, 'gold_price_karats', true);
}
if ($gold_price_karats == "14k") {
$response = array('price' => $price_gram_14k);
wp_send_json_success($response);
echo $price_gram_14k;
// update_post_meta($product_id, 'custom_price_field', $price_gram_14k);
} elseif ($gold_price_karats == "18k") {
$response = array('price' => $price_gram_18k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "22k") {
$response = array('price' => $price_gram_22k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "24k") {
$response = array('price' => $price_gram_24k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "21k") {
$response = array('price' => $price_gram_21k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "20k") {
$response = array('price' => $price_gram_20k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "18k") {
$response = array('price' => $price_gram_18k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "16k") {
$response = array('price' => $price_gram_16k . " " . "ريال");
wp_send_json_success($response);
} elseif ($gold_price_karats == "10k") {
$response = array('price' => $price_gram_10k . " " . "ريال");
wp_send_json_success($response);
}else{
$response = array('price' => 0 . " " . "ريال");
wp_send_json_success($response);
}
wp_die(); // Always use wp_die() after echoing the response.
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter