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

Packages

  • None
  • Order-Delivery-Date-Pro-for-WooCommerce
    • Admin
      • Edit-Order
      • Non-Sensitive-Data-Capture
      • Settings
        • Custom-Delivery
        • General
        • Google-Calendar-Sync
    • Class-ORDDD-Email-Manager
    • Common-Functions
    • Delivery-Calendar
    • Emails
      • Class-ORDDD-Email-Update-Date
    • Filter
    • Frontend
      • Checkout-Page-Processes
      • ICS-Files-Data
    • Google-Calendar
    • Integration
    • Lang
    • License
    • Plugin-Updates
      • EDD-SL-Plugin-Updater

Classes

  • EDD_SL_Plugin_Updater
  • orddd_additional_settings
  • orddd_admin_delivery_class
  • orddd_appearance_settings
  • orddd_calendar_sync
  • orddd_calendar_sync_settings
  • orddd_class_view_deliveries
  • orddd_common
  • orddd_date_settings
  • orddd_delivery_days_settings
  • ORDDD_Email_Manager
  • ORDDD_Email_Update_Date
  • orddd_filter
  • orddd_holidays_settings
  • orddd_integration
  • orddd_license
  • orddd_process
  • orddd_settings
  • orddd_shipping_based_settings
  • orddd_shipping_days_settings
  • orddd_shipping_multiple_address
  • orddd_time_settings
  • orddd_time_slot_settings
  • ORDDD_View_Delivery_Dates_Table
  • ORDDD_View_Disable_Time_Slots_Table
  • ORDDD_View_Holidays_Table
  • ORDDD_View_Shipping_Settings_Table
  • ORDDD_View_Time_Slots_Table
  • OrdddGcal
  • order_delivery_date
  • TS_Tracker
  • TS_tracking

Functions

  • orddd_get_dateToCal
  • orddd_get_escapeString
  • orddd_t
  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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 
<?php 
/**
 * Order Delivery Date Pro for WooCommerce
 *
 * Integration class to make the Order Delivery Date plugin compatible with various third party plugins.
 *
 * @author      Tyche Softwares
 * @package     Order-Delivery-Date-Pro-for-WooCommerce/Integration
 * @since       2.7
 */

include_once( dirname( __FILE__ ) . '/orddd-common.php' );

/**
 * orddd_integration Class
 *
 * @class orddd_integration
 */
class orddd_integration {
    
    /**
     * Constructor. Adds various hooks and filters 
     * based on the settings.
     */
    public function __construct() {     
        // Zapier integration
        add_action( 'plugins_loaded', array( 'orddd_integration', 'orddd_plugins_loaded' ) );
        // WooCommerce PDF Invoices & Packing Slips
        if ( get_option( 'orddd_show_fields_in_pdf_invoice_and_packing_slips' ) == 'on' ) {
            if ( version_compare( get_option( 'wpo_wcpdf_version' ), '2.0.0', ">=" ) ) {
                add_action( 'wpo_wcpdf_after_order_details', array( 'orddd_integration', 'orddd_plugins_packing_slip' ), 10, 2 );
            } else {
                add_action( 'wpo_wcpdf_after_order_details', array( 'orddd_integration', 'orddd_plugins_packing_slip' ) );
            }
        }
        // add custom columns headers to csv when Order/Customer CSV Export Plugin is activate
        if ( get_option( 'orddd_show_fields_in_csv_export_check' ) == 'on' ) {
            add_filter( 'wc_customer_order_csv_export_order_headers', array( 'orddd_integration', 'wc_csv_export_modify_column_headers' ) );
            add_filter( 'wc_customer_order_csv_export_order_row', array( 'orddd_integration', 'wc_csv_export_modify_row_data'), 10, 3 );
        }
        //WooCommerce Print Invoice & Delivery Note
        if( get_option( 'orddd_show_fields_in_invoice_and_delivery_note' ) == 'on' ) {
            add_filter( 'wcdn_order_info_fields', array( 'orddd_integration', 'orddd_plugin_print_invoice_delivery_note' ), 10, 2 );
        }
        if ( get_option( 'orddd_show_fields_in_cloud_print_orders' ) == 'on' ) {
            add_action( 'woocommerce_cloudprint_internaloutput_footer', array( 'orddd_integration', 'cloud_print_fields' ) );
        }
        
        //WooCommerce Print Invoice/Packing list plugin
        add_action( 'wc_pip_after_body', array( 'orddd_integration', 'orddd_plugin_woocommerce_pip' ), 10, 4 );
        
        //WooCommerce Simply Order Export plugin
        add_filter( 'wpg_order_columns', array( 'orddd_integration', 'wpg_add_columns' ) );
        add_filter( 'wc_settings_tab_order_export', array( 'orddd_integration', 'wpg_add_fields' ) );
        add_action( 'wpg_add_values_to_csv', array( 'orddd_integration', 'csv_write' ), 10, 6 );
        
        add_action( 'woocommerce_api_order_response', array( 'orddd_integration', 'woocommerce_api_create_order' ), 10, 4 );
    }
    
    /**
     * Adds the Delivery Details to the WooCommerce API
     * 
     * @param array $order_data - Order Data
     * @param WC_Order $order - Order Details
     * @param array $fields - Request fields.
     * @param object $server 
     * @return array $order_data - Updated Order Data with Delivery details.
     * 
     * @hook woocommerce_api_order_response
     * @since 5.8
     */
    public static function woocommerce_api_create_order( $order_data, $order, $fields, $server ) {
        
        if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {            
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id;
        }
        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        if( $delivery_date_formatted != '' ) {
            $order_data[ get_option( 'orddd_delivery_date_field_label' ) ] = $delivery_date_formatted;
        }
        
        if( get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ) , true ) ) {
            $order_data[ get_option( 'orddd_delivery_timeslot_field_label' ) ] = get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ), true );
        }
        
        if( get_post_meta( $order_id, '_orddd_timestamp' , true ) ) {
            $order_data[ '_orddd_timestamp' ] = get_post_meta( $order_id, '_orddd_timestamp', true );
        }
        return $order_data;
    }
    
    /**
    * Executed during the 'plugins_loaded' WordPress hook.
    *
    * - Load Supported Zapier Triggers
    * 
    * @hook plugins_loaded
    * @since 2.7 
    */
    public static function orddd_plugins_loaded() {
        if ( class_exists( 'WC_Zapier' ) ) {
            $trigger_keys = array(
                'wc.new_order', // New Order
                'wc.order_status_change' // New Order Status Change
            );
            foreach ( $trigger_keys as $trigger_key ) {
                add_filter( "wc_zapier_data_{$trigger_key}", array('orddd_integration', 'orddd_order_data_override' ), 10, 4 );
            }
        }
    }

    /**
    * When sending WooCommerce Order data to Zapier, also send order delivery date field 
    * that have been created by the Order Delivery Date plugin.
    *
    * @param array $order_data - Order data that will be overridden.
    * @param WC_Zapier_Trigger $trigger - Trigger that initiated the data send.
    * @return array $order_data - Updated Order data with delivery details.
    * 
    * @since 2.7
    */
    public static function orddd_order_data_override( $order_data, WC_Zapier_Trigger $trigger ) {
        $field_name = get_option( 'orddd_delivery_date_field_label' );
        $time_slot = get_option( 'orddd_delivery_timeslot_field_label' );
        if ( $trigger->is_sample() ) {
            // We're sending sample data.
            // Send the label of the custom checkout field as the field's value.
            $order_data[ $field_name ] = $field_name;
            $order_data[ $time_slot ] = $time_slot;
        } else {
            // We're sending real data.
            // Send the saved value of this checkout field.
            // If the order doesn't contain this custom field, an empty string will be used as the value.
            $order_data[ $field_name ] = get_post_meta( $order_data[ 'id' ], $field_name, true );
            $order_data[ $time_slot ] = get_post_meta( $order_data[ 'id' ], $time_slot, true );
        }
        return $order_data;
    }

    /**
     * Adds delivery date and time selected for an order in the PDF invoices
     * and Packing slips from WooCommerce PDF Invoices & Packing Slips plugin.
     *
     * @param string $template_type - Template Type for the Invoice
     * @param array $order - Order data
     * 
     * @hook wpo_wcpdf_after_order_details
     * @since 2.7
     */
    public static function orddd_plugins_packing_slip( $template_type = "", $order = array() ) {
        global $orddd_date_formats;
        if ( version_compare( get_option( 'wpo_wcpdf_version' ), '2.0.0', ">=" ) ) {
            $order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">="  ) ) ? $order->get_id() : $order->id;
        } else { 
            global $wpo_wcpdf;
            $order_export = $wpo_wcpdf->export;
            $order_obj = $order_export->order;
            $order_id = $order_obj->id;
        }

        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        if( $delivery_date_formatted != '' ) {
            echo '<p><strong>' . __( get_option( 'orddd_delivery_date_field_label' ), 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted;
        }
        
        $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id );
        if( $order_page_time_slot != "" && $order_page_time_slot != '' ) {
            echo '<p><strong>' . __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot;
        }
    }
    
    /**
     * Adds delivery date and time column headings to CSV when order
     * is exported from Order/Customer CSV Export Plugin.
     *
     * @param array $column_headers - List of Column Names
     * @return array $column_headers - The list of column names
     *
     * @hook wc_customer_order_csv_export_order_headers
     * @since 2.7
     */
    public static function wc_csv_export_modify_column_headers( $column_headers ) { 
        $new_headers = array(
            'column_1' => __( get_option( 'orddd_delivery_date_field_label' ), 'order-delivery-date' ),
            'column_2' => __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ),
        );
        return array_merge( $column_headers, $new_headers );
    }
    
    /**
     * Adds delivery date and time column content to CSV when order
     * is exported from Order/Customer CSV Export Plugin.
     *
     * @param array $order_data -
     * @param object $order - Order Details
     * @param object $csv_generator
     * @return array $new_order_data - Delivery data
     *
     * @hook wc_customer_order_csv_export_order_row
     * @since 2.7
     */
    public static function wc_csv_export_modify_row_data( $order_data, $order, $csv_generator ) {
        $new_order_data = array();
        if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {            
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id;
        }
        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        
        $custom_data = array(
            'column_1' => $delivery_date_formatted,
            'column_2' => get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ), true ),
        );
 
        $new_order_data   = array();
        $one_row_per_item = false;
        
        if ( version_compare( wc_customer_order_csv_export()->get_version(), '4.0.0', '<' ) ) {
            // pre 4.0 compatibility
            $one_row_per_item = ( 'default_one_row_per_item' === $csv_generator->order_format || 'legacy_one_row_per_item' === $csv_generator->order_format );
        } elseif ( isset( $csv_generator->format_definition ) ) {
            // post 4.0 (requires 4.0.3+)
            $one_row_per_item = 'item' === $csv_generator->format_definition['row_type'];
        }
        if ( $one_row_per_item ) {
            foreach ( $order_data as $data ) {
                $new_order_data[] = array_merge( (array) $data, $custom_data );
            }
        } else {
            $new_order_data = array_merge( $order_data, $custom_data );
        }
        
        return $new_order_data;     
    }
    
    /**
     * Adds delivery date and time selected for an order in the invoices
     * and delivery notes from WooCommerce Print Invoice & Delivery Note plugin.
     *
     * @param array $fields - List of fields
     * @param object $order - Order data
     * @return array $fields - with the delivery data added
     *
     * @hook wcdn_order_info_fields
     * @since 2.7
     */
    public static function orddd_plugin_print_invoice_delivery_note( $fields, $order ) {
        $new_fields = array();
        if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {            
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id;
        }
        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        if( $delivery_date_formatted != '' ) {
            $new_fields[ get_option( 'orddd_delivery_date_field_label' ) ] = array(
                'label' => __( get_option( 'orddd_delivery_date_field_label' ), 'order-delivery-date' ),
                'value' => $delivery_date_formatted
            );
        }   
        
        if( get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ) , true ) ) {
            $new_fields[ get_option( 'orddd_delivery_timeslot_field_label' ) ] = array( 
                'label' => __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ),
                'value' => get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ), true )
            );
        }
        return array_merge( $fields, $new_fields );
    }
    
    /**
     * Adds delivery date and time selected for an order
     * in the prints from WooCommerce Print Orders plugin.
     *
     * @param object $order - Order Details
     *
     * @hook woocommerce_cloudprint_internaloutput_footer
     * @since 2.7
     */
    public static function cloud_print_fields( $order ) { 
        $field_date_label = get_option( 'orddd_delivery_date_field_label' );
        if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {            
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id;
        }
        
        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        echo '<p><strong>'.__( $field_date_label, 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted;

        $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id );
        if( $order_page_time_slot != "" && $order_page_time_slot != '' ) {
            echo '<p><strong>' . __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot;
        }
    }
    
    /**
     * Adds delivery date and time selected for an order in the invoices
     * and delivery notes from WooCommerce Print Invoice/Packing list plugin.
     *
     * @param string $type
     * @param string $action
     * @param string $document
     * @param resource $order Order Details
     *
     * @hook wc_pip_after_body
     * @todo Need to check the type of the parameters.
     *
     * @since 2.7
     */
    public static function orddd_plugin_woocommerce_pip( $type, $action, $document, $order ) {
        global $orddd_date_formats;
        $delivery_date = get_option( 'orddd_delivery_date_field_label' );
        $time_slot = get_option( 'orddd_delivery_timeslot_field_label' );
        
        if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {            
            $order_id = $order->get_id();
        } else {
            $order_id = $order->id;
        }
        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        if( $delivery_date_formatted != '' ) {
            echo '<p><strong>' . __( $delivery_date, 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted;
        }
        
        $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id );
        if( $order_page_time_slot != "" && $order_page_time_slot != '' ) {
            echo '<p><strong>' . __( $time_slot, 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot;
        }
    }
    
    /**
     * Adds Delivery date and/or time column in CSV export file 
     * for WooCommerce Simply Order Export plugin.
     * 
     * @param array $cols - Column Names
     * @return array $cols - Updated Column Names
     * 
     * @hook wpg_order_columns
     * @since 4.0
     */
    public static function wpg_add_columns( $cols ) {
        $delivery_date_label = get_option( 'orddd_delivery_date_field_label' );
        $time_slot_label = get_option( 'orddd_delivery_timeslot_field_label' );
        $cols[ 'orddd_delivery_date' ] = $delivery_date_label;
        $cols[ 'orddd_time_slot' ] = $time_slot_label;
        return $cols;
    }
    
    /**
     * Adds Delivery date and/or time field display settings on the 
     * Settings page for WooCommerce Simply Order Export plugin
     * 
     * @param array $settings - Settings
     * @param array $settings - Updated with Delivery field settings
     * 
     * @hook wc_settings_tab_order_export
     * @since 4.0
     */
    public static function wpg_add_fields( $settings ) {
        $delivery_date_label = get_option( 'orddd_delivery_date_field_label' );
        $time_slot_label = get_option( 'orddd_delivery_timeslot_field_label' );
        $settings[ 'Delivery Date' ] = array(
            'name' => $delivery_date_label,
            'type' => 'checkbox',
            'desc' => __( 'Delivery Date', 'order-delivery-date' ),
            'id'   => 'orddd_delivery_date'
        );
         
        $settings[ 'Time Slot' ] = array(
            'name' => $time_slot_label,
            'type' => 'checkbox',
            'desc' => __( 'Time Slot', 'order-delivery-date' ),
            'id'   => 'orddd_time_slot'
        );
         
        return $settings;
    
    }
    
    /**
     * Adds Delivery date and/or time details in CSV export file 
     * for WooCommerce Simply Order Export plugin.
     * 
     * @hook wpg_add_values_to_csv
     * 
     * @param array $csv Values to export to CSV
     * @param resoruce $od Order Object
     * @param string $field Field slug
     * @param string $key 
     * @param string $item_id
     * @param array $current_item
     *
     * @since 4.0
     */
    public static function csv_write( &$csv, $od, $field, $key, $item_id, $current_item ) {
        $order_id = $od->id;
        $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id );
        $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id );
        switch( $field ) {
            case 'orddd_delivery_date':
                array_push( $csv, $delivery_date_formatted );
                break;
    
            case 'orddd_time_slot':
                array_push( $csv, $order_page_time_slot );
                break;
    
            default :
                break;
        }   
    }
}
$orddd_integration = new orddd_integration();
?>
API documentation generated by ApiGen