Advertisement
Guest User

Untitled

a guest
Aug 28th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. remove_action( 'wp_travel_single_trip_meta_list', 'wp_travel_single_location', 1 );
  2. add_action( 'wp_travel_single_trip_meta_list', 'wp_travel_single_location_modified', 1 );
  3.  
  4. function wp_travel_single_location_modified( $post_id ) {
  5. if ( ! $post_id ) {
  6. return;
  7. }
  8. // Get Strings
  9. $strings = wp_travel_get_strings();
  10.  
  11. $terms = get_the_terms( $post_id, 'travel_locations' );
  12.  
  13. $fixed_departure = get_post_meta( $post_id, 'wp_travel_fixed_departure', true );
  14. $fixed_departure = ( $fixed_departure ) ? $fixed_departure : 'yes';
  15. $fixed_departure = apply_filters( 'wp_travel_fixed_departure_defalut', $fixed_departure );
  16.  
  17. $trip_duration = get_post_meta( $post_id, 'wp_travel_trip_duration', true );
  18. $trip_duration = ( $trip_duration ) ? $trip_duration : 0;
  19. $trip_duration_night = get_post_meta( $post_id, 'wp_travel_trip_duration_night', true );
  20. $trip_duration_night = ( $trip_duration_night ) ? $trip_duration_night : 0;
  21.  
  22. // Strings
  23. $locations_text = isset( $strings['locations'] ) ? $strings['locations'] : __( 'Locations', 'wp-travel' );
  24. $fixed_departure_text = isset( $strings['fixed_departure'] ) ? $strings['fixed_departure'] : __( 'Fixed departure', 'wp-travel' );
  25. $trip_duration_text = isset( $strings['trip_duration'] ) ? $strings['trip_duration'] : __( 'Trip duration', 'wp-travel' );
  26.  
  27. if ( is_array( $terms ) && count( $terms ) > 0 ) :
  28. ?>
  29. <li class="no-border">
  30. <div class="travel-info">
  31. <strong class="title"><?php echo esc_html( $locations_text ); ?></strong>
  32. </div>
  33. <div class="travel-info">
  34. <span class="value">
  35. <?php
  36. $i = 0;
  37. foreach ( $terms as $term ) :
  38. if ( $i > 0 ) :
  39. ?>
  40. ,
  41. <?php
  42. endif;
  43. ?>
  44. <span class="wp-travel-locations"><a href="<?php echo esc_url( get_term_link( $term->term_id ) ); ?>"><?php echo esc_html( $term->name ); ?></a></span>
  45. <?php
  46. $i++;
  47. endforeach;
  48. ?>
  49. </span>
  50. </div>
  51. </li>
  52. <?php endif; ?>
  53. <?php
  54. if ( 'yes' === $fixed_departure ) :
  55. if ( $dates = wp_travel_get_fixed_departure_date_modified( $post_id ) ) {
  56. ?>
  57. <li>
  58. <div class="travel-info">
  59. <strong class="title"><?php echo esc_html( $fixed_departure_text ); ?></strong>
  60. </div>
  61. <div class="travel-info">
  62. <span class="value">
  63. <?php echo $dates; ?>
  64. </span>
  65. </div>
  66. </li>
  67. <?php
  68. }
  69. ?>
  70.  
  71. <?php else : ?>
  72. <?php if ( $trip_duration || $trip_duration_night ) : ?>
  73. <li>
  74. <div class="travel-info">
  75. <strong class="title"><?php echo esc_html( $trip_duration_text ); ?></strong>
  76. </div>
  77. <div class="travel-info">
  78. <span class="value">
  79. <?php printf( __( '%1$s Day(s) %2$s Night(s)', 'wp-travel' ), $trip_duration, $trip_duration_night ); ?>
  80. </span>
  81. </div>
  82. </li>
  83. <?php endif; ?>
  84. <?php
  85. endif;
  86. }
  87.  
  88. function wp_travel_get_fixed_departure_date_modified( $trip_id ) {
  89.  
  90. $start_date = get_post_meta( $trip_id, 'wp_travel_start_date', true );
  91. $end_date = get_post_meta( $trip_id, 'wp_travel_end_date', true );
  92. $show_end_date = wp_travel_booking_show_end_date();
  93. $date_format = get_option( 'date_format' );
  94. if ( ! $date_format ) :
  95. $date_format = 'jS M, Y';
  96. endif;
  97.  
  98. ob_start();
  99. if ( 'single-price' === wp_travel_get_pricing_option_type() ) {
  100. if ( $start_date || $end_date ) :
  101. if ( $start_date || $end_date ) :
  102.  
  103. if ( '' !== $end_date && $show_end_date ) {
  104. printf( '%s - %s', date_i18n( $date_format, strtotime( $start_date ) ), date_i18n( $date_format, strtotime( $end_date ) ) );
  105. } else {
  106. printf( '%s', date_i18n( $date_format, strtotime( $start_date ) ) );
  107. }
  108. else :
  109. esc_html_e( 'N/A', 'wp-travel' );
  110. endif;
  111. endif;
  112.  
  113. } elseif ( 'multiple-price' === wp_travel_get_pricing_option_type() ) {
  114. $dates = array();
  115. $trip_pricing_options = get_post_meta( $trip_id, 'wp_travel_pricing_options', true );
  116. if ( is_array( $trip_pricing_options ) && count( $trip_pricing_options ) > 0 ) {
  117. foreach ( $trip_pricing_options as $price_key => $pricing ) :
  118. // Set Vars.
  119. $price_key = isset( $pricing['price_key'] ) ? $pricing['price_key'] : '';
  120. $available_dates = wp_travel_get_trip_available_dates( $trip_id, $price_key ); // No need to pass date
  121. if ( is_array( $available_dates ) && count( $available_dates ) > 0 ) { // multiple available dates
  122. foreach ( $available_dates as $available_date ) {
  123. $dates[] = $available_date;
  124. }
  125. }
  126. endforeach;
  127. $dates = array_unique( $dates );
  128. usort( $dates, 'wp_travel_date_sort' );
  129. $show_multiple = apply_filters( 'wp_travel_show_multiple_fixed_departure_dates', false );
  130.  
  131. if ( $show_multiple ) {
  132. echo '<ul>';
  133. foreach ( $dates as $date ) {
  134. printf( '<li>%s</li>', date_i18n( $date_format, strtotime( $date ) ) );
  135. }
  136. echo '</ul>';
  137. } else {
  138.  
  139. if ( count( $dates ) > 0 ) {
  140. $date_found = false;
  141. foreach ( $dates as $date ) {
  142. if ( date('Y-m-d ', strtotime( $date ) ) >= date( 'Y-m-d' ) ) {
  143. $date_found = true;
  144. printf( '%s', date_i18n( $date_format, strtotime( $date ) ) );
  145. break;
  146. }
  147. }
  148. if ( ! $date_found ) {
  149. echo __( 'N/A', 'wp-travel' );
  150. }
  151. }
  152. }
  153. }
  154. }
  155.  
  156. $content = ob_get_contents();
  157. ob_end_clean();
  158. return $content;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement