1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
<?php
class DFW_Deposits_For_Bookings {
public function __construct() {
add_action( 'bkap_js', array( &$this, 'dfw_get_booking_date' ), 10, 3 );
}
public static function dfw_add_ajax_for_bookings(){
if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'dfw_get_start_date' ):
do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
endif;
}
public function dfw_get_booking_date( $booking_date, $post_id, $addon_data){
$start_date = new DateTime( $booking_date );
DFW_Deposits_For_Bookings::dfw_disable_deposits( $booking_date, $post_id );
}
public static function dfw_disable_deposits( $booking_date, $post_id ) {
$enabled = DFW_Manage_Products::dfw_is_deposits_enabled( $post_id );
$plans = DFW_Manage_Plans::get_plans_for_product( $post_id );
if( empty( $plans ) ) {
return;
}
$booking_settings = get_post_meta( $post_id, 'woocommerce_booking_settings', true );
$is_booking_enabled = false;
if ( ( isset( $booking_settings['booking_enable_date'] ) && $booking_settings['booking_enable_date'] == "on" ) ) {
$is_booking_enabled = true;
}
$plan_schedule = $plans[0]->get_plan_schedule();
$booking_time = strtotime( $booking_date, current_time('timestamp'));
$current_date = date( 'd-m-Y', current_time( 'timestamp' ) );
array_shift( $plan_schedule );
$current_timestamp = current_time('timestamp');
foreach ( $plan_schedule as $row ) {
if( "before" == $row->plan_due ) {
$current_timestamp = strtotime( "-{$row->plan_interval_amount} {$row->plan_interval_time}", $booking_time );
}
$due_date = date( 'd-m-Y', $current_timestamp );
}
if( $due_date < $current_date ) {
if( $is_booking_enabled === true ) {
print('jQuery(".wcd-wrapper").hide();');
}else {
print("yes");
}
}else{
if( $is_booking_enabled === true ) {
print('jQuery(".wcd-wrapper").show();');
print('jQuery("ul.payment-plan-options li:nth-child(2)").hide();');
}else {
print("no");
}
}
}
public static function dfw_get_start_date(){
global $post;
$booking_date = $_POST['booking_date'];
$product_id = $_POST['product_id'];
DFW_Deposits_For_Bookings::dfw_disable_deposits( $booking_date, $product_id );
}
}
new DFW_Deposits_For_Bookings();