| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit; |
| 3 |
|
| 4 |
// Load Helpers |
| 5 |
|
| 6 |
include_once YATRA_ABSPATH . 'includes/yatra-html-functions.php'; |
| 7 |
include_once YATRA_ABSPATH . 'includes/helpers/yatra-country-helper.php'; |
| 8 |
include_once YATRA_ABSPATH . 'includes/helpers/yatra-currency-helper.php'; |
| 9 |
include_once YATRA_ABSPATH . 'includes/template-tags.php'; |
| 10 |
include_once YATRA_ABSPATH . 'includes/yatra-destination-functions.php'; |
| 11 |
include_once YATRA_ABSPATH . 'includes/yatra-activity-functions.php'; |
| 12 |
include_once YATRA_ABSPATH . 'includes/yatra-misc-functions.php'; |
| 13 |
|
| 14 |
|
| 15 |
if (!function_exists('yatra_tour_tabs')) { |
| 16 |
function yatra_tour_tabs() |
| 17 |
{ |
| 18 |
$tour_tabs_array = array( |
| 19 |
'options' => array( |
| 20 |
'title' => __('Options', 'yatra'), |
| 21 |
'icon' => '', |
| 22 |
), |
| 23 |
'itinerary' => array( |
| 24 |
'title' => __('Itinerary', 'yatra'), |
| 25 |
'icon' => '', |
| 26 |
), |
| 27 |
'cost_info' => array( |
| 28 |
'title' => __('Cost Info', 'yatra'), |
| 29 |
'icon' => '', |
| 30 |
), |
| 31 |
'facts' => array( |
| 32 |
'title' => __('Facts', 'yatra'), |
| 33 |
'icon' => '', |
| 34 |
), |
| 35 |
'faq' => array( |
| 36 |
'title' => __('FAQ', 'yatra'), |
| 37 |
'icon' => '', |
| 38 |
), |
| 39 |
); |
| 40 |
|
| 41 |
return apply_filters('yatra_tour_tabs', $tour_tabs_array); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
if (!function_exists('yatra_tour_metabox_tabs')) { |
| 46 |
|
| 47 |
function yatra_tour_metabox_tabs() |
| 48 |
{ |
| 49 |
$metabox_tabs = array( |
| 50 |
|
| 51 |
'general' => array( |
| 52 |
'title' => esc_html__('General & Dates', 'yatra'), |
| 53 |
'is_active' => true, |
| 54 |
'settings' => yatra_tour_general_configurations() |
| 55 |
), |
| 56 |
'pricing' => array( |
| 57 |
'title' => esc_html__('Pricing', 'yatra'), |
| 58 |
'settings' => yatra_tour_pricing_configurations() |
| 59 |
), |
| 60 |
|
| 61 |
'attributes' => array( |
| 62 |
'title' => esc_html__('Attributes', 'yatra'), |
| 63 |
'settings' => yatra_tour_attributes() |
| 64 |
), |
| 65 |
'tour_tabs' => array( |
| 66 |
'title' => esc_html__('Tour Tabs', 'yatra'), |
| 67 |
'settings' => yatra_tour_tab_configurations() |
| 68 |
), |
| 69 |
); |
| 70 |
|
| 71 |
return apply_filters('yatra_tour_metabox_tabs', $metabox_tabs); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
if (!function_exists('yatra_set_session')) { |
| 77 |
|
| 78 |
function yatra_set_session($key = '', $value = '') |
| 79 |
{ |
| 80 |
if (!session_id()) { |
| 81 |
session_start(); |
| 82 |
} |
| 83 |
|
| 84 |
$yatra_session_id = "yatra_session"; |
| 85 |
|
| 86 |
if (!empty($key) && !empty($value)) { |
| 87 |
|
| 88 |
$_SESSION[$yatra_session_id][$key] = $value; |
| 89 |
|
| 90 |
return true; |
| 91 |
} |
| 92 |
return false; |
| 93 |
|
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
if (!function_exists('yatra_get_session')) { |
| 98 |
|
| 99 |
function yatra_get_session($key = '') |
| 100 |
{ |
| 101 |
|
| 102 |
$yatra_session_id = "yatra_session"; |
| 103 |
|
| 104 |
if (!empty($key)) { |
| 105 |
|
| 106 |
if (isset($_SESSION[$yatra_session_id][$key])) { |
| 107 |
|
| 108 |
return $_SESSION[$yatra_session_id][$key]; |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
if (isset($_SESSION[$yatra_session_id])) { |
| 113 |
|
| 114 |
return $_SESSION[$yatra_session_id]; |
| 115 |
} |
| 116 |
|
| 117 |
return array(); |
| 118 |
|
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
if (!function_exists('yatra_clear_session')) { |
| 123 |
|
| 124 |
function yatra_clear_session($key = '') |
| 125 |
{ |
| 126 |
if (!session_id()) { |
| 127 |
session_start(); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
$yatra_session_id = "yatra_session"; |
| 132 |
|
| 133 |
if (!empty($key)) { |
| 134 |
|
| 135 |
if (isset($_SESSION[$yatra_session_id][$key])) { |
| 136 |
|
| 137 |
unset($_SESSION[$yatra_session_id][$key]); |
| 138 |
|
| 139 |
return true; |
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
if (isset($_SESSION[$yatra_session_id])) { |
| 144 |
|
| 145 |
unset($_SESSION[$yatra_session_id]); |
| 146 |
|
| 147 |
return true; |
| 148 |
} |
| 149 |
|
| 150 |
return false; |
| 151 |
|
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
if (!function_exists('yatra_get_template')) { |
| 156 |
|
| 157 |
function yatra_get_template($template_name, $args = array(), $template_path = '', $default_path = '') |
| 158 |
{ |
| 159 |
$cache_key = sanitize_key(implode('-', array('template', $template_name, $template_path, $default_path))); |
| 160 |
$template = (string)wp_cache_get($cache_key, 'yatra'); |
| 161 |
|
| 162 |
if (!$template) { |
| 163 |
$template = yatra_locate_template($template_name, $template_path, $default_path); |
| 164 |
wp_cache_set($cache_key, $template, 'yatra'); |
| 165 |
} |
| 166 |
// Allow 3rd party plugin filter template file from their plugin. |
| 167 |
$filter_template = apply_filters('yatra_get_template', $template, $template_name, $args, $template_path, $default_path); |
| 168 |
|
| 169 |
if ($filter_template !== $template) { |
| 170 |
if (!file_exists($filter_template)) { |
| 171 |
/* translators: %s template */ |
| 172 |
_doing_it_wrong(__FUNCTION__, sprintf(__('%s does not exist.', 'yatra'), '<code>' . $template . '</code>'), '1.0.1'); |
| 173 |
return; |
| 174 |
} |
| 175 |
$template = $filter_template; |
| 176 |
} |
| 177 |
|
| 178 |
$action_args = array( |
| 179 |
'template_name' => $template_name, |
| 180 |
'template_path' => $template_path, |
| 181 |
'located' => $template, |
| 182 |
'args' => $args, |
| 183 |
); |
| 184 |
|
| 185 |
if (!empty($args) && is_array($args)) { |
| 186 |
if (isset($args['action_args'])) { |
| 187 |
_doing_it_wrong( |
| 188 |
__FUNCTION__, |
| 189 |
__('action_args should not be overwritten when calling yatra_get_template.', 'yatra'), |
| 190 |
'1.0.0' |
| 191 |
); |
| 192 |
unset($args['action_args']); |
| 193 |
} |
| 194 |
extract($args); // @codingStandardsIgnoreLine |
| 195 |
} |
| 196 |
|
| 197 |
do_action('yatra_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args']); |
| 198 |
|
| 199 |
include $action_args['located']; |
| 200 |
|
| 201 |
do_action('yatra_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args']); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
if (!function_exists('yatra_locate_template')) { |
| 206 |
function yatra_locate_template($template_name, $template_path = '', $default_path = '') |
| 207 |
{ |
| 208 |
if (!$template_path) { |
| 209 |
$template_path = yatra()->template_path(); |
| 210 |
} |
| 211 |
|
| 212 |
if (!$default_path) { |
| 213 |
$default_path = yatra()->plugin_template_path(); |
| 214 |
} |
| 215 |
|
| 216 |
// Look within passed path within the theme - this is priority. |
| 217 |
$template = locate_template( |
| 218 |
array( |
| 219 |
trailingslashit($template_path) . $template_name, |
| 220 |
$template_name, |
| 221 |
) |
| 222 |
); |
| 223 |
|
| 224 |
// Get default template/. |
| 225 |
if (!$template) { |
| 226 |
$template = $default_path . $template_name; |
| 227 |
} |
| 228 |
// Return what we found. |
| 229 |
return apply_filters('yatra_locate_template', $template, $template_name, $template_path); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
if (!function_exists('yatra_single_tour_tabs')) { |
| 234 |
|
| 235 |
function yatra_single_tour_tabs() |
| 236 |
{ |
| 237 |
global $post; |
| 238 |
|
| 239 |
|
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
if (!function_exists('yatra_get_checkout_page')) { |
| 244 |
|
| 245 |
function yatra_get_checkout_page($get_permalink = false) |
| 246 |
{ |
| 247 |
|
| 248 |
$page_id = absint(get_option('yatra_checkout_page')); |
| 249 |
|
| 250 |
if ($page_id < 1) { |
| 251 |
|
| 252 |
global $wpdb; |
| 253 |
|
| 254 |
$page_id = $wpdb->get_var('SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE "%[yatra_checkout]%" AND post_parent = 0'); |
| 255 |
} |
| 256 |
|
| 257 |
$page_permalink = get_permalink($page_id); |
| 258 |
|
| 259 |
if ($get_permalink) { |
| 260 |
|
| 261 |
return $page_permalink; |
| 262 |
} |
| 263 |
|
| 264 |
return $page_id; |
| 265 |
|
| 266 |
|
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
if (!function_exists('yatra_get_cart_page')) { |
| 272 |
|
| 273 |
function yatra_get_cart_page($get_permalink = false) |
| 274 |
{ |
| 275 |
$page_id = absint(get_option('yatra_cart_page')); |
| 276 |
|
| 277 |
if ($page_id < 1) { |
| 278 |
|
| 279 |
global $wpdb; |
| 280 |
|
| 281 |
$page_id = $wpdb->get_var('SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE "%[yatra_cart]%" AND post_parent = 0'); |
| 282 |
} |
| 283 |
|
| 284 |
$page_permalink = get_permalink($page_id); |
| 285 |
|
| 286 |
if ($get_permalink) { |
| 287 |
|
| 288 |
return $page_permalink; |
| 289 |
} |
| 290 |
|
| 291 |
return $page_id; |
| 292 |
|
| 293 |
|
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
if (!function_exists('yatra_get_booking_statuses')) { |
| 298 |
|
| 299 |
function yatra_get_booking_statuses($status_key = '') |
| 300 |
{ |
| 301 |
$statuses = apply_filters( |
| 302 |
'yatra_booking_statuses', array( |
| 303 |
'yatra-pending' => __('Pending', 'yatra'), |
| 304 |
'yatra-processing' => __('Processing', 'yatra'), |
| 305 |
'yatra-on-hold' => __('On Hold', 'yatra'), |
| 306 |
'yatra-completed' => __('Completed', 'yatra'), |
| 307 |
'yatra-cancelled' => __('Cancelled', 'yatra') |
| 308 |
) |
| 309 |
); |
| 310 |
|
| 311 |
if (empty($status_key)) { |
| 312 |
|
| 313 |
return $statuses; |
| 314 |
} |
| 315 |
if (isset($statuses[$status_key])) { |
| 316 |
return $statuses[$status_key]; |
| 317 |
} |
| 318 |
return $statuses; |
| 319 |
|
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
if (!function_exists('yatra_the_posts_navigation')) : |
| 324 |
/** |
| 325 |
* Documentation for function. |
| 326 |
*/ |
| 327 |
function yatra_the_posts_navigation() |
| 328 |
{ |
| 329 |
the_post_navigation(array( |
| 330 |
'prev_text' => '<span class="screen-reader-text">' . esc_html__('Previous Post', 'yatra') . '</span><span class="nav-title">%title</span>', |
| 331 |
'next_text' => '<span class="screen-reader-text">' . esc_html__('Next Post', 'yatra') . '</span><span class="nav-title">%title</span>', |
| 332 |
)); |
| 333 |
} |
| 334 |
endif; |
| 335 |
|
| 336 |
if (!function_exists('yatra_get_template_part')) { |
| 337 |
|
| 338 |
function yatra_get_template_part($slug, $name = '') |
| 339 |
{ |
| 340 |
$path = "{$slug}.php"; |
| 341 |
|
| 342 |
if ('' !== $name) { |
| 343 |
|
| 344 |
$path = "{$slug}-{$name}.php"; |
| 345 |
} |
| 346 |
$template = yatra_locate_template($path, false, false); |
| 347 |
|
| 348 |
require $template; |
| 349 |
|
| 350 |
} |
| 351 |
|
| 352 |
} |
| 353 |
if (!function_exists('yatra_posted_by')) : |
| 354 |
/** |
| 355 |
* Prints HTML with meta information about theme author. |
| 356 |
*/ |
| 357 |
function yatra_posted_by() |
| 358 |
{ |
| 359 |
printf( |
| 360 |
/* translators: 1: SVG icon. 2: post author, only visible to screen readers. 3: author link. */ |
| 361 |
'<span class="byline"><span class="screen-reader-text">%1$s</span><span class="author vcard"><a class="url fn n" href="%2$s">%3$s</a></span></span>', |
| 362 |
__('Posted by', 'yatra'), |
| 363 |
esc_url(get_author_posts_url(get_the_author_meta('ID'))), |
| 364 |
esc_html(get_the_author()) |
| 365 |
); |
| 366 |
} |
| 367 |
endif; |
| 368 |
|
| 369 |
if (!function_exists('yatra_posted_on')) : |
| 370 |
/** |
| 371 |
* Prints HTML with meta information for the current post-date/time. |
| 372 |
*/ |
| 373 |
function yatra_posted_on() |
| 374 |
{ |
| 375 |
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; |
| 376 |
if (get_the_time('U') !== get_the_modified_time('U')) { |
| 377 |
//$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; |
| 378 |
} |
| 379 |
|
| 380 |
$time_string = sprintf( |
| 381 |
$time_string, |
| 382 |
esc_attr(get_the_date(DATE_W3C)), |
| 383 |
esc_html(get_the_date()), |
| 384 |
esc_attr(get_the_modified_date(DATE_W3C)), |
| 385 |
esc_html(get_the_modified_date()) |
| 386 |
); |
| 387 |
|
| 388 |
printf( |
| 389 |
'<span class="posted-on"><a href="%1$s" rel="bookmark">%2$s</a></span>', |
| 390 |
esc_url(get_permalink()), |
| 391 |
$time_string |
| 392 |
); |
| 393 |
} |
| 394 |
endif; |
| 395 |
|
| 396 |
if (!function_exists('yatra_entry_meta')) { |
| 397 |
|
| 398 |
function yatra_entry_meta() |
| 399 |
{ |
| 400 |
?> |
| 401 |
<div class="entry-meta"> |
| 402 |
<?php yatra_posted_by(); ?> |
| 403 |
<?php yatra_posted_on(); ?> |
| 404 |
<?php |
| 405 |
// Edit post link. |
| 406 |
edit_post_link( |
| 407 |
sprintf( |
| 408 |
wp_kses( |
| 409 |
/* translators: %s: Name of current post. Only visible to screen readers. */ |
| 410 |
__('Edit <span class="screen-reader-text">%s</span>', 'yatra'), |
| 411 |
array( |
| 412 |
'span' => array( |
| 413 |
'class' => array(), |
| 414 |
), |
| 415 |
) |
| 416 |
), |
| 417 |
get_the_title() |
| 418 |
), |
| 419 |
'<span class="edit-link">', |
| 420 |
'</span>' |
| 421 |
); |
| 422 |
?> |
| 423 |
</div><!-- .meta-info --> |
| 424 |
<?php |
| 425 |
} |
| 426 |
|
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
/** |
| 431 |
* Get permalink settings |
| 432 |
* |
| 433 |
* @since 1.0.0 |
| 434 |
* @return array |
| 435 |
*/ |
| 436 |
function yatra_get_permalink_structure() |
| 437 |
{ |
| 438 |
|
| 439 |
$permalinks = wp_parse_args( |
| 440 |
(array)get_option('yatra_permalinks', array()), |
| 441 |
array( |
| 442 |
'yatra_tour_base' => 'tour', |
| 443 |
'yatra_destination_base' => 'destination', |
| 444 |
'yatra_activity_base' => 'activity', |
| 445 |
'yatra_attributes_base' => 'attributes', |
| 446 |
) |
| 447 |
); |
| 448 |
|
| 449 |
// Ensure rewrite slugs are set. |
| 450 |
$permalinks['yatra_tour_base'] = untrailingslashit(empty($permalinks['yatra_tour_base']) ? 'tour' : $permalinks['yatra_tour_base']); |
| 451 |
$permalinks['yatra_destination_base'] = untrailingslashit(empty($permalinks['yatra_destination_base']) ? 'destination' : $permalinks['yatra_destination_base']); |
| 452 |
$permalinks['yatra_activity_base'] = untrailingslashit(empty($permalinks['yatra_activity_base']) ? 'activity' : $permalinks['yatra_activity_base']); |
| 453 |
return $permalinks; |
| 454 |
} |
| 455 |
|
| 456 |
if (!function_exists('yatra_tour_price')) { |
| 457 |
|
| 458 |
function yatra_tour_price($tour_id, $is_html = true) |
| 459 |
{ |
| 460 |
$yatra_tour_meta_regular_price = get_post_meta($tour_id, 'yatra_tour_meta_regular_price', true); |
| 461 |
|
| 462 |
$yatra_tour_meta_sales_price = get_post_meta($tour_id, 'yatra_tour_meta_sales_price', true); |
| 463 |
|
| 464 |
$price_per_person = empty($yatra_tour_meta_sales_price) || $yatra_tour_meta_sales_price == 0 ? $yatra_tour_meta_regular_price : $yatra_tour_meta_sales_price; |
| 465 |
|
| 466 |
if (!$is_html) { |
| 467 |
|
| 468 |
return $price_per_person; |
| 469 |
} |
| 470 |
$price_string = '<span class="regular-price"><del>' . yatra_get_current_currency_symbol() . '' . $yatra_tour_meta_regular_price . '</del></span>'; |
| 471 |
|
| 472 |
$price_string .= '<br/><span class="sales-price">' . yatra_get_current_currency_symbol() . '' . $yatra_tour_meta_sales_price . '</del></span>'; |
| 473 |
|
| 474 |
if (empty($yatra_tour_meta_sales_price) || $yatra_tour_meta_sales_price == 0) { |
| 475 |
|
| 476 |
$price_string = '<span class="regular-price">' . yatra_get_current_currency_symbol() . '' . $yatra_tour_meta_regular_price . '</span>'; |
| 477 |
|
| 478 |
|
| 479 |
} |
| 480 |
return $price_string; |
| 481 |
} |
| 482 |
|
| 483 |
} |
| 484 |
|
| 485 |
if (!function_exists('yatra_get_final_tour_price')) { |
| 486 |
|
| 487 |
function yatra_get_final_tour_price($tour_id, $number_of_people = 1, $type = 'single') |
| 488 |
{ |
| 489 |
|
| 490 |
if (is_array($number_of_people) && $type == 'single') { |
| 491 |
$type = 'multi'; |
| 492 |
} |
| 493 |
|
| 494 |
$yatra_tour_meta_regular_price = get_post_meta($tour_id, 'yatra_tour_meta_regular_price', true); |
| 495 |
|
| 496 |
$yatra_tour_meta_sales_price = get_post_meta($tour_id, 'yatra_tour_meta_sales_price', true); |
| 497 |
|
| 498 |
$yatra_tour_meta_price_per = get_post_meta($tour_id, 'yatra_tour_meta_price_per', true); |
| 499 |
|
| 500 |
$yatra_tour_meta_group_size = get_post_meta($tour_id, 'yatra_tour_meta_group_size', true); |
| 501 |
|
| 502 |
if ($yatra_tour_meta_group_size == 0) { |
| 503 |
|
| 504 |
$yatra_tour_meta_group_size = 1; |
| 505 |
} |
| 506 |
if ($type == 'single') { |
| 507 |
|
| 508 |
$number_of_people = absint($number_of_people); |
| 509 |
|
| 510 |
$price_per_person = empty($yatra_tour_meta_sales_price) || $yatra_tour_meta_sales_price == 0 ? $yatra_tour_meta_regular_price : $yatra_tour_meta_sales_price; |
| 511 |
|
| 512 |
if ($yatra_tour_meta_price_per == 'person') { |
| 513 |
|
| 514 |
return $price_per_person * $number_of_people; |
| 515 |
} |
| 516 |
if ($yatra_tour_meta_price_per == 'group') { |
| 517 |
|
| 518 |
|
| 519 |
$number_of_group = ceil($number_of_people / $yatra_tour_meta_group_size); |
| 520 |
|
| 521 |
return $price_per_person * $number_of_group; |
| 522 |
} |
| 523 |
return $price_per_person; |
| 524 |
|
| 525 |
} else if ($type == "multi") { |
| 526 |
|
| 527 |
$total_price = 0; |
| 528 |
|
| 529 |
$yatra_multiple_pricing = get_post_meta($tour_id, 'yatra_multiple_pricing', true); |
| 530 |
|
| 531 |
foreach ($yatra_multiple_pricing as $pricing_key => $price_args) { |
| 532 |
$person = is_array($number_of_people) && isset($number_of_people[$pricing_key]) ? absint($number_of_people[$pricing_key]) : 0; |
| 533 |
$regular_price = isset($price_args['regular_price']) ? absint($price_args['regular_price']) : 0; |
| 534 |
$sales_price = isset($price_args['sales_price']) ? absint($price_args['sales_price']) : 0; |
| 535 |
$sales_price = isset($price_args['sales_price']) && '' != $price_args['sales_price'] ? $sales_price : $regular_price; |
| 536 |
switch ($yatra_tour_meta_price_per) { |
| 537 |
case "person": |
| 538 |
$total_price += ($sales_price * $person); |
| 539 |
break; |
| 540 |
case "group": |
| 541 |
$number_of_group = ceil($person / $yatra_tour_meta_group_size); |
| 542 |
$total_price += ($sales_price * $number_of_group); |
| 543 |
break; |
| 544 |
} |
| 545 |
} |
| 546 |
return $total_price; |
| 547 |
} |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
if (!function_exists('yatra_update_booking_status')) { |
| 553 |
|
| 554 |
function yatra_update_booking_status($booking_id = 0, $status = 'yatra-pending') |
| 555 |
{ |
| 556 |
$yatra_booking_statuses = yatra_get_booking_statuses(); |
| 557 |
|
| 558 |
if ($booking_id < 1 || !isset($yatra_booking_statuses[$status])) { |
| 559 |
|
| 560 |
return false; |
| 561 |
} |
| 562 |
|
| 563 |
do_action('yatra_before_booking_status_change', array( |
| 564 |
'booking_id' => $booking_id, |
| 565 |
'status' => $status |
| 566 |
)); |
| 567 |
|
| 568 |
$booking_array = array(); |
| 569 |
$booking_array['ID'] = $booking_id; |
| 570 |
$booking_array['post_status'] = $status; |
| 571 |
|
| 572 |
// Update the post into the database |
| 573 |
wp_update_post($booking_array); |
| 574 |
|
| 575 |
do_action('yatra_after_booking_status_change', array( |
| 576 |
'booking_id' => $booking_id, |
| 577 |
'status' => $status |
| 578 |
)); |
| 579 |
|
| 580 |
return true; |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
if (!function_exists('yatra_global_smart_tags')) { |
| 586 |
|
| 587 |
function yatra_global_smart_tags() |
| 588 |
{ |
| 589 |
return apply_filters( |
| 590 |
'yatra_global_smart_tags', |
| 591 |
array( |
| 592 |
'home_url' => get_home_url(), |
| 593 |
'blog_info' => get_bloginfo(), |
| 594 |
) |
| 595 |
); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
if (!function_exists('yatra_booking_smart_tags')) { |
| 600 |
|
| 601 |
function yatra_booking_smart_tags($booking_id = 0) |
| 602 |
{ |
| 603 |
$smart_tags['booking_code'] = ''; |
| 604 |
|
| 605 |
$smart_tags['booking_status'] = ''; |
| 606 |
|
| 607 |
$smart_tags['tour_lists'] = ''; |
| 608 |
|
| 609 |
if ($booking_id > 0) { |
| 610 |
|
| 611 |
$booking_post = get_post($booking_id); |
| 612 |
|
| 613 |
$booking_status = isset($booking_post->post_status) ? $booking_post->post_status : ''; |
| 614 |
|
| 615 |
$all_post_statuses = yatra_get_booking_statuses(); |
| 616 |
|
| 617 |
$booking_meta_params = get_post_meta($booking_id, 'yatra_booking_meta_params', true); |
| 618 |
|
| 619 |
$booking_meta = get_post_meta($booking_id, 'yatra_booking_meta', true); |
| 620 |
|
| 621 |
$smart_tags['booking_code'] = isset($booking_meta_params['booking_code']) ? $booking_meta_params['booking_code'] : ''; |
| 622 |
|
| 623 |
$smart_tags['booking_status'] = isset($all_post_statuses[$booking_status]) ? $all_post_statuses[$booking_status] : ''; |
| 624 |
|
| 625 |
foreach ($booking_meta as $tour_id => $meta) { |
| 626 |
|
| 627 |
$smart_tags['tour_lists'] .= '<a href="' . get_permalink($tour_id) . '" target="_blank">' . $meta['yatra_tour_name'] . '</a><br/>'; |
| 628 |
|
| 629 |
} |
| 630 |
|
| 631 |
} |
| 632 |
|
| 633 |
return apply_filters( |
| 634 |
'yatra_booking_smart_tags', |
| 635 |
$smart_tags |
| 636 |
); |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
if (!function_exists('yatra_customer_smart_tags')) { |
| 641 |
|
| 642 |
function yatra_customer_smart_tags($booking_id = 0) |
| 643 |
{ |
| 644 |
$smart_tags['customer_name'] = ''; |
| 645 |
|
| 646 |
$smart_tags['customer_email'] = ''; |
| 647 |
|
| 648 |
if ($booking_id > 0) { |
| 649 |
|
| 650 |
$booking_meta_params = get_post_meta($booking_id, 'yatra_booking_meta_params', true); |
| 651 |
|
| 652 |
$customer_info = isset($booking_meta_params ['yatra_tour_customer_info']) ? $booking_meta_params ['yatra_tour_customer_info'] : array(); |
| 653 |
|
| 654 |
$smart_tags['customer_name'] = isset($customer_info['fullname']) ? $customer_info['fullname'] : ''; |
| 655 |
|
| 656 |
$smart_tags['customer_email'] = isset($customer_info['email']) ? $customer_info['email'] : ''; |
| 657 |
} |
| 658 |
|
| 659 |
return apply_filters( |
| 660 |
'yatra_customer_smart_tags', |
| 661 |
$smart_tags |
| 662 |
); |
| 663 |
} |
| 664 |
} |
| 665 |
if (!function_exists('yatra_get_date')) { |
| 666 |
|
| 667 |
function yatra_get_date() |
| 668 |
{ |
| 669 |
return date('Y-m-d H:i:s'); |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
if (!function_exists('yatra_all_smart_tags')) { |
| 674 |
|
| 675 |
function yatra_all_smart_tags($booking_id = 0) |
| 676 |
{ |
| 677 |
$yatra_global_smart_tags = yatra_global_smart_tags(); |
| 678 |
|
| 679 |
$yatra_booking_smart_tags = yatra_booking_smart_tags($booking_id); |
| 680 |
|
| 681 |
$yatra_customer_smart_tags = yatra_customer_smart_tags($booking_id); |
| 682 |
|
| 683 |
$all_tags = array_merge($yatra_global_smart_tags, $yatra_booking_smart_tags, $yatra_customer_smart_tags); |
| 684 |
|
| 685 |
return apply_filters('yatra_all_smart_tags', $all_tags); |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
/** |
| 691 |
* Get data if set, otherwise return a default value or null. Prevents notices when data is not set. |
| 692 |
* |
| 693 |
* @since |
| 694 |
* @param mixed $var Variable. |
| 695 |
* @param string $default Default value. |
| 696 |
* @return mixed |
| 697 |
*/ |
| 698 |
if (!function_exists(('yatra_get_var'))) { |
| 699 |
function yatra_get_var(&$var, $default = null) |
| 700 |
{ |
| 701 |
return isset($var) ? $var : $default; |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
if (!function_exists('is_yatra_error')) { |
| 706 |
|
| 707 |
function is_yatra_error($thing) |
| 708 |
{ |
| 709 |
return ($thing instanceof WP_Error); |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
} |
| 714 |
|
| 715 |
if (!function_exists('yatra_logout_url')) { |
| 716 |
|
| 717 |
function yatra_logout_url() |
| 718 |
{ |
| 719 |
|
| 720 |
return wp_logout_url(get_permalink()); |
| 721 |
|
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
} |
| 726 |
|
| 727 |
if (!function_exists('yatra_get_my_account_page')) { |
| 728 |
|
| 729 |
function yatra_get_my_account_page($get_permalink = false) |
| 730 |
{ |
| 731 |
$page_id = absint(get_option('yatra_my_account_page')); |
| 732 |
|
| 733 |
if ($page_id < 1) { |
| 734 |
|
| 735 |
global $wpdb; |
| 736 |
|
| 737 |
$page_id = $wpdb->get_var('SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE "%[yatra_my_account]%" AND post_parent = 0'); |
| 738 |
} |
| 739 |
|
| 740 |
$page_permalink = get_permalink($page_id); |
| 741 |
|
| 742 |
if ($get_permalink) { |
| 743 |
|
| 744 |
return $page_permalink; |
| 745 |
} |
| 746 |
|
| 747 |
return $page_id; |
| 748 |
|
| 749 |
|
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
if (!function_exists('yatra_enable_guest_checkout')) { |
| 754 |
|
| 755 |
function yatra_enable_guest_checkout() |
| 756 |
{ |
| 757 |
if ('yes' === get_option('yatra_enable_guest_checkout', 'yes')) { |
| 758 |
|
| 759 |
return true; |
| 760 |
} |
| 761 |
return false; |
| 762 |
|
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
if (!function_exists('yatra_payment_gateway_fields')) { |
| 767 |
function yatra_payment_gateway_fields() |
| 768 |
{ |
| 769 |
$yatra_get_active_payment_gateways = (yatra_get_active_payment_gateways()); |
| 770 |
|
| 771 |
$yatra_get_payment_gateways = yatra_get_payment_gateways(); |
| 772 |
|
| 773 |
if (count($yatra_get_active_payment_gateways) > 0) { |
| 774 |
|
| 775 |
echo '<h2 class="yatra-payment-gateway-title">' . __('Payment Gateways', 'yatra') . '</h2>'; |
| 776 |
|
| 777 |
echo '<ul class="yatra-payment-gateway">'; |
| 778 |
|
| 779 |
foreach ($yatra_get_payment_gateways as $gateway) { |
| 780 |
|
| 781 |
$gateway_id = isset($gateway['id']) ? $gateway['id'] : ''; |
| 782 |
|
| 783 |
if (in_array($gateway_id, $yatra_get_active_payment_gateways)) { |
| 784 |
|
| 785 |
echo '<li>'; |
| 786 |
|
| 787 |
echo '<label>'; |
| 788 |
|
| 789 |
echo '<input type="radio" name="yatra-payment-gateway" value="' . esc_attr($gateway_id) . '"/>'; |
| 790 |
|
| 791 |
echo ' <span>' . $gateway['frontend_title'] . '</span>'; |
| 792 |
|
| 793 |
echo '</label>'; |
| 794 |
|
| 795 |
echo '</li>'; |
| 796 |
} |
| 797 |
|
| 798 |
} |
| 799 |
echo '</ul>'; |
| 800 |
} |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
if (!function_exists('yatra_maybeintempty')) { |
| 806 |
function yatra_maybeintempty($var) |
| 807 |
{ |
| 808 |
if ($var == '') { |
| 809 |
return ''; |
| 810 |
} |
| 811 |
return absint($var); |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
|