Created
July 13, 2021 05:23
-
-
Save asifpix/a38853a00936ff9cbce45de1a6994eb0 to your computer and use it in GitHub Desktop.
It will display min price in tour search result page.
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
<?php | |
class Travelux_Tour_Render { | |
private function __construct() { | |
$this->actions(); | |
} | |
public static function init(){ | |
static $instance = false; | |
if( ! $instance ) { | |
$instance = new self(); | |
} | |
return $instance; | |
} | |
public function actions() { | |
add_action( 'tour_grid_head', [$this, 'render_tour_destination'], 10 ); | |
add_action( 'tour_grid_head', [$this, 'reder_tour_title'], 20 ); | |
add_action( 'tour_grid_review', [$this, 'render_tour_grid_star_rating'], 10 ); | |
add_action( 'tour_grid_review', [$this, 'render_tour_grid_review_count'], 20 ); | |
add_action( 'tour_grid_bottom', [$this, 'render_tour_grid_meta_info'], 10 ); | |
add_action( 'tour_grid_bottom', [$this, 'render_tour_grid_price'], 20 ); | |
add_action( 'single_tour_price', [$this, 'render_tour_grid_price'], 20 ); | |
add_action( 'single_tour_review', [$this, 'render_tour_grid_review_count'], 20 ); | |
add_action( 'single_tour_review', [$this, 'render_tour_grid_star_rating'], 10 ); | |
add_action( 'tour_detail_meta', [$this, 'render_tour_detail_meta'], 10 ); | |
} | |
public function render_tour_destination() { | |
global $post; | |
$destination_name = get_the_terms( $post->ID, 'destination' ); | |
if ( $destination_name ) { | |
printf( '<p>%s</p>', esc_html( $destination_name[0]->name ) ); | |
} | |
} | |
public function reder_tour_title() { | |
printf( '<h4><a href="%s">%s</a></h4>', get_the_permalink(), get_the_title() ); | |
} | |
private function tour_grid_review_query() { | |
global $post; | |
$likeData = '"xs_post_id":"' . $post->ID . '"'; | |
$reviewArguments = array( | |
'post_type' => 'xs_review', | |
'meta_query' => array( | |
array( | |
'key' => 'xs_public_review_data', | |
'value' => '' . $likeData . '', | |
'compare' => 'LIKE', | |
), | |
), | |
); | |
$reviewQuery = new \WP_Query( $reviewArguments ); | |
return $reviewQuery; | |
} | |
public function render_tour_grid_star_rating() { | |
$rating = get_post_meta( get_the_ID(), 'tl_tour_rating', true ); | |
$html = ''; | |
$html .= '<div class="ft-card__star"><div class="display-star-rating">'; | |
for ( $i = 0; $i < 5; $i++ ) { | |
$checked = ''; | |
if ( $rating > 0 ) { | |
$checked = ( $i < $rating ) ? 'checked' : ''; | |
} | |
$html .= '<i class="fas fa-star ' . esc_attr( $checked ) . ' "></i>'; | |
} | |
$html .= '</div></div>'; | |
printf( $html ); | |
} | |
public function render_tour_grid_review_count() { | |
$review_data = $this->tour_grid_review_query(); | |
$totalReviews = isset( $review_data->post_count ) ? $review_data->post_count : 0; | |
$review_text = ( $totalReviews == 1 ) ? __( 'Review', 'travelux' ) : __( 'Reviews', 'travelux' ); | |
printf( '<div class="ft-card__review">%d %s</div>', esc_html( $totalReviews ), esc_html( $review_text ) ); | |
} | |
public function render_tour_grid_meta_info() { | |
$tour_duration = get_terms( array( 'taxonomy' => 'duration', 'hide_empty' => false ) ); | |
$age_restrictions = get_post_meta( get_the_ID(), 'tl_tour_age_restrictions', true ); | |
$metaInfo = ''; | |
if ( $tour_duration ) { | |
$metaInfo .= sprintf( '<p>%s</p>', esc_html( $tour_duration[0]->name ) ); | |
} | |
if ( $age_restrictions ) { | |
$metaInfo .= sprintf( '<p>%s</p>', esc_html( $age_restrictions ) ); | |
} | |
printf( '<div class="ft-card__left">%s</div>', $metaInfo ); | |
} | |
public function render_tour_grid_price() { | |
$product_id = get_post_meta( get_the_ID(), 'tl_tour_code', true ); | |
if ( $product_id && class_exists( 'WooCommerce' ) ) { | |
$product = wc_get_product( $product_id ); | |
if ( $product->is_type( 'variable' ) ) { | |
$variableProductPrices = $product->get_available_variations(); | |
$min_price = $product->get_variation_price( 'min', true ); | |
foreach ( $variableProductPrices as $value ) { | |
$max_price[] = $value['display_price']; | |
} | |
$priceMarkup = sprintf( '<span class="tf-card__price"><span class="tf-card__symbol">%s</span>%d</span>', | |
get_woocommerce_currency_symbol(), $min_price ); | |
} else { | |
$priceMarkup = sprintf( '<span class="tf-card__price"><span class="tf-card__symbol">%s</span>%d</span>', | |
get_woocommerce_currency_symbol(), $product->get_regular_price() ); | |
} | |
printf( '<div class="ft-card__right">%s</div>', $priceMarkup ); | |
} | |
} | |
public function render_tour_detail_meta() { | |
global $post; | |
$meta_data['duration'] = get_post_meta( get_the_ID(), 'tl_tour_duration', true ); | |
$meta_data['age_limit'] = get_post_meta( get_the_ID(), 'tl_tour_age_restrictions', true ); | |
$get_group_size = get_post_meta( get_the_ID(), 'tl_tour_group_size', true ); | |
if ( '' != $get_group_size ) { | |
$meta_data['group_size'] = get_post_meta( get_the_ID(), 'tl_tour_group_size', true ) . __( ' Peoples', 'travelux' ); | |
} | |
$tour_types = wp_get_post_terms( $post->ID, 'tour_type' ); | |
$meta_data['tour_type'] = ( $tour_types ) ? $tour_types[0]->name : ''; | |
$meta_data['start_date'] = get_post_meta( get_the_ID(), 'tl_tour_start_date', true ); | |
$meta_string = ''; | |
foreach ( $meta_data as $key => $value ) { | |
if ( '' != $value ) { | |
$meta_string .= sprintf( '<div class="tour-detail__meta-infobox">%s</div>', esc_html( $value ) ); | |
} | |
} | |
( '' != $meta_string ) ? printf( '<div class="tour-detail__meta">%s</div>', $meta_string ) : ''; | |
} | |
} | |
function travelux_render_tour_item() { | |
return Travelux_Tour_Render::init(); | |
} | |
travelux_render_tour_item(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment