| 1 |
<?php |
| 2 |
use SureCart\Support\Currency; |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
class ESHB_Core { |
| 5 |
|
| 6 |
private static $_instance = null; |
| 7 |
|
| 8 |
public static function instance() { |
| 9 |
|
| 10 |
if ( is_null( self::$_instance ) ) { |
| 11 |
self::$_instance = new self(); |
| 12 |
} |
| 13 |
return self::$_instance; |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
public function __construct() {} |
| 18 |
|
| 19 |
public function eshb_send_html_email($to, $subject, $message, $from_name = 'reactheme.com/easyhotel', $from_email = 'rubel.reacthemes@gmail.com') { |
| 20 |
|
| 21 |
require_once( trailingslashit( ABSPATH ) .'wp-load.php' ); |
| 22 |
|
| 23 |
if (!function_exists('wp_mail')) { |
| 24 |
return false; |
| 25 |
} |
| 26 |
|
| 27 |
// Guard the global function declaration. Without this, calling |
| 28 |
// this method twice in the same request (e.g. customer + admin |
| 29 |
// emails) raises a fatal "Cannot redeclare function" error. |
| 30 |
if ( ! function_exists( 'eshb_html_email_filter_calback' ) ) { |
| 31 |
function eshb_html_email_filter_calback(){ |
| 32 |
return 'text/html'; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
// Set content type to HTML |
| 37 |
add_filter('wp_mail_content_type', 'eshb_html_email_filter_calback'); |
| 38 |
|
| 39 |
// Set email headers |
| 40 |
$headers = array(); |
| 41 |
$headers[] = "From: {$from_name} <{$from_email}>"; |
| 42 |
$headers[] = "Reply-To: {$from_email}"; |
| 43 |
|
| 44 |
// Send email |
| 45 |
$sent = wp_mail($to, $subject, $message, $headers); |
| 46 |
|
| 47 |
// Remove filter to avoid conflicts |
| 48 |
remove_filter('wp_mail_content_type', 'eshb_html_email_filter_calback'); |
| 49 |
|
| 50 |
//return $sent; // Returns true if sent, false if failed |
| 51 |
return $sent; |
| 52 |
} |
| 53 |
|
| 54 |
public function get_eshb_currency_symbol(){ |
| 55 |
|
| 56 |
$eshb_settings = get_option( 'eshb_settings' ,[]); |
| 57 |
$booking_type = isset($eshb_settings['booking-type']) ? $eshb_settings['booking-type'] : ''; |
| 58 |
|
| 59 |
if( !empty($eshb_settings['currency_symbol']) ){ |
| 60 |
$currency_symbol = $eshb_settings['currency_symbol']; |
| 61 |
}else if($booking_type == 'woocommerce' && class_exists('woocommerce')){ |
| 62 |
$currency_symbol = get_woocommerce_currency_symbol(); |
| 63 |
}else if($booking_type == 'surecart' && class_exists('SureCart')){ |
| 64 |
$currency = new Currency(); |
| 65 |
$currency_symbol = $currency->getCurrencySymbol(); |
| 66 |
}else { |
| 67 |
$currency_symbol = '$'; |
| 68 |
} |
| 69 |
|
| 70 |
$currency_symbol = apply_filters('eshb_currency_symbol', $currency_symbol, $booking_type); |
| 71 |
|
| 72 |
return $currency_symbol; |
| 73 |
} |
| 74 |
|
| 75 |
public function get_eshb_currency_position(){ |
| 76 |
|
| 77 |
$currency_position = 'left'; |
| 78 |
|
| 79 |
$eshb_settings = get_option( 'eshb_settings' ,[]); |
| 80 |
if(isset($eshb_settings['currency_position']) && !empty($eshb_settings['currency_position'])){ |
| 81 |
$currency_position = $eshb_settings['currency_position']; |
| 82 |
} |
| 83 |
|
| 84 |
return $currency_position; |
| 85 |
} |
| 86 |
|
| 87 |
public function get_eshb_default_start_end_date(){ |
| 88 |
$today_date = gmdate('Y-m-d'); // Get today's date |
| 89 |
|
| 90 |
// Create a DateTime object from today's date |
| 91 |
$date = new DateTime($today_date); |
| 92 |
|
| 93 |
// Add one day |
| 94 |
$date->modify('+1 day'); |
| 95 |
|
| 96 |
// Get the new date in 'Y-m-d' format |
| 97 |
$tomorrow_date = $date->format('Y-m-d'); |
| 98 |
|
| 99 |
return array( |
| 100 |
'start_date' => $today_date, |
| 101 |
'end_date' => $tomorrow_date |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
public function has_upcoming_or_current_session_price($accomodation_id, $start_date, $end_date, $night = 1, $adult = 1, $children = '') { |
| 107 |
$metaboxes = get_post_meta($accomodation_id, 'eshb_accomodation_metaboxes', true); |
| 108 |
$regular_price = !empty($metaboxes['regular_price']) ? $metaboxes['regular_price'] : 0; |
| 109 |
|
| 110 |
// Get all sessions |
| 111 |
$qargs = array( |
| 112 |
'post_type' => 'eshb_session', |
| 113 |
'post_status' => 'publish', |
| 114 |
'posts_per_page' => -1, |
| 115 |
); |
| 116 |
$query = new WP_Query($qargs); |
| 117 |
|
| 118 |
$sessions = []; |
| 119 |
|
| 120 |
if ($query->have_posts()) { |
| 121 |
while ($query->have_posts()) { |
| 122 |
$query->the_post(); |
| 123 |
$post_id = get_the_ID(); |
| 124 |
$metaboxes = maybe_unserialize(get_post_meta($post_id, 'eshb_session_metaboxes', true)); |
| 125 |
|
| 126 |
if (empty($metaboxes['start_date']) || empty($metaboxes['end_date'])) continue; |
| 127 |
|
| 128 |
$sessions[] = [ |
| 129 |
'id' => $post_id, |
| 130 |
'start_date' => $metaboxes['start_date'], |
| 131 |
'end_date' => $metaboxes['end_date'], |
| 132 |
'price' => $metaboxes['session_price'] ?? $regular_price, |
| 133 |
'accomodation_ids' => $metaboxes['accomodation_ids'] ?? [], |
| 134 |
'longstay_pricing' => $metaboxes['longstay_pricing'] ?? [], |
| 135 |
'variable_pricing' => $metaboxes['variable_pricing'] ?? [], |
| 136 |
'days' => $metaboxes['days'] ?? [], |
| 137 |
]; |
| 138 |
} |
| 139 |
wp_reset_postdata(); |
| 140 |
} |
| 141 |
|
| 142 |
// Create date range (exclude checkout date if multi-day) |
| 143 |
$period = new DatePeriod( |
| 144 |
new DateTime($start_date), |
| 145 |
new DateInterval('P1D'), |
| 146 |
(new DateTime($start_date) == new DateTime($end_date)) |
| 147 |
? (new DateTime($end_date))->modify('+1 day') |
| 148 |
: new DateTime($end_date) |
| 149 |
); |
| 150 |
|
| 151 |
$total_nights = iterator_count($period); |
| 152 |
|
| 153 |
// Initialize flags |
| 154 |
$longstay_applied = false; |
| 155 |
$variable_applied = false; |
| 156 |
$session_price_applied = false; |
| 157 |
|
| 158 |
foreach ($period as $day) { |
| 159 |
$current_date = $day->format('Y-m-d'); |
| 160 |
$current_day_name = strtolower($day->format('l')); |
| 161 |
foreach ($sessions as $session) { |
| 162 |
|
| 163 |
if(empty($session['accomodation_ids'])){ |
| 164 |
continue; |
| 165 |
} |
| 166 |
|
| 167 |
if (!empty($session['accomodation_ids']) && !in_array($accomodation_id, $session['accomodation_ids'])) { |
| 168 |
continue; |
| 169 |
} |
| 170 |
$session_days = !empty($session['days']) ? $session['days'] : ['saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday']; |
| 171 |
if(is_array($session['days']) && in_array('all', $session['days'])){ |
| 172 |
$session_days = ['saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday']; |
| 173 |
} |
| 174 |
if ($current_date >= $session['start_date'] && $current_date <= $session['end_date'] && in_array($current_day_name, $session_days)) { |
| 175 |
|
| 176 |
// 1. Longstay Pricing |
| 177 |
if (!empty($session['longstay_pricing']) && $total_nights >= 1) { |
| 178 |
// reverse the longstay_pricing array |
| 179 |
$session['longstay_pricing'] = array_reverse($session['longstay_pricing']); |
| 180 |
foreach ($session['longstay_pricing'] as $ls) { |
| 181 |
if (!empty($ls['night']) && $total_nights >= $ls['night']) { |
| 182 |
$longstay_applied = true; |
| 183 |
break 2; // early return since found |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
// 2. Variable Pricing |
| 189 |
if (!empty($session['variable_pricing'])) { |
| 190 |
foreach ($session['variable_pricing'] as $vp) { |
| 191 |
$vp_adult = $vp['adult_quantity'] ?? 0; |
| 192 |
$vp_children = $vp['children_quantity'] ?? 0; |
| 193 |
if ($vp_adult == $adult && $vp_children == $children) { |
| 194 |
$variable_applied = true; |
| 195 |
break 2; |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
// 3. Session Price (basic price) |
| 201 |
if (!empty($session['price']) && $session['price'] != $regular_price) { |
| 202 |
$session_price_applied = true; |
| 203 |
break 2; |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
if ($longstay_applied || $variable_applied || $session_price_applied) { |
| 210 |
return true; |
| 211 |
} |
| 212 |
|
| 213 |
return false; |
| 214 |
} |
| 215 |
|
| 216 |
public function get_eshb_price_by_session($accomodation_id, $start_date, $end_date, $night = '', $adult = '', $children = '') { |
| 217 |
|
| 218 |
$metaboxes = get_post_meta($accomodation_id, 'eshb_accomodation_metaboxes', true); |
| 219 |
$regular_price = !empty($metaboxes['regular_price']) ? $metaboxes['regular_price'] : 0; |
| 220 |
|
| 221 |
|
| 222 |
// Get all sessions |
| 223 |
$qargs = array( |
| 224 |
'post_type' => 'eshb_session', |
| 225 |
'post_status' => 'publish', |
| 226 |
'posts_per_page' => -1, |
| 227 |
); |
| 228 |
$query = new WP_Query($qargs); |
| 229 |
|
| 230 |
$sessions = []; |
| 231 |
|
| 232 |
if ($query->have_posts()) { |
| 233 |
while ($query->have_posts()) { |
| 234 |
$query->the_post(); |
| 235 |
$post_id = get_the_ID(); |
| 236 |
$metaboxes = maybe_unserialize(get_post_meta($post_id, 'eshb_session_metaboxes', true)); |
| 237 |
|
| 238 |
if (empty($metaboxes['start_date']) || empty($metaboxes['end_date'])) continue; |
| 239 |
|
| 240 |
$sessions[] = [ |
| 241 |
'id' => $post_id, |
| 242 |
'start_date' => $metaboxes['start_date'], |
| 243 |
'end_date' => $metaboxes['end_date'], |
| 244 |
'price' => $metaboxes['session_price'] ?? $regular_price, |
| 245 |
'accomodation_ids' => $metaboxes['accomodation_ids'] ?? [], |
| 246 |
'longstay_pricing' => $metaboxes['longstay_pricing'] ?? [], |
| 247 |
'variable_pricing' => $metaboxes['variable_pricing'] ?? [], |
| 248 |
'days' => $metaboxes['days'] ?? [], |
| 249 |
]; |
| 250 |
} |
| 251 |
wp_reset_postdata(); |
| 252 |
} |
| 253 |
|
| 254 |
// Create date range (exclude checkout date if multi-day) |
| 255 |
$period = new DatePeriod( |
| 256 |
new DateTime($start_date), |
| 257 |
new DateInterval('P1D'), |
| 258 |
(new DateTime($start_date) == new DateTime($end_date)) |
| 259 |
? (new DateTime($end_date))->modify('+1 day') // same-day booking |
| 260 |
: new DateTime($end_date) // exclude checkout |
| 261 |
); |
| 262 |
|
| 263 |
$total_nights = iterator_count($period); |
| 264 |
$per_day_prices = []; |
| 265 |
|
| 266 |
|
| 267 |
foreach ($period as $day) { |
| 268 |
$current_date = $day->format('Y-m-d'); |
| 269 |
$current_day_name = strtolower($day->format('l')); |
| 270 |
$matched_price = $regular_price; |
| 271 |
|
| 272 |
foreach ($sessions as $session) { |
| 273 |
|
| 274 |
|
| 275 |
if(empty($session['accomodation_ids'])){ |
| 276 |
continue; |
| 277 |
} |
| 278 |
|
| 279 |
if (!empty($session['accomodation_ids']) && !in_array($accomodation_id, $session['accomodation_ids'])) { |
| 280 |
continue; |
| 281 |
} |
| 282 |
|
| 283 |
$session_days = !empty($session['days']) ? $session['days'] : ['saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday']; |
| 284 |
if(in_array('all', $session_days)){ |
| 285 |
$session_days = ['saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday']; |
| 286 |
} |
| 287 |
|
| 288 |
if ($current_date >= $session['start_date'] && $current_date <= $session['end_date'] && in_array($current_day_name, $session_days)) { |
| 289 |
|
| 290 |
// 1. Longstay Pricing (highest priority) |
| 291 |
$longstay_applied = false; |
| 292 |
|
| 293 |
|
| 294 |
if (!empty($session['longstay_pricing']) && $total_nights >= 1) { |
| 295 |
$session['longstay_pricing'] = array_reverse($session['longstay_pricing']); |
| 296 |
foreach ($session['longstay_pricing'] as $ls) { |
| 297 |
if (!empty($ls['night']) && $total_nights >= $ls['night']) { |
| 298 |
$matched_price = floatval($ls['price']); |
| 299 |
$longstay_applied = true; |
| 300 |
break; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
if ($longstay_applied) break; |
| 307 |
|
| 308 |
// 2. Variable Pricing |
| 309 |
$variable_applied = false; |
| 310 |
if (!empty($session['variable_pricing'])) { |
| 311 |
foreach ($session['variable_pricing'] as $vp) { |
| 312 |
$vp_adult = $vp['adult_quantity'] ?? 0; |
| 313 |
$vp_children = $vp['children_quantity'] ?? 0; |
| 314 |
if ($vp_adult == $adult && $vp_children == $children) { |
| 315 |
$matched_price = floatval($vp['price']); |
| 316 |
$variable_applied = true; |
| 317 |
break; |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
if ($variable_applied) break; |
| 323 |
|
| 324 |
// 3. Session price |
| 325 |
$matched_price = floatval($session['price']); |
| 326 |
break; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
$per_day_prices[] = $matched_price; |
| 334 |
} |
| 335 |
|
| 336 |
$total_price = array_sum($per_day_prices); |
| 337 |
$total_price = apply_filters('eshb_session_price', $total_price); |
| 338 |
return $total_price; |
| 339 |
} |
| 340 |
|
| 341 |
public function get_eshb_price($start_date = null, $end_date = null, $accomodation_id = null, $session_price = true, $night = '', $adult = '', $children = '', $sale = true, $single_day = true) { |
| 342 |
|
| 343 |
if($start_date == null || empty($start_date) || $end_date == null || empty($end_date)){ |
| 344 |
$dates = $this->get_eshb_default_start_end_date(); |
| 345 |
$start_date = $dates['start_date']; |
| 346 |
$end_date = $dates['end_date']; |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
if( $accomodation_id == null || empty($accomodation_id) ){ |
| 351 |
global $post; |
| 352 |
$accomodation_id = $post->ID; |
| 353 |
} |
| 354 |
$price = ''; |
| 355 |
$metaboxes = get_post_meta($accomodation_id, 'eshb_accomodation_metaboxes', true); |
| 356 |
|
| 357 |
$regular_price = !empty($metaboxes['regular_price']) ? $metaboxes['regular_price'] : 0; |
| 358 |
$sale_price = !empty($metaboxes['sale_price']) ? $metaboxes['sale_price'] : 0; |
| 359 |
|
| 360 |
if($single_day){ |
| 361 |
$single_day_price = apply_filters( 'eshb_single_day_price', 0, $accomodation_id); |
| 362 |
$eshb_single_day_sale_price = apply_filters( 'eshb_single_day_sale_price', 0, $accomodation_id); |
| 363 |
$regular_price = !empty($single_day_price) ? $single_day_price : $regular_price; |
| 364 |
$sale_price = !empty($eshb_single_day_sale_price) ? $eshb_single_day_sale_price : $sale_price; |
| 365 |
} |
| 366 |
|
| 367 |
$price = $regular_price; |
| 368 |
|
| 369 |
if($sale == true){ |
| 370 |
$price = !empty($sale_price) ? $sale_price : $regular_price; |
| 371 |
} |
| 372 |
|
| 373 |
if($session_price == true){ |
| 374 |
$session_price = $this->get_eshb_price_by_session($accomodation_id, $start_date, $end_date, $night, $adult, $children); |
| 375 |
$price = !empty($session_price) ? $session_price : $price; |
| 376 |
} |
| 377 |
|
| 378 |
$price = apply_filters('eshb_price', $price); |
| 379 |
|
| 380 |
return $price; |
| 381 |
} |
| 382 |
|
| 383 |
public function eshb_price ($price, $currency_symbol = NULL){ |
| 384 |
|
| 385 |
if( empty($currency_symbol) ) { |
| 386 |
// Get the currency symbol |
| 387 |
$currency_symbol = $this->get_eshb_currency_symbol(); |
| 388 |
} |
| 389 |
|
| 390 |
// Prepare the price HTML, with or without currency symbol |
| 391 |
$currency_position = $this->get_eshb_currency_position(); |
| 392 |
|
| 393 |
$eshb_settings = get_option('eshb_settings'); |
| 394 |
$booking_type = isset($eshb_settings['booking-type']) ? $eshb_settings['booking-type'] : 'woocommerce'; |
| 395 |
|
| 396 |
|
| 397 |
if($booking_type == 'woocommerce' && class_exists('WooCommerce')){ |
| 398 |
$price = wc_price($price, []); |
| 399 |
return $price; |
| 400 |
}else{ |
| 401 |
if(!empty($price)){ |
| 402 |
$price = number_format($price,2); |
| 403 |
} |
| 404 |
$price_html = $currency_symbol . $price; |
| 405 |
if($currency_position == 'right') { |
| 406 |
$price_html = $price . $currency_symbol; |
| 407 |
} |
| 408 |
} |
| 409 |
return $price_html; |
| 410 |
} |
| 411 |
|
| 412 |
public function get_eshb_price_html($start_date = null, $end_date = null, $accomodation_id = null, $show_currency = true, $include_single_day_price = true, $include_day_wise_price = true, $include_session_price = true, $format = 'sale') { |
| 413 |
|
| 414 |
if($start_date == null || empty($start_date) || $end_date == null || empty($end_date)){ |
| 415 |
$dates = $this->get_eshb_default_start_end_date(); |
| 416 |
$start_date = $dates['start_date']; |
| 417 |
$end_date = $dates['end_date']; |
| 418 |
} |
| 419 |
|
| 420 |
$eshb_settings = get_option('eshb_settings'); |
| 421 |
$booking_type = isset($eshb_settings['booking-type']) ? $eshb_settings['booking-type'] : 'woocommerce'; |
| 422 |
|
| 423 |
$is_wc_price = false; |
| 424 |
if($booking_type == 'woocommerce' && class_exists('WooCommerce')){ |
| 425 |
$is_wc_price = true; |
| 426 |
} |
| 427 |
|
| 428 |
// Get the currency symbol |
| 429 |
$currency_symbol = $this->get_eshb_currency_symbol(); |
| 430 |
|
| 431 |
// Get price values from different sources |
| 432 |
$regular_price = $this->get_eshb_price($start_date, $end_date, $accomodation_id, false, '', '', '', false); |
| 433 |
$sale_price = $this->get_eshb_price($start_date, $end_date, $accomodation_id, false, '', '', '', true); |
| 434 |
|
| 435 |
$prices = [ |
| 436 |
'regular_price' => $regular_price, |
| 437 |
'sale_price' => $sale_price |
| 438 |
]; |
| 439 |
|
| 440 |
$day_wise_price = $this->get_eshb_day_wise_price($start_date, $end_date, $accomodation_id, false, 1, 1, 0); |
| 441 |
|
| 442 |
$has_session_price = $this->has_upcoming_or_current_session_price($accomodation_id, $start_date, $end_date, 1, 1, 0); |
| 443 |
|
| 444 |
if ($has_session_price && $include_session_price) { |
| 445 |
$include_session_price = true; |
| 446 |
} else { |
| 447 |
$include_session_price = false; |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
$session_price = $this->get_eshb_price_by_session($accomodation_id, $start_date, $end_date); |
| 452 |
$single_day_price = apply_filters( 'eshb_single_day_price', 0, $accomodation_id ); |
| 453 |
|
| 454 |
// Determine the price to use |
| 455 |
if ($include_session_price === true && !empty($session_price) && ($session_price !== $regular_price && $session_price !== $sale_price)) { |
| 456 |
$price = $session_price; |
| 457 |
} elseif ($include_day_wise_price === true && !empty($day_wise_price) && ($day_wise_price !== $regular_price && $day_wise_price !== $sale_price)) { |
| 458 |
$price = $day_wise_price; |
| 459 |
} elseif ($include_single_day_price === true && !empty($single_day_price) && ($single_day_price !== $regular_price && $single_day_price !== $sale_price)) { |
| 460 |
$price = $single_day_price; |
| 461 |
} else { |
| 462 |
if(!empty($sale_price ) && $sale_price !== $regular_price){ |
| 463 |
if($format == 'sale'){ |
| 464 |
$price = $prices; |
| 465 |
}else{ |
| 466 |
$price = $sale_price; |
| 467 |
} |
| 468 |
}else{ |
| 469 |
$price = $regular_price; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
// Return empty string if price is empty |
| 475 |
if (empty($price)) { |
| 476 |
return ''; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
// Prepare the price HTML, with or without currency symbol |
| 481 |
$currency_position = $this->get_eshb_currency_position(); |
| 482 |
$price_html = ''; |
| 483 |
$price = apply_filters('eshb_price_html_price', $price); |
| 484 |
|
| 485 |
if ( is_array( $price ) ) { |
| 486 |
// Regular & Sale Price |
| 487 |
$regular_price = $price['regular_price']; |
| 488 |
$sale_price = $price['sale_price']; |
| 489 |
|
| 490 |
if ( $show_currency && !$is_wc_price ) { |
| 491 |
if ( $currency_position == 'right' ) { |
| 492 |
$regular_price = $regular_price . $currency_symbol; |
| 493 |
$sale_price = $sale_price . $currency_symbol; |
| 494 |
} else { |
| 495 |
$regular_price = $currency_symbol . $regular_price; |
| 496 |
$sale_price = $currency_symbol . $sale_price; |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
if($is_wc_price){ |
| 501 |
$regular_price = wc_price($regular_price, []); |
| 502 |
$sale_price = wc_price($sale_price, []); |
| 503 |
} |
| 504 |
|
| 505 |
$price_html = '<span class="eshb-price">'; |
| 506 |
$price_html .= '<del aria-hidden="true"><span class="eshb-price-amount amount"><bdi>' . $regular_price . '</bdi></span></del>'; |
| 507 |
$price_html .= '<span class="screen-reader-text">Original price was: ' . $regular_price . '.</span>'; |
| 508 |
$price_html .= '<ins aria-hidden="true"><span class="eshb-price-amount amount"><bdi>' . $sale_price . '</bdi></span></ins>'; |
| 509 |
$price_html .= '<span class="screen-reader-text">Current price is: ' . $sale_price . '.</span>'; |
| 510 |
$price_html .= '</span>'; |
| 511 |
|
| 512 |
} else { |
| 513 |
// Single Price (No Sale) |
| 514 |
$single_price = $price; |
| 515 |
|
| 516 |
if ( $show_currency && !$is_wc_price) { |
| 517 |
if ( $currency_position == 'right' ) { |
| 518 |
$single_price = $single_price . $currency_symbol; |
| 519 |
} else { |
| 520 |
$single_price = $currency_symbol . $single_price; |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
if($is_wc_price){ |
| 525 |
$single_price = wc_price($single_price, []); |
| 526 |
} |
| 527 |
$price_html = '<span class="eshb-price">'; |
| 528 |
$price_html .= '<span class="eshb-price-amount amount"><bdi>' . $single_price . '</bdi></span>'; |
| 529 |
$price_html .= '</span>'; |
| 530 |
} |
| 531 |
|
| 532 |
$price_html = apply_filters('eshb_price_html', $price_html, $price); |
| 533 |
return $price_html; |
| 534 |
} |
| 535 |
|
| 536 |
public function get_eshb_day_names_from_date_ranges($start_date, $end_date){ |
| 537 |
$period = new DatePeriod( |
| 538 |
new DateTime($start_date), |
| 539 |
new DateInterval('P1D'), |
| 540 |
new DateTime($end_date) // Stop before the end date |
| 541 |
); |
| 542 |
|
| 543 |
$dayNames = []; |
| 544 |
foreach ($period as $date) { |
| 545 |
$dayNames[] = strtolower($date->format('l')); // Convert to lowercase |
| 546 |
} |
| 547 |
|
| 548 |
return $dayNames; |
| 549 |
} |
| 550 |
|
| 551 |
public function get_eshb_day_wise_price($start_date, $end_date, $accomodation_id, $fallback_regular_price = true, $night = '', $adult = '', $children = ''){ |
| 552 |
|
| 553 |
if($start_date == null || empty($start_date) || $end_date == null || empty($end_date) || $accomodation_id == null || empty($accomodation_id)) return 0; |
| 554 |
|
| 555 |
|
| 556 |
$regular_price = $fallback_regular_price == true ? $this->get_eshb_price($start_date, $end_date, $accomodation_id, false, $night, $adult, $children,) : 0; |
| 557 |
|
| 558 |
if ($start_date === $end_date) { |
| 559 |
// Add 1 day to end date if they are the same |
| 560 |
$end_date = gmdate('Y-m-d', strtotime($end_date . ' +1 day')); |
| 561 |
} |
| 562 |
|
| 563 |
$period = new DatePeriod( |
| 564 |
new DateTime($start_date), |
| 565 |
new DateInterval('P1D'), |
| 566 |
new DateTime($end_date) // Stop before the end date |
| 567 |
); |
| 568 |
|
| 569 |
$dayNames = []; |
| 570 |
$days_count = 0; |
| 571 |
foreach ($period as $date) { |
| 572 |
$dayNames[] = strtolower($date->format('l')); // Convert to lowercase |
| 573 |
$days_count++; |
| 574 |
} |
| 575 |
|
| 576 |
// If only one day is selected, return the price for that day |
| 577 |
// if(is_archive() || isset($_GET['eshb_global_nonce_action']) || isset($_GET['eshb_search_nonce'])){ |
| 578 |
// $todayName = strtolower(gmdate('l')); |
| 579 |
// //remove all day names from the array but today's name |
| 580 |
// $dayNames = array_filter($dayNames, function($day) use ($todayName) { |
| 581 |
// return $day === $todayName; |
| 582 |
// }); |
| 583 |
// } |
| 584 |
|
| 585 |
$metaboxes = get_post_meta($accomodation_id, 'eshb_accomodation_metaboxes', true); |
| 586 |
$day_wise_price = isset($metaboxes['day_wise_price']) && !empty($metaboxes['day_wise_price']) ? $metaboxes['day_wise_price'] : ''; |
| 587 |
|
| 588 |
$price_by_day = 0; |
| 589 |
|
| 590 |
if(!empty($day_wise_price) && isset($day_wise_price[0]) && !empty($day_wise_price[0])){ |
| 591 |
$day_wise_price = $day_wise_price[0]; |
| 592 |
foreach ($dayNames as $key => $day) { |
| 593 |
if( !empty($day_wise_price[$day]) ){ |
| 594 |
$price_by_day += $day_wise_price[$day]; |
| 595 |
}else{ |
| 596 |
$price_by_day += $regular_price; |
| 597 |
} |
| 598 |
|
| 599 |
} |
| 600 |
}else{ |
| 601 |
|
| 602 |
$price_by_day = $regular_price * $days_count; |
| 603 |
|
| 604 |
} |
| 605 |
$price_by_day = apply_filters('eshb_day_wise_price', $price_by_day); |
| 606 |
return $price_by_day; |
| 607 |
} |
| 608 |
} |
| 609 |
ESHB_Core::instance(); |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|