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 
<?php
/** 
 * Manage Scheduled Payment Plans
 * 
 * @author Tyche Softwares
 * @since 1.0 
 * @category Classes
 * @package Deposits-for-WooCommerce/Payment-Plans
 */

class DFW_Scheduled_Plan_Orders {

    /**
     * Create subsequent orders for payment plans
     * 
     * @param DFW_Deposits_Plan $plan Payment Plan object
     * @param int $original_order_id Order ID of the original order
     * @param mixed $item Order item object
     * @globals $wpdb
     */
    public static function create_orders_for_plans( $plan, $original_order_id, $item ) {
        global $wpdb;
        $plan_schedule     = $plan->get_plan_schedule();
        $total_percent     = $plan->get_total_percent();
        $price             = ( $item['price'] * 100 ) / $total_percent; 
        $product_id        = $item['product']->get_id();
        $payment_no        = 2;
        $current_timestamp = current_time('timestamp');
        $booking_query     = '';
        $booking_date      = '';
        $booking_time      = '';
        array_shift( $plan_schedule );

        $booking_settings =   get_post_meta( $product_id, 'woocommerce_booking_settings', true );
        $is_booking_enabled = false;
        $is_woo_booking_enabled = false;

        if ( ( isset( $booking_settings['booking_enable_date'] ) && $booking_settings['booking_enable_date'] == "on" ) ) {
            $is_booking_enabled = true;
        }
        
        if( class_exists( 'WC_Bookings' ) ) {
            if( is_wc_booking_product( $item['product'] ) ) {
                $is_woo_booking_enabled = true;
            }
        }
        
        if( $is_booking_enabled === true ) {
            $booking_query     = "SELECT a1.start_date FROM `" . $wpdb->prefix . "booking_history` AS a1,`" . $wpdb->prefix . "booking_order_history` AS a2 WHERE a1.id = a2.booking_id AND a2.order_id=".$original_order_id; 
            $booking_date      = $wpdb->get_results( $booking_query );
            $booking_time      = strtotime( $booking_date[0]->start_date, current_time('timestamp'));
            
        } else if( $is_woo_booking_enabled ) {
            $booking_query = "SELECT a1.meta_value FROM `" . $wpdb->prefix . "postmeta` as a1,`" . $wpdb->prefix . "posts` as a2 WHERE a1.post_id = a2.ID AND a2.post_parent = ". $original_order_id ." AND a1.meta_key = '_booking_start'";
            $booking_date  = $wpdb->get_results( $booking_query );
            $booking_time  = strtotime( $booking_date[0]->meta_value, 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 );  

            }else {
                $current_timestamp = strtotime( "+{$row->plan_interval_amount} {$row->plan_interval_time}", current_time('timestamp') );  
            }
            //$current_timestamp = strtotime( "+{$row->plan_interval_amount} {$row->plan_interval_time}", current_time( 'timestamp' ) );
            $item['amount']    = ( $price / 100 ) * $row->plan_amount;
            DFW_Manage_Orders::dfw_create_order( $current_timestamp, $original_order_id, $payment_no, $item, 'scheduled-payment' );
            $payment_no++;

        }
    }
}

$dfw_scheduled_plan_orders = new DFW_Scheduled_Plan_Orders();
API documentation generated by ApiGen