Casper_R
Создатель
- Регистрация
- 2 Май 2007
- Сообщения
- 88
- Реакции
- 33
тогда давай разбираться могу ошибаться, но я склоняюсь к тому, что строка
и содержит ID отеля, к которому будет привязан отзыв. Все выборки в классе CT_Hotel_Order - просто мишура.
Попробуй этот код вместо своего:
если переменная из формы $data['post_id'] и есть ID отеля, к которому привязывается отзыв, то должно сработать
PHP:
$data['post_id'] = $order_data['post_id'];
Попробуй этот код вместо своего:
PHP:
if ( ! function_exists( 'ct_ajax_submit_review' ) ) {
function ct_ajax_submit_review() {
global $wpdb;
$result_json = array( 'success' => 0, 'result' => '', 'title' => '' );
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'post-' . $_POST['post_id'] ) ) {
$result_json['success'] = 0;
$result_json['result'] = esc_html__( 'Sorry, your nonce did not verify.', 'citytours' );
wp_send_json( $result_json );
}
$fields = array( 'post_id', 'booking_no', 'pin_code', 'review_text', 'review_rating' );
//validation
$data = array();
foreach( $fields as $field ) {
$data[$field] = ( isset( $_POST[$field] ) ) ? sanitize_text_field( $_POST[$field] ) : '';
}
// убираем проверку
if ($data['booking_no'] && $data['pin_code']) {
$order = new CT_Hotel_Order($data['booking_no'], $data['pin_code']);
if (!$order_data = $order->get_order_info()) {
$result_json['success'] = 0;
$result_json['result'] = esc_html__('Wrong Booking Number and Pin Code.', 'citytours');
wp_send_json($result_json);
}
if (!is_array($order_data) || $order_data['status'] == 'cancelled') {
$result_json['success'] = 0;
$result_json['title'] = esc_html__('Sorry, You cannot leave a rating.', 'citytours');
$result_json['result'] = esc_html__('You cancelled your booking, so cannot leave a rating.', 'citytours');
wp_send_json($result_json);
}
if ((empty($order_data['date_to']) && ct_strtotime($order_data['date_from']) > ct_strtotime(date("Y-m-d")))
|| (ct_strtotime($order_data['date_to']) > ct_strtotime(date("Y-m-d")))
) {
$result_json['success'] = 0;
$result_json['title'] = esc_html__('Sorry, You cannot leave a rating before travel.', 'citytours');
$result_json['result'] = esc_html__('You can leave a review after travel.', 'citytours');
wp_send_json($result_json);
}
} else {
$order_data = array('post_id'=>$data['post_id'],'first_name'=>'first_name','last_name'=>'last_name','email'=>'email@email.com');
}
$data['post_id'] = $order_data['post_id'];
$data['reviewer_name'] = $order_data['first_name'] . ' ' . $order_data['last_name'];
$data['reviewer_email'] = $order_data['email'];
$data['reviewer_ip'] = $_SERVER['REMOTE_ADDR'];
$data['review_rating_detail'] = serialize( $_POST['review_rating_detail'] );
$data['review_rating'] = array_sum( $_POST['review_rating_detail'] ) / count( $_POST['review_rating_detail'] );
$data['date'] = date( 'Y-m-d H:i:s' );
$data['status'] = 'pending';
if ( is_user_logged_in() ) $data['user_id'] = get_current_user_id();
if ( ! $review_data = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . CT_REVIEWS_TABLE . ' WHERE booking_no=%d AND pin_code=%d', $data['booking_no'], $data['pin_code'] ), ARRAY_A ) ) {
if ( $wpdb->insert( CT_REVIEWS_TABLE, $data ) ) {
$result_json['success'] = 1;
$result_json['title'] = esc_html__( 'Thank you! Your review has been submitted successfully.', 'citytours' );
$result_json['result'] = esc_html__( 'Your review has been submitted.', 'citytours' );
} else {
$result_json['success'] = 0;
$result_json['title'] = esc_html__( 'Sorry, An error occurred while add review.', 'citytours' );
$result_json['result'] = esc_html__( 'Please try again after a while.', 'citytours' );
}
} else {
if ( $wpdb->update( CT_REVIEWS_TABLE, $data, array('booking_no'=>$data['booking_no'], 'pin_code'=>$data['pin_code']) ) ) {
$result_json['success'] = 1;
$result_json['title'] = esc_html__( 'Thank you! Your review has been submitted successfully.', 'citytours' );
$result_json['result'] = esc_html__( 'You can change your review anytime.', 'citytours' );
ct_review_calculate_rating( $data['post_id'] );
} else {
$result_json['success'] = 0;
$result_json['title'] = esc_html__( 'Sorry, An error occurred while add review.', 'citytours' );
$result_json['result'] = esc_html__( 'Please try again after a while.', 'citytours' );
}
}
wp_send_json( $result_json );
}
}
если переменная из формы $data['post_id'] и есть ID отеля, к которому привязывается отзыв, то должно сработать