Мне нужно чтоб при каждом клике и успешной отправке на сервер, для записей с выбранным id (id получаем при клике) в метаполе pole_booked_product передавалось значение "1". Это метаполе есть в каждой записи. Так не работает
jQuery(document).ready(function() {
jQuery(".submit").on("click", function (event) {
event.preventDefault();
if (jQuery(".block-border").hasClass("active")) {
var name = jQuery('.form-name').val();
var last_name = jQuery('.form-last_name').val();
var form_phone = jQuery('.form-phone').val();
var form_country = jQuery('.form-country').val();
var form_city = jQuery('.form-city').val();
var form_street = jQuery('.form-street').val();
var form_message = jQuery('.form-message').val();
var form_num = jQuery('.form-num').val();
var form_weight1 = jQuery('.form-weight1').val();
var form_weight2 = jQuery('.form-weight2').val();
var form_num2 = jQuery('.form-num2').val();
var form_weight3 = jQuery('.form-weight3').val();
var form_weight4 = jQuery('.form-weight4').val();
var ids = 'post_id_' + jQuery.map(jQuery('.block-border.active'), function(a) {
return jQuery(a).find('.hidd').attr('id')
}).join(', post_id_');
jQuery.ajax({
context: document.body,
url: "/wp-admin/admin-ajax.php",
method: 'post',
data: {
action: 'ajax_order',
name: name,
last_name: last_name,
phone: form_phone,
country: form_country,
city: form_city,
street: form_street,
message: form_message,
form_num: form_num,
form_weight1: form_weight1,
form_weight2: form_weight2,
form_num2: form_num2,
form_weight3: form_weight3,
form_weight4: form_weight4,
//post_id: jQuery('.block-border.active').find('.hidd').attr('id'),
post_id:ids,
meta_val: 1
},
function(date) {
jQuery('.block-border').hasClass("active").find('.hidd').text(date);
},
success: function (response) {
jQuery("#sendform").html('<p class="thank" style="text-align: center;margin-bottom: 0px;">Заказ забронирован!<p>');
}
});
};
});
});
<?php function total_form(){
$name = $_REQUEST['name'];
$last_name = $_REQUEST['last_name'];
$phone = $_REQUEST['phone'];
$country = $_REQUEST['country'];
$city = $_REQUEST['city'];
$street = $_REQUEST['street'];
$message = $_REQUEST['message'];
$form_num = $_REQUEST['form_num'];
$form_weight1 = $_REQUEST['form_weight1'];
$form_weight2 = $_REQUEST['form_weight2'];
$form_num2 = $_REQUEST['form_num2'];
$form_weight3 = $_REQUEST['form_weight3'];
$form_weight4 = $_REQUEST['form_weight4'];
$metaVal = $_POST['meta_val'];
//$post_id = $_POST['post_id'];
$post_id = json_decode($_POST['post_id'], 1); //массив id
//$action = 'post_id_' . $post_id;
$action = 'post_id_' . implode(', post_id_', json_decode($_POST['post_id'], 1));
update_post_meta($post_id, 'pole_booked_product', $metaVal);
//echo get_post_meta($post_id, 'pole_booked_product', true);
$response = '';
$thm = 'Заказ звонка';
$thm = "=?utf-8?b?". base64_encode($thm) ."?=";
$msg = "Имя: ".$name."<br/>
Фамилия: ".$last_name ."<br/>
Телефон: ".$phone ."<br/>
Страна: ".$country ."<br/>
Город: ".$city ."<br/>
Улица: ".$street ."<br/>
Сообщение: ".$message ."<br/>
№ HELIX ASPERSA MULLER: ".$form_num ."<br/>
1 класс HELIX ASPERSA MULLER: ".$form_weight1 ."<br/>
2 класс HELIX ASPERSA MULLER: ".$form_weight2 ."<br/>
№ HELIX ASPERSA MAXIMA: ".$form_num2 ."<br/>
1 класс HELIX ASPERSA MAXIMA: ".$form_weight3 ."<br/>
2 класс HELIX ASPERSA MAXIMA: ".$form_weight4 ."<br/>
";
$mail_to = 'juliaradionova1991@gmail.com';
$headers = "Content-Type: text/html; charset=utf-8\n";
//$headers .= 'From: test@gmail.com' . "\r\n";
// Отправляем почтовое сообщение
if(mail($mail_to, $thm, $msg, $headers)){
$response = 'Сообщение отправлено';
}else
$response = 'Ошибка при отправке';
// Сообщение о результате отправки почты
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ){
echo $response;
wp_die();
}
}
add_action('wp_ajax_nopriv_ajax_order', 'total_form' );
add_action('wp_ajax_ajax_order', 'total_form' ); ?>