| 1 |
<?php |
| 2 |
/** |
| 3 |
* Discount and Deals Shortcode Template |
| 4 |
* |
| 5 |
* @package Yatra |
| 6 |
* @var array $trips Array of trip objects with discounts |
| 7 |
* @var array $atts Shortcode attributes |
| 8 |
*/ |
| 9 |
|
| 10 |
// Prevent direct access |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
$columns = (int) $atts['columns']; |
| 16 |
$column_class = 'yatra-discount-grid-' . min(max($columns, 1), 4); |
| 17 |
$yatra_deals_dp_overlay = true; |
| 18 |
if (function_exists('yatra_get_dynamic_pricing_display_flags')) { |
| 19 |
$yatra_deals_dp_overlay = !empty(yatra_get_dynamic_pricing_display_flags()['show_savings_badge']); |
| 20 |
} |
| 21 |
?> |
| 22 |
|
| 23 |
<div class="yatra-discount-shortcode"> |
| 24 |
<div class="yatra-discount-header"> |
| 25 |
<h2 class="yatra-discount-title"><?php esc_html_e('Special Deals & Discounts', 'yatra'); ?></h2> |
| 26 |
<?php if (!empty($trips)): ?> |
| 27 |
<div class="yatra-discount-count"> |
| 28 |
<?php |
| 29 |
printf( |
| 30 |
/* translators: %d: number of deals currently available. */ |
| 31 |
_nx('%d Deal Available', '%d Deals Available', count($trips), 'deal count', 'yatra'), |
| 32 |
(int) count($trips) |
| 33 |
); |
| 34 |
?> |
| 35 |
</div> |
| 36 |
<?php endif; ?> |
| 37 |
</div> |
| 38 |
|
| 39 |
<?php if (!empty($trips)): ?> |
| 40 |
<div class="yatra-discount-grid <?php echo esc_attr($column_class); ?>"> |
| 41 |
<?php foreach ($trips as $trip): ?> |
| 42 |
<div class="yatra-discount-card"> |
| 43 |
<?php |
| 44 |
// Load the trip-listing-card.php template (same as tour shortcode) |
| 45 |
include YATRA_PLUGIN_PATH . 'templates/trip-listing-card.php'; |
| 46 |
?> |
| 47 |
|
| 48 |
<!-- Discount Badge Overlay --> |
| 49 |
<?php if ($yatra_deals_dp_overlay && $trip->has_discount && !empty($trip->best_discount)): ?> |
| 50 |
<div class="yatra-discount-badge"> |
| 51 |
<?php |
| 52 |
printf( |
| 53 |
/* translators: %s: discount percentage */ |
| 54 |
esc_html__('%s%% OFF', 'yatra'), |
| 55 |
esc_html($trip->best_discount['value']) |
| 56 |
); |
| 57 |
?> |
| 58 |
</div> |
| 59 |
<?php endif; ?> |
| 60 |
</div> |
| 61 |
<?php endforeach; ?> |
| 62 |
</div> |
| 63 |
|
| 64 |
<?php if (count($trips) >= (int) $atts['per_page']): ?> |
| 65 |
<div class="yatra-discount-more"> |
| 66 |
<a href="<?php echo esc_url(get_post_type_archive_link('trip')); ?>" class="yatra-btn yatra-btn-outline yatra-archive-card-cta"> |
| 67 |
<span><?php esc_html_e('View All Deals', 'yatra'); ?></span> |
| 68 |
<?php echo yatra_svg_icon('chevron-right', 'yatra-btn-icon'); ?> |
| 69 |
</a> |
| 70 |
</div> |
| 71 |
<?php endif; ?> |
| 72 |
<?php else: ?> |
| 73 |
<div class="yatra-discount-empty"> |
| 74 |
<div class="yatra-empty-icon"> |
| 75 |
<svg width="60" height="60" fill="currentColor" viewBox="0 0 20 20"> |
| 76 |
<path fill-rule="evenodd" d="M5 2a2 2 0 00-2 2v14l3.5-2 3.5 2 3.5-2 3.5 2V4a2 2 0 00-2-2H5zm2.5 3a1.5 1.5 0 100 3 1.5 1.5 0 000-3zm6.207.293a1 1 0 00-1.414 0l-6 6a1 1 0 101.414 1.414l6-6a1 1 0 000-1.414zM12.5 10a1.5 1.5 0 100 3 1.5 1.5 0 000-3z" clip-rule="evenodd" /> |
| 77 |
</svg> |
| 78 |
</div> |
| 79 |
<h3><?php esc_html_e('No Deals Available', 'yatra'); ?></h3> |
| 80 |
<p><?php esc_html_e('There are no special deals or discounts available at the moment. Check back soon for amazing offers!', 'yatra'); ?></p> |
| 81 |
<a href="<?php echo esc_url(get_post_type_archive_link('trip')); ?>" class="yatra-btn yatra-btn-primary yatra-archive-card-cta"> |
| 82 |
<?php echo yatra_svg_icon('globe', 'yatra-btn-icon'); ?> |
| 83 |
<span><?php esc_html_e('Browse All Trips', 'yatra'); ?></span> |
| 84 |
</a> |
| 85 |
</div> |
| 86 |
<?php endif; ?> |
| 87 |
</div> |
| 88 |
|