Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- remove_action( 'wp_travel_single_trip_meta_list', 'wp_travel_single_location', 1 );
- add_action( 'wp_travel_single_trip_meta_list', 'wp_travel_single_location_modified', 1 );
- function wp_travel_single_location_modified( $post_id ) {
- if ( ! $post_id ) {
- return;
- }
- // Get Strings
- $strings = wp_travel_get_strings();
- $terms = get_the_terms( $post_id, 'travel_locations' );
- $fixed_departure = get_post_meta( $post_id, 'wp_travel_fixed_departure', true );
- $fixed_departure = ( $fixed_departure ) ? $fixed_departure : 'yes';
- $fixed_departure = apply_filters( 'wp_travel_fixed_departure_defalut', $fixed_departure );
- $trip_duration = get_post_meta( $post_id, 'wp_travel_trip_duration', true );
- $trip_duration = ( $trip_duration ) ? $trip_duration : 0;
- $trip_duration_night = get_post_meta( $post_id, 'wp_travel_trip_duration_night', true );
- $trip_duration_night = ( $trip_duration_night ) ? $trip_duration_night : 0;
- // Strings
- $locations_text = isset( $strings['locations'] ) ? $strings['locations'] : __( 'Locations', 'wp-travel' );
- $fixed_departure_text = isset( $strings['fixed_departure'] ) ? $strings['fixed_departure'] : __( 'Fixed departure', 'wp-travel' );
- $trip_duration_text = isset( $strings['trip_duration'] ) ? $strings['trip_duration'] : __( 'Trip duration', 'wp-travel' );
- if ( is_array( $terms ) && count( $terms ) > 0 ) :
- ?>
- <li class="no-border">
- <div class="travel-info">
- <strong class="title"><?php echo esc_html( $locations_text ); ?></strong>
- </div>
- <div class="travel-info">
- <span class="value">
- <?php
- $i = 0;
- foreach ( $terms as $term ) :
- if ( $i > 0 ) :
- ?>
- ,
- <?php
- endif;
- ?>
- <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>
- <?php
- $i++;
- endforeach;
- ?>
- </span>
- </div>
- </li>
- <?php endif; ?>
- <?php
- if ( 'yes' === $fixed_departure ) :
- if ( $dates = wp_travel_get_fixed_departure_date_modified( $post_id ) ) {
- ?>
- <li>
- <div class="travel-info">
- <strong class="title"><?php echo esc_html( $fixed_departure_text ); ?></strong>
- </div>
- <div class="travel-info">
- <span class="value">
- <?php echo $dates; ?>
- </span>
- </div>
- </li>
- <?php
- }
- ?>
- <?php else : ?>
- <?php if ( $trip_duration || $trip_duration_night ) : ?>
- <li>
- <div class="travel-info">
- <strong class="title"><?php echo esc_html( $trip_duration_text ); ?></strong>
- </div>
- <div class="travel-info">
- <span class="value">
- <?php printf( __( '%1$s Day(s) %2$s Night(s)', 'wp-travel' ), $trip_duration, $trip_duration_night ); ?>
- </span>
- </div>
- </li>
- <?php endif; ?>
- <?php
- endif;
- }
- function wp_travel_get_fixed_departure_date_modified( $trip_id ) {
- $start_date = get_post_meta( $trip_id, 'wp_travel_start_date', true );
- $end_date = get_post_meta( $trip_id, 'wp_travel_end_date', true );
- $show_end_date = wp_travel_booking_show_end_date();
- $date_format = get_option( 'date_format' );
- if ( ! $date_format ) :
- $date_format = 'jS M, Y';
- endif;
- ob_start();
- if ( 'single-price' === wp_travel_get_pricing_option_type() ) {
- if ( $start_date || $end_date ) :
- if ( $start_date || $end_date ) :
- if ( '' !== $end_date && $show_end_date ) {
- printf( '%s - %s', date_i18n( $date_format, strtotime( $start_date ) ), date_i18n( $date_format, strtotime( $end_date ) ) );
- } else {
- printf( '%s', date_i18n( $date_format, strtotime( $start_date ) ) );
- }
- else :
- esc_html_e( 'N/A', 'wp-travel' );
- endif;
- endif;
- } elseif ( 'multiple-price' === wp_travel_get_pricing_option_type() ) {
- $dates = array();
- $trip_pricing_options = get_post_meta( $trip_id, 'wp_travel_pricing_options', true );
- if ( is_array( $trip_pricing_options ) && count( $trip_pricing_options ) > 0 ) {
- foreach ( $trip_pricing_options as $price_key => $pricing ) :
- // Set Vars.
- $price_key = isset( $pricing['price_key'] ) ? $pricing['price_key'] : '';
- $available_dates = wp_travel_get_trip_available_dates( $trip_id, $price_key ); // No need to pass date
- if ( is_array( $available_dates ) && count( $available_dates ) > 0 ) { // multiple available dates
- foreach ( $available_dates as $available_date ) {
- $dates[] = $available_date;
- }
- }
- endforeach;
- $dates = array_unique( $dates );
- usort( $dates, 'wp_travel_date_sort' );
- $show_multiple = apply_filters( 'wp_travel_show_multiple_fixed_departure_dates', false );
- if ( $show_multiple ) {
- echo '<ul>';
- foreach ( $dates as $date ) {
- printf( '<li>%s</li>', date_i18n( $date_format, strtotime( $date ) ) );
- }
- echo '</ul>';
- } else {
- if ( count( $dates ) > 0 ) {
- $date_found = false;
- foreach ( $dates as $date ) {
- if ( date('Y-m-d ', strtotime( $date ) ) >= date( 'Y-m-d' ) ) {
- $date_found = true;
- printf( '%s', date_i18n( $date_format, strtotime( $date ) ) );
- break;
- }
- }
- if ( ! $date_found ) {
- echo __( 'N/A', 'wp-travel' );
- }
- }
- }
- }
- }
- $content = ob_get_contents();
- ob_end_clean();
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement