Skip to content

Instantly share code, notes, and snippets.

Created February 15, 2018 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7230510989cb3a21c0038385de0d3b0b to your computer and use it in GitHub Desktop.
Save anonymous/7230510989cb3a21c0038385de0d3b0b to your computer and use it in GitHub Desktop.
function wp_travel_single_location_customized( $post_id ){
if ( ! $post_id ) {
return;
}
$terms = get_the_terms( $post_id, 'travel_locations' );
$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 );
$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>
<li>
<?php if ( 'yes' === $fixed_departure ) : ?>
<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>
<?php else : ?>
<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)', $trip_duration, $trip_duration_night ); ?>
</span>
</div>
<?php endif; ?>
</li>
<?php
endif;
}
add_action('after_setup_theme', 'wp_travel_custom_sort_date', 20 );
function wp_travel_custom_sort_date() {
remove_action( 'wp_travel_single_itinerary_after_trip_meta_list', 'wp_travel_single_location', 1 );
add_action( 'wp_travel_single_itinerary_after_trip_meta_list', 'wp_travel_single_location_customized', 10 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment