Last active
June 1, 2018 09:46
-
-
Save stevenbrown-85/cd80b48ec16f3ac2c256cb2791cd033f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******** SHOW MULTIPLE DATES ON TRIP PAGE ********/ | |
//remove original function | |
remove_action( 'wp_travel_single_itinerary_after_trip_meta_list', 'wp_travel_single_location', 1 ); | |
//our own function | |
function wp_travel_single_location_multiple_dates( $post_id ) { | |
if ( ! $post_id ) { | |
return; | |
} | |
$terms = get_the_terms( $post_id, 'travel_locations' ); | |
$enable_pricing_options = get_post_meta( $post_id, 'wp_travel_enable_pricing_options', true ); | |
$enable_pricing_options = ( $enable_pricing_options ) ? $enable_pricing_options : 'yes'; | |
$enable_pricing_options = apply_filters( 'wp_travel_enable_pricing_options', $enable_pricing_options ); | |
$start_date = get_post_meta( $post_id, 'wp_travel_start_date', true ); | |
$end_date = get_post_meta( $post_id, 'wp_travel_end_date', true ); | |
$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 ); | |
$multiple_departure = get_post_meta( $post_id, 'wp_travel_enable_multiple_fixed_departue', true ); | |
$multiple_departure = ( $multiple_departure ) ? $multiple_departure : 'yes'; | |
$multiple_departure = apply_filters( 'wp_travel_enable_multiple_fixed_departue', $multiple_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; | |
if ( is_array( $terms ) && count( $terms ) > 0 ) : ?> | |
<li class="no-border"> | |
<div class="travel-info"> | |
<strong class="title"><?php esc_html_e( 'Locations', 'wp-travel' ); ?></strong> | |
</div> | |
<div class="travel-info"> | |
<span class="value"><?php $i = 0; ?><?php foreach ( $terms as $term ) : ?><?php 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 && 'no' === $enable_pricing_options ) : ?> | |
<li> | |
<div class="travel-info"> | |
<strong class="title"><?php esc_html_e( 'Fixed Departure', 'wp-travel' ); ?></strong> | |
</div> | |
<div class="travel-info"> | |
<span class="value"> | |
<?php $date_format = get_option( 'date_format' ); ?> | |
<?php if ( ! $date_format ) : ?> | |
<?php $date_format = 'jS M, Y'; ?> | |
<?php endif; ?> | |
<?php printf( '%s - %s', date( $date_format, strtotime( $start_date ) ), date( $date_format, strtotime( $end_date ) ) ); ?> | |
</span> | |
</div> | |
</li> | |
<?php elseif ( 'yes' === $fixed_departure && 'no' === $multiple_departure) : ?> | |
<?php if ( $start_date && $end_date ) : ?> | |
<li> | |
<div class="travel-info"> | |
<strong class="title"><?php esc_html_e( 'Fixed Departure', 'wp-travel' ); ?></strong> | |
</div> | |
<div class="travel-info"> | |
<span class="value"> | |
<?php $date_format = get_option( 'date_format' ); ?> | |
<?php if ( ! $date_format ) : ?> | |
<?php $date_format = 'jS M, Y'; ?> | |
<?php endif; ?> | |
<?php printf( '%s - %s', date( $date_format, strtotime( $start_date ) ), date( $date_format, strtotime( $end_date ) ) ); ?> | |
</span> | |
</div> | |
</li> | |
<?php endif; ?> | |
<?php elseif ( 'yes' === $fixed_departure && 'yes' === $multiple_departure) : ?> | |
<li style="width:100%"> | |
<div class="travel-info"> | |
<strong class="title"><?php esc_html_e( 'Departure Dates', 'wp-travel' ); ?></strong> | |
</div> | |
<div class="travel-info"> | |
<span class="value"> | |
<?php global $post; | |
$trip_multiple_date_options = get_post_meta( $post->ID, 'wp_travel_multiple_trip_dates', true ); | |
if ( is_array( $trip_multiple_date_options ) && count( $trip_multiple_date_options ) !== 0 ) : | |
foreach ( $trip_multiple_date_options as $date_key => $date_option ) { | |
// Set Vars. | |
$start_date = isset( $date_option['start_date'] ) ? $date_option['start_date'] : ''; | |
$end_date = isset( $date_option['end_date'] ) ? $date_option['end_date'] : ''; | |
?> | |
<?php $date_format = get_option( 'date_format' ); ?> | |
<?php if ( ! $date_format ) : ?> | |
<?php $date_format = 'jS M, Y'; ?> | |
<?php endif; ?> | |
<?php printf( '%s - %s <br/>', date( $date_format, strtotime( $start_date ) ), date( $date_format, strtotime( $end_date ) ) ); | |
} | |
endif;?> | |
</span> | |
</div> | |
</li> | |
<?php else : ?> | |
<li> | |
<?php if ( $trip_duration || $trip_duration_night ) : ?> | |
<div class="travel-info"> | |
<strong class="title"><?php esc_html_e( 'Trip Duration', 'wp-travel' ); ?></strong> | |
</div> | |
<div class="travel-info"> | |
<span class="value"> | |
<?php printf( __( '%s Day(s) %s Night(s)', 'wp-travel' ), $trip_duration, $trip_duration_night ); ?> | |
</span> | |
</div> | |
</li> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php | |
} | |
add_action( 'wp_travel_single_itinerary_after_trip_meta_list', 'wp_travel_single_location_multiple_dates', 1 ); | |
/******** SHOW MULTIPLE DATES ON TRIP PAGE END ********/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi thank you for your coding. May I ask you if there's a way to show the starting date only in case of "same day trips/events"? Thanx again.