Created
October 30, 2024 13:12
-
-
Save kartikparmar/77237680542cf45048f400f1511a1d1a to your computer and use it in GitHub Desktop.
Exclude the disabled weekdays and season with 100% discount from number of selected days
This file contains hidden or 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 | |
function bkap_selected_number_of_nights( $number, $checkin_date, $checkout_date, $product_id, $booking_settings ) { | |
$dates = bkap_common::bkap_get_betweendays( $checkin_date, $checkout_date, 'Y-m-d' ); | |
foreach ( $dates as $date ) { | |
$day = date( 'w', strtotime( $date ) ); | |
$weekday_name = 'booking_weekday_' . $day; | |
if ( '' === $booking_settings['booking_recurring'][$weekday_name] ) { | |
$number = $number - 1; | |
} | |
} | |
$number = bkap_selected_number_of_nights_seasonal( $number, $checkin_date, $checkout_date, $product_id, $booking_settings ); | |
return $number; | |
} | |
add_filter( 'bkap_selected_number_of_nights', 'bkap_selected_number_of_nights', 10, 5 ); | |
function bkap_consider_date_for_season( $consider, $date_value, $product_id, $booking_settings ) { | |
$day = gmdate( 'w', strtotime( $date_value ) ); | |
$weekday_name = 'booking_weekday_' . $day; | |
if ( '' === $booking_settings['booking_recurring'][ $weekday_name ] ) { | |
return false; | |
} | |
return $consider; | |
} | |
add_filter( 'bkap_consider_date_for_season', 'bkap_consider_date_for_season', 10, 4 ); | |
function bkap_selected_number_of_nights_seasonal( $number, $checkin_date, $checkout_date, $product_id, $booking_settings ) { | |
global $wpdb; | |
if ( isset( $booking_settings['booking_seasonal_pricing_enable'] ) && 'yes' === $booking_settings['booking_seasonal_pricing_enable'] ) { | |
if ( is_plugin_active( 'bkap-rental/rental.php' ) && isset( $booking_settings['booking_charge_per_day'] ) && $booking_settings['booking_charge_per_day'] == 'on' ) { | |
$bkap_date_range = bkap_common::bkap_get_betweendays_when_flat( $checkin_date, $checkout_date, $product_id, 'Y-m-d' ); | |
} else { | |
$bkap_date_range = bkap_common::bkap_get_betweendays( $checkin_date, $checkout_date, 'Y-m-d' ); | |
} | |
$query = 'SELECT * FROM `' . $wpdb->prefix . "booking_seasonal_pricing` WHERE post_id = '" . $product_id . "'"; | |
$results = $wpdb->get_results( $query ); | |
$current_user = wp_get_current_user(); | |
$roles = $current_user->roles; | |
$role = array_shift( $roles ); | |
foreach ( $bkap_date_range as $date_key => $date_value ) { | |
foreach ( $results as $key => $val ) { | |
$season_start_date = $val->start_date; | |
$season_end_date = $val->end_date; | |
$user_roles = json_decode( $val->user_role ); | |
if ( $user_roles == '' || in_array( 'all', $user_roles, true ) || in_array( $role, $user_roles ) ) { | |
if ( $date_value >= $season_start_date && $date_value <= $season_end_date ) { | |
if ( 'percent' === $val->amount_or_percent && 'subtract' === $val->operator && '100' == $val->price ) { | |
$number = $number - 1; | |
} | |
} | |
} | |
} | |
} | |
} | |
return $number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment