| 1 |
<?php |
| 2 |
if (!function_exists('yatra_get_discount_deals_lists')) { |
| 3 |
|
| 4 |
function yatra_get_discount_deals_lists($atts = array()) |
| 5 |
{ |
| 6 |
$order = isset($atts['order']) ? sanitize_text_field($atts['order']) : 'DESC'; |
| 7 |
$order = in_array(strtolower($order), array('asc', 'desc')) ? $order : 'desc'; |
| 8 |
$args = array( |
| 9 |
'meta_query' => array( |
| 10 |
array( |
| 11 |
'key' => 'yatra_tour_meta_sales_price', |
| 12 |
'value' => array('', 0, '0'), |
| 13 |
'compare' => 'NOT IN' |
| 14 |
) |
| 15 |
), |
| 16 |
'post_type' => 'tour', |
| 17 |
'order' => $order, |
| 18 |
'posts_per_page' => 9 |
| 19 |
); |
| 20 |
$posts = get_posts($args); |
| 21 |
|
| 22 |
echo '<div class="yatra-discount-deals-wrap yatra-col-3">'; |
| 23 |
|
| 24 |
foreach ($posts as $item) { |
| 25 |
|
| 26 |
$data['data'] = array( |
| 27 |
'id' => $item->ID, |
| 28 |
'title' => $item->post_title, |
| 29 |
'excerpt' => $item->post_excerpt, |
| 30 |
'permalink' => get_permalink($item->ID), |
| 31 |
'image' => '' |
| 32 |
); |
| 33 |
|
| 34 |
$attachment_id = (int)get_post_thumbnail_id($item); |
| 35 |
|
| 36 |
if (($attachment_id) > 0) { |
| 37 |
|
| 38 |
$attachment_link = wp_get_attachment_image_url($attachment_id, 'full'); |
| 39 |
|
| 40 |
$data['data']['image'] = $attachment_link; |
| 41 |
} |
| 42 |
|
| 43 |
yatra_get_template('tmpl-deals-item.php', $data); |
| 44 |
|
| 45 |
} |
| 46 |
echo '</div>'; |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
if (!function_exists('yatra_get_tour_lists')) { |
| 53 |
|
| 54 |
function yatra_get_tour_lists($atts = array()) |
| 55 |
{ |
| 56 |
$order = isset($atts['order']) ? sanitize_text_field($atts['order']) : 'DESC'; |
| 57 |
|
| 58 |
$order = in_array(strtolower($order), array('asc', 'desc')) ? $order : 'desc'; |
| 59 |
|
| 60 |
$featured = isset($atts['featured']) ? absint($atts['featured']) : 2; |
| 61 |
|
| 62 |
$posts_per_page = isset($atts['posts_per_page']) ? absint($atts['posts_per_page']) : 9; |
| 63 |
|
| 64 |
$meta_query = array(); |
| 65 |
|
| 66 |
|
| 67 |
switch ($featured) { |
| 68 |
|
| 69 |
case 0: |
| 70 |
$meta_query[] = |
| 71 |
|
| 72 |
array( |
| 73 |
'relation' => 'OR', |
| 74 |
array( |
| 75 |
'key' => 'yatra_tour_meta_tour_featured', |
| 76 |
'value' => array(1, '1'), |
| 77 |
'compare' => 'NOT IN' |
| 78 |
), |
| 79 |
array( |
| 80 |
'key' => 'yatra_tour_meta_tour_featured', |
| 81 |
'compare' => 'NOT EXISTS', |
| 82 |
'value' => 'null', |
| 83 |
) |
| 84 |
); |
| 85 |
break; |
| 86 |
|
| 87 |
case 1: |
| 88 |
$meta_query[] = |
| 89 |
array( |
| 90 |
'key' => 'yatra_tour_meta_tour_featured', |
| 91 |
'value' => array(1, '1'), |
| 92 |
'compare' => 'IN' |
| 93 |
|
| 94 |
); |
| 95 |
break; |
| 96 |
} |
| 97 |
|
| 98 |
$args = array( |
| 99 |
'post_type' => 'tour', |
| 100 |
'order' => $order, |
| 101 |
'posts_per_page' => $posts_per_page |
| 102 |
); |
| 103 |
|
| 104 |
if (count($meta_query) > 0) { |
| 105 |
$args['meta_query'] = $meta_query; |
| 106 |
} |
| 107 |
|
| 108 |
$posts = get_posts($args); |
| 109 |
|
| 110 |
echo '<div class="yatra-tour-list-wrap yatra-col-3">'; |
| 111 |
|
| 112 |
foreach ($posts as $item) { |
| 113 |
|
| 114 |
$data['data'] = array( |
| 115 |
'id' => $item->ID, |
| 116 |
'title' => $item->post_title, |
| 117 |
'excerpt' => $item->post_excerpt, |
| 118 |
'permalink' => get_permalink($item->ID), |
| 119 |
'image' => '' |
| 120 |
); |
| 121 |
|
| 122 |
$attachment_id = (int)get_post_thumbnail_id($item); |
| 123 |
|
| 124 |
if (($attachment_id) > 0) { |
| 125 |
|
| 126 |
$attachment_link = wp_get_attachment_image_url($attachment_id, 'full'); |
| 127 |
|
| 128 |
$data['data']['image'] = $attachment_link; |
| 129 |
} |
| 130 |
|
| 131 |
yatra_get_template('tmpl-tour-item.php', $data); |
| 132 |
|
| 133 |
} |
| 134 |
echo '</div>'; |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
} |
| 139 |
if (!function_exists('yatra_booking_pricing_details')) { |
| 140 |
function yatra_booking_pricing_details($tour_id = null) |
| 141 |
{ |
| 142 |
global $post; |
| 143 |
|
| 144 |
if (is_null($tour_id)) { |
| 145 |
$tour_id = isset($post->ID) ? $post->ID : ''; |
| 146 |
} |
| 147 |
if ($tour_id == '' || is_null($tour_id)) { |
| 148 |
return array(); |
| 149 |
} |
| 150 |
$yatra_tour_meta_regular_price = get_post_meta($tour_id, 'yatra_tour_meta_regular_price', true); |
| 151 |
$yatra_tour_meta_sales_price = get_post_meta($tour_id, 'yatra_tour_meta_sales_price', true); |
| 152 |
$yatra_multiple_pricing = get_post_meta($tour_id, 'yatra_multiple_pricing', true); |
| 153 |
$yatra_tour_meta_price_per = get_post_meta($tour_id, 'yatra_tour_meta_price_per', true); |
| 154 |
$yatra_tour_meta_group_size = get_post_meta($tour_id, 'yatra_tour_meta_group_size', true); |
| 155 |
$pricing_details = array(); |
| 156 |
if (is_array($yatra_multiple_pricing)) { |
| 157 |
if (count($yatra_multiple_pricing) > 0) { |
| 158 |
foreach ($yatra_multiple_pricing as $pricing_id => $pricing) { |
| 159 |
$sales_price = $pricing['sales_price']; |
| 160 |
$regular_price = $pricing['regular_price']; |
| 161 |
$pricing_details[$pricing_id] = array( |
| 162 |
'name' => 'yatra_number_of_person[multi_pricing][' . $pricing_id . ']', |
| 163 |
'pricing_label' => $pricing['pricing_label'], |
| 164 |
'regular_price' => $regular_price, |
| 165 |
'sales_price' => $sales_price, |
| 166 |
'pricing_per' => $yatra_tour_meta_price_per, |
| 167 |
'group_size' => $yatra_tour_meta_group_size, |
| 168 |
); |
| 169 |
} |
| 170 |
return $pricing_details; |
| 171 |
} |
| 172 |
} |
| 173 |
$regular_price = $yatra_tour_meta_regular_price; |
| 174 |
$sales_price = $yatra_tour_meta_sales_price; |
| 175 |
$pricing_details[] = array( |
| 176 |
'name' => 'yatra_number_of_person[single_pricing]', |
| 177 |
'pricing_label' => 'Person', |
| 178 |
'regular_price' => $regular_price, |
| 179 |
'sales_price' => $sales_price, |
| 180 |
'pricing_per' => $yatra_tour_meta_price_per, |
| 181 |
'group_size' => $yatra_tour_meta_group_size, |
| 182 |
); |
| 183 |
return $pricing_details; |
| 184 |
|
| 185 |
} |
| 186 |
} |
| 187 |
if (!function_exists('yatra_cart_pricing_details')) { |
| 188 |
function yatra_cart_pricing_details($tour_id, $cart_items) |
| 189 |
{ |
| 190 |
$booking_pricing_details = yatra_booking_pricing_details($tour_id); |
| 191 |
|
| 192 |
$updated_booking_details = array(); |
| 193 |
|
| 194 |
$pricing_type = isset($cart_items['pricing_type']) ? $cart_items['pricing_type'] : 'single'; |
| 195 |
$number_of_person = isset($cart_items['number_of_person']) ? $cart_items['number_of_person'] : ''; |
| 196 |
|
| 197 |
switch ($pricing_type) { |
| 198 |
case "multi": |
| 199 |
foreach ($booking_pricing_details as $pricing_id => $pricing_detail) { |
| 200 |
$updated_booking_details[$pricing_id] = $pricing_detail; |
| 201 |
$price_per = isset($pricing_detail['pricing_per']) ? $pricing_detail['pricing_per'] : 'single'; |
| 202 |
$group_size = isset($pricing_detail['group_size']) ? $pricing_detail['group_size'] : 1; |
| 203 |
$person_count = is_array($number_of_person) && isset($number_of_person[$pricing_id]) ? (absint($number_of_person[$pricing_id])) : 0; |
| 204 |
$updated_booking_details[$pricing_id]['number_of_person'] = $person_count; |
| 205 |
$person_count = $price_per == 'person' ? $person_count : ceil($person_count / $group_size); |
| 206 |
$regular_price = isset($pricing_detail['regular_price']) ? absint($pricing_detail['regular_price']) : 0; |
| 207 |
$sales_price = isset($pricing_detail['sales_price']) ? absint($pricing_detail['sales_price']) : 0; |
| 208 |
$sales_price = isset($pricing_detail['sales_price']) && '' != $pricing_detail['sales_price'] ? $sales_price : $regular_price; |
| 209 |
$updated_booking_details[$pricing_id]['total'] = ($sales_price * $person_count); |
| 210 |
$updated_booking_details[$pricing_id]['name'] = 'yatra_number_of_person[' . $tour_id . '][multi_pricing][' . $pricing_id . ']'; |
| 211 |
} |
| 212 |
break; |
| 213 |
case "single": |
| 214 |
$sales_price = isset($booking_pricing_details[0]['sales_price']) && '' != $booking_pricing_details[0]['sales_price'] ? $booking_pricing_details[0]['sales_price'] : $booking_pricing_details[0]['regular_price']; |
| 215 |
$price_per = isset($booking_pricing_details[0]['pricing_per']) ? $booking_pricing_details[0]['pricing_per'] : 'single'; |
| 216 |
$group_size = isset($booking_pricing_details[0]['group_size']) ? $booking_pricing_details[0]['group_size'] : 1; |
| 217 |
$person_count = !is_array($number_of_person) ? (absint($number_of_person)) : 0; |
| 218 |
$booking_pricing_details[0]['number_of_person'] = $person_count; |
| 219 |
$person_count = $price_per == 'person' ? $person_count : ceil($person_count / $group_size); |
| 220 |
$booking_pricing_details[0]['total'] = $person_count * $sales_price; |
| 221 |
$booking_pricing_details[0]['name'] = 'yatra_number_of_person[' . $tour_id . '][single_pricing]'; |
| 222 |
$updated_booking_details = $booking_pricing_details; |
| 223 |
|
| 224 |
|
| 225 |
break; |
| 226 |
} |
| 227 |
return $updated_booking_details; |
| 228 |
|
| 229 |
|
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
function yatra_export($args = array()) |
| 234 |
{ |
| 235 |
$defaults = array( |
| 236 |
|
| 237 |
'content' => array(), |
| 238 |
|
| 239 |
); |
| 240 |
|
| 241 |
$args = wp_parse_args($args, $defaults); |
| 242 |
|
| 243 |
do_action('export_yatra', $args); |
| 244 |
|
| 245 |
$sitename = strtolower(sanitize_key(get_bloginfo('name'))); |
| 246 |
|
| 247 |
if (!empty($sitename)) { |
| 248 |
|
| 249 |
$sitename .= '.'; |
| 250 |
} |
| 251 |
|
| 252 |
$content = $args['content']; |
| 253 |
|
| 254 |
$content = is_string($content) ? $content : json_encode($content); |
| 255 |
|
| 256 |
$date = gmdate('Y-m-d'); |
| 257 |
|
| 258 |
$wp_filename = $sitename . 'yatra.' . $date . '.json'; |
| 259 |
|
| 260 |
$filename = apply_filters('export_wp_filename', $wp_filename, $sitename, $date); |
| 261 |
|
| 262 |
header('Content-Description: File Transfer'); |
| 263 |
|
| 264 |
header('Content-Disposition: attachment; filename=' . $filename); |
| 265 |
|
| 266 |
header('Content-Type: text/json; charset=' . get_option('blog_charset'), true); |
| 267 |
|
| 268 |
echo $content; |
| 269 |
|
| 270 |
exit; |
| 271 |
|
| 272 |
} |
| 273 |
|