Skip to content

Instantly share code, notes, and snippets.

@asifpix
Created June 6, 2021 05:07
Show Gist options
  • Save asifpix/da7a18d65002ae03ee0fd30f7fc2a577 to your computer and use it in GitHub Desktop.
Save asifpix/da7a18d65002ae03ee0fd30f7fc2a577 to your computer and use it in GitHub Desktop.
It will display the lowest price of variable products.
<?php
trait Ratings {
public function display_tour_grid_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 tour_grid_review_query() {
global $post;
$reviewPostType = 'xs_review';
$likeData = '"xs_post_id":"' . $post->ID . '"';
$reviewArguments = array(
'post_type' => $reviewPostType,
'meta_query' => array(
array(
'key' => 'xs_public_review_data',
'value' => '' . $likeData . '',
'compare' => 'LIKE',
),
),
);
$reviewQuery = new \WP_Query($reviewArguments);
return $reviewQuery;
}
public function display_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 static function display_tour_grid_review_count() {
global $post;
$reviewPostType = 'xs_review';
$likeData = '"xs_post_id":"' . $post->ID . '"';
$reviewArguments = array(
'post_type' => $reviewPostType,
'meta_query' => array(
array(
'key' => 'xs_public_review_data',
'value' => '' . $likeData . '',
'compare' => 'LIKE',
),
),
);
$review_data = new \WP_Query($reviewArguments);
$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 display_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 display_tour_grid_carousel_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(), round($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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment