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

Packages

  • None
  • Product-Delivery-Date-Pro-for-WooCommerce
    • Addon
    • Admin
      • Settings
        • Field-Labels
        • General
        • Google-Sync
      • View-Deliveries
    • Calendar
    • Common-Functions
    • Configuration
    • Delivery-Charges
    • Edit-Deliveries
    • Emails
    • Frontend
      • Cart
      • Checkout
    • Google-Calendar
    • Languages
    • License
    • Reschedule-Deliveries
    • View-Deliveries

Classes

  • EDD_PRDD_Plugin_Updater
  • prdd_addon_compatibility_class
  • prdd_admin_deliveries
  • prdd_adminevent_jsons
  • prdd_box_class
  • prdd_cart
  • prdd_checkout
  • prdd_common
  • prdd_delivery_labels_settings
  • prdd_delivery_settings
  • prdd_edit_deliveries_class
  • PRDD_Email_Delivery_Rescheduled
  • PRDD_Email_Delivery_Rescheduled_Admin
  • PRDD_Email_Manager
  • prdd_estimate_delivery
  • prdd_global_menu
  • prdd_ics
  • prdd_license
  • prdd_process
  • prdd_rescheduled_order_class
  • prdd_special_delivery_price
  • prdd_timeslot_price
  • prdd_validation
  • PRDD_View_Deliveries_Table
  • ts_google_calendar_sync
  • ts_google_calendar_sync_settings
  • TsGcal
  • view_deliveries
  • woocommerce_prdd

Functions

  • is_prdd_active
  • prdd_get_dateToCal
  • prdd_get_delivery_arrays
  • prdd_get_delivery_t
  • prdd_get_escapeString
  • prdd_woocommerce_delete
  • ts_get_option
  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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 
<?php 
/**
 * Product Delivery Date Pro for WooCommerce
 *
 * Handles the JSON output for deliveries to be displayed in Calendar View for admin.
 *
 * @author      Tyche Softwares
 * @package     Product-Delivery-Date-Pro-for-WooCommerce/Calendar
 * @since       1.0
 */

include_once( 'prdd-common.php' );
include_once( 'prdd-lang.php' );

/**
 * Class for Generating ICS file of the booking on Order Receive page and Email notification
 *
 * @class prdd_ics
 * @since 1.0
 */
class prdd_ics {
    /**
     * This fuction adds Add to calendar button on Order recieved page which when clicked download the ICS file with  product delivery date details.
     *     
     * @since 1.0
     * @param object $order Order Object
     * @global object $wpdb Global wpdb object
     * @global object $woocommerce Global WooCommerce object
     */
    
    public static function prdd_export_to_ics( $order ){
        global $woocommerce, $wpdb;
        if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id; 
        }
        $order_obj = new WC_Order( $order_id );
        $order_items = $order_obj->get_items();
        $c = 0;
        $start_timestamp = $end_timestamp = '';
        foreach( $order_items as $item_key => $item_value ) {
            $dupicate_of = prdd_common::prdd_get_product_id( $item_value[ 'product_id' ] );
            $prdd_settings = get_post_meta( $item_value[ 'product_id' ], 'woocommerce_prdd_settings', true );
            if( isset( $prdd_settings[ 'prdd_enable_date' ] ) && $prdd_settings[ 'prdd_enable_date' ] == 'on' ) {
                $dt = $time_slot = '';
                if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
                    $meta_data = $item_value->get_meta_data();
                    foreach( $meta_data as $meta_key => $meta_value ) {
                        if( $meta_value->key == '_prdd_date' ) {
                            $dt = new DateTime( $meta_value->value  );    
                        } 

                        if( $meta_value->key == '_prdd_time_slot' ) {
                            $time_slot = $meta_value->value;
                        }
                    }
                } else {
                    if( isset( $item_value[ 'item_meta' ][ '_prdd_date' ][ 0 ] ) ) {
                        $dt = new DateTime( $item_value[ 'item_meta' ][ '_prdd_date' ][ 0 ] );
                    }    
                    if( isset( $item_value[ 'item_meta' ][ '_prdd_time_slot' ][ 0 ] ) ) {
                        $time_slot = $item_value[ 'item_meta' ][ '_prdd_time_slot' ][ 0 ];
                    }
                }
                
                $global_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
                
                $time = 0;
                $time_start = array();
                $time_end = array();
                $time_start_hour = 0;
                $time_start_min = 0;
                $time_end_hour = 0;
                $time_end_min = 0;
                
                if ( isset( $prdd_settings[ 'prdd_enable_time' ] ) && $prdd_settings[ 'prdd_enable_time' ] == 'on' ) {
                    if( $time_slot != '' ) {
                        $timeslot_exploded = explode( " - ", $time_slot );
                        $time_start = explode( ':', $timeslot_exploded[ 0 ] );
                        if( isset( $timeslot_exploded[ 1 ] ) ) {
                            $time_end = explode( ':', $timeslot_exploded[ 1 ] );
                        }
                    }
                }

                if( isset( $time_start[0] ) ) {
                    $time_start_hour = $time_start[0];
                }

                if( isset( $time_start[1] ) ) {
                    $time_start_min = $time_start[1];
                } 

                if( isset( $time_end[0] ) ) {
                    $time_end_hour = $time_end[0];
                }

                if( isset( $time_end[1] ) ) {
                    $time_end_min = $time_end[1];
                } 
                
                if( $dt != '' ) {
                    $start_timestamp = strtotime( $dt->format( 'Y-m-d' ) ) + trim( $time_start_hour )*60*60 + trim( $time_start_min )*60 + (time() - current_time( 'timestamp' ) );
                }
                $end_timestamp = '';
                if ( isset( $time_end[0] ) && isset( $time_end[1] ) ) {
                    if( $dt != '' ) {
                        $end_timestamp = strtotime( $dt->format( 'Y-m-d' ) ) + trim( $time_end_hour )*60*60 + trim( $time_end_min )*60 + (time() - current_time( 'timestamp' ) );
                    }
                }
                ?>
                <form method="post" action="<?php echo plugins_url("/prdd-export-ics.php", __FILE__ );?>" id="export_to_ics">
                    <input type="hidden" id="delivery_date_start" name="delivery_date_start" value="<?php echo $start_timestamp; ?>" />
                    <input type="hidden" id="delivery_date_end" name="delivery_date_end" value="<?php echo $end_timestamp; ?>" />
                                    
                    <input type="hidden" id="current_time" name="current_time" value="<?php echo current_time('timestamp'); ?>" />
                    <input type="hidden" id="delivery_name" name="delivery_name" value="<?php echo $item_value[ 'name' ]; ?>" />
                                    
                    <input type="submit" id="exp_ics" name="exp_ics" value="<?php _e( 'Add to Calendar', 'woocommerce-prdd' ); ?>" /> (<?php echo $item_value['name']; ?>)
                </form>
                <?php 
            }
        }           
    }
    
    /**
     * This function attach the ICS file with the delivery details in the email sent to user and admin.
     * 
     * @since 1.0
     * @param array $other Empty array
     * @param object $order_id ID of email template
     * @param object $order Order Object
     * @global object $wpdb Global wpdb object
     * @global object $woocommerce Global WooCommerce object
     *
     * @return $file Returns the ICS file for the delivery details
     */
    public static function prdd_email_attachment ( $other, $order_id, $order ) {
        global $wpdb;       
        if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id; 
        }       
        $order_obj = new WC_Order( $order_id ); 
        $order_items = $order_obj->get_items(); 
        $random_hash = md5( date( 'r', time() ) );  
        $file_path = WP_CONTENT_DIR.'/uploads/wprdd_tmp';
        $file = array();
        $c = 0;
        $start_timestamp = $end_timestamp = '';
        foreach ( $order_items as $item_key => $item_value ) {
            $duplicate_of = prdd_common::prdd_get_product_id( $item_value[ 'product_id' ] ); 
            $prdd_settings = get_post_meta( $duplicate_of, 'woocommerce_prdd_settings', true );
            $file_name = get_option( 'delivery_ics-file-name' );
            if( isset( $prdd_settings[ 'prdd_enable_date' ] ) && $prdd_settings[ 'prdd_enable_date' ] == 'on' ) {
                $global_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
                $dt = '';
                if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
                    $meta_data = $item_value->get_meta_data();
                    foreach( $meta_data as $meta_key => $meta_value ) {
                        if( $meta_value->key == '_prdd_date' ) {
                            $dt = new DateTime( $meta_value->value  );    
                        }
                    }
                } else {
                    if( isset( $item_value[ 'item_meta' ][ '_prdd_date' ][ 0 ] ) ) {
                        $dt = new DateTime( $item_value[ 'item_meta' ][ '_prdd_date' ][ 0 ] );
                    }    
                }
                $time = 0;
                $time_start = 0;
                $time_end = 0;
                if ( $prdd_settings[ 'prdd_enable_time' ] == 'on' ) {   
                    if( isset( $item_value[ 'item_meta' ][ '_prdd_time_slot' ][ 0 ] ) ) {
                        $timeslot_exploded = explode( " - ", $item_value[ 'item_meta' ][ '_prdd_time_slot' ][ 0 ] );
                        $time_start = explode( ':', $timeslot_exploded[ 0 ] );
                        if( isset( $timeslot_exploded[ 1 ] ) ) {
                            $time_end = explode( ':', $timeslot_exploded[ 1 ] );
                        }
                    }
                }
                
                if( isset( $time_start ) && count( $time_start ) > 0 && $time_start[0] != "" ) {
                    if( $dt != '' ) {
                        if( isset( $time_start[1] ) ) {
                            $time_start_min = $time_start[1];
                        } else {
                            $time_start_min = 0;
                        }
                        $start_timestamp = strtotime( $dt->format( 'Y-m-d' ) ) + trim( $time_start[0] )*60*60 + trim( $time_start_min )*60 + ( time() - current_time( 'timestamp' ) );
                    }
                } else {
                    if( $dt != '' ) {
                        $start_timestamp = strtotime( $dt->format( 'Y-m-d' ) ) + ( time() - current_time( 'timestamp' ) );
                    }    
                }
                
                if( isset( $time_end ) && count( $time_end ) > 0 && $time_end[0] != "" ) {
                    if( $dt != '' ) {
                        if( isset( $time_end[1] ) ) {
                            $time_end_min = $time_end[1];
                        } else {
                            $time_end_min = 0;
                        }
                        $end_timestamp = strtotime( $dt->format( 'Y-m-d' ) ) + trim( $time_end[0] )*60*60 + trim( $time_end_min )*60 + ( time() - current_time( 'timestamp' ) );
                    }
                } else {
                    if( $dt != '' ) {
                       $end_timestamp = strtotime( $dt->format( 'Y-m-d' ) ) + ( time() - current_time( 'timestamp' ) );
                    }
                }
                
                $icsString = "
BEGIN:VCALENDAR
PRODID:-//Events Calendar//iCal4j 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTART:" . date( 'Ymd\THis\Z', $start_timestamp ) . "
DTEND:" . date( 'Ymd\THis\Z', $end_timestamp ) . "
DTSTAMP:" . date( 'Ymd\THis\Z', current_time( 'timestamp' ) ) . "
UID:" . ( uniqid() ) . "
DESCRIPTION:" . $item_value[ 'name' ] . "
SUMMARY:" . $item_value[ 'name' ] . "
END:VEVENT
END:VCALENDAR";
                if ( !file_exists( $file_path ) ) {
                    mkdir( $file_path, 0777 );
                } 
                $file[$c] = $file_path . '/' . $file_name . '_' . $c . '.ics';
                // Append a new person to the file                              
                $current = $icsString;
                // Write the contents back to the file
                file_put_contents( $file[$c], $current );   
            }
        }
        return $file;
    }
}
?>
API documentation generated by ApiGen