Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • Deposits-for-WooCommerce
    • Bookings
    • Cart
    • Order
    • Other
    • Payment-Plans
      • Views
    • Products
    • Settings

Classes

  • DFW_Deposits
  • DFW_Deposits_For_Bookings
  • DFW_Deposits_Plan
  • DFW_Deposits_Settings
  • DFW_License
  • DFW_Manage_Cart
  • DFW_Manage_Order_Items
  • DFW_Manage_Orders
  • DFW_Manage_Plans
  • DFW_Manage_Products
  • DFW_Payment_Plans_List
  • DFW_Plans_Admin_Settings
  • DFW_Product_Admin_Settings
  • DFW_Scheduled_Plan_Orders
  • DFW_Update_DB
  • EDD_DEPOSITS_Plugin_Updater

Functions

  • dfw_update_po_file
  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
/**
 * Manage Bookings with Deposits
 * 
 * @author Tyche Softwares
 * @since 1.0 
 * @category Classes
 * @package Deposits-for-WooCommerce/Bookings
 */

class DFW_Deposits_For_Bookings {

    /**
     * Constructor function which adds a hook from the Booking plugin
     * 
     * @since 1.2
     */
    public function __construct() {
        add_action( 'bkap_js', array( &$this, 'dfw_get_booking_date' ), 10, 3 );
    }

    /**
     * Display options if start date is selected
     * 
     * @since 1.2
     */
    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;
    }

    /**
     * Get the booking date
     * 
     * @hook bkap_js
     * 
     * @param DateTime $booking_date Selected Booking date 
     * @param int $post_id Product ID
     * @param $addon_data
     * @since 1.2
     */
    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 );
    }

    /**
     * Disable deposits if booking date is before the specified period
     *      
     * @param DateTime $booking_date Selected Booking date 
     * @param int $post_id Product ID
     * @since 1.2
     */
    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");
                
            }
            
        }
        
    }

    /**
     * Get the selected start date
     *      
     * @since 1.2
     */
    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();
API documentation generated by ApiGen