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 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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 
<?php

/**
 * PRDD Allow Deliveries to be edited from Cart and Checkout Page
 * 
 * @author  Tyche Softwares
 * @package Product-Delivery-Date-Pro-for-WooCommerce/Edit-Deliveries
 *
 * @since   2.4
 */

if( ! class_exists( 'prdd_edit_deliveries_class' ) ) {

    /**
     * Class for allowing Deliveries to be edited from Cart and Checkout Page
     *
     * @since 2.4
     */
    class prdd_edit_deliveries_class {

        /**
         * Default Constructor
         * 
         * @since 2.4
         */
        public function __construct() {

            add_action( 'admin_init', array( &$this, 'prdd_add_edit_settings' ), 11 );

            $global_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            if( isset( $global_settings->prdd_enable_delivery_edit ) && 
                $global_settings->prdd_enable_delivery_edit === 'on' ){
            
                add_filter( 'woocommerce_cart_item_name', array( &$this, 'prdd_add_edit_link' ), 10, 3 );

                add_action( 'wp_ajax_nopriv_prdd_update_edited_deliveries', array( &$this, 'prdd_update_edited_deliveries' ) );
                add_action( 'wp_ajax_prdd_update_edited_deliveries', array( &$this, 'prdd_update_edited_deliveries' ) );
            }

            add_action( 'woocommerce_order_item_meta_end', array( &$this, 'prdd_add_reschedule_link' ), 10, 3 );
        }

        /**
         * Load modal template for delivery box
         * 
         * @param array $prdd_settings Delivery Details array
         * @param WC_Product $cart_product Product Object
         * @param int|string $product_id Product ID
         * @param array $localized_array Localized array to be passed to JS
         * @param string $prdd_cart_item_key Cart Item key or Order Item key for unique ID of modal
         * @param int|string $variation_id Variation ID
         *
         * @since 2.4
         */
        public static function prdd_load_template( $prdd_settings, $cart_product, $product_id, $localized_array, $prdd_cart_item_key, $variation_id ) {
            wc_get_template( 
                'prdd-edit-delivery-modal.php', 
                array(
                    'prdd_delivery' => $prdd_settings,
                    'product_obj' => $cart_product,
                    'product_id' => $product_id,
                    'variation_id' => $variation_id,
                    'prdd_cart_item_key' => $prdd_cart_item_key ), 
                'product-delivery-date/', 
                PRDD_DELIVERIES_TEMPLATE_PATH );

            $plugin_version_number = get_option( 'woocommerce_prdd_db_version' );

            self::prdd_enqueue_edit_deliveries_scripts( 
                $prdd_cart_item_key,
                $plugin_version_number, 
                $localized_array
            );

            self::prdd_enqueue_edit_deliveries_styles(
                $plugin_version_number
            );
        }

        /**
         * Add Edit Link on Cart and Checkout page
         * 
         * @hook woocommerce_cart_item_name
         * 
         * @param string $product_title Product Title to which additional string needs to be appeded
         * @param WC_Product $cart_item Cart Item in WC_Product object form
         * @param string $cart_item_key Cart Item key
         *
         * @return string Product Title with appended data
         * 
         * @since 2.4
         */
        public function prdd_add_edit_link( $product_title, $cart_item, $cart_item_key ) {
            if ( ( ( is_cart() && !is_ajax() ) || is_checkout() ) && !is_product() && 
                !( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) ) &&
                 isset( $cart_item['prdd_delivery'] ) ) {

                $product_id = $cart_item['product_id'];

                if ( $cart_item['variation_id'] !== 0 ) {
                    $variation_id = $cart_item['variation_id'];
                }else {
                    $variation_id = 0;
                }

                $product_title .= '<div style="clear:both;"></div>';

                $product_title .= sprintf( '<input type="button" onclick=prdd_edit_delivery_class.prdd_edit_deliveries(%d,"%s") value="%s">', $product_id, $cart_item_key, __( 'Edit Deliveries', 'woocommerce-prdd' ) );

                $page_type = '';
                if ( is_cart() ) {
                    $page_type = 'cart';
                }else if ( is_checkout() ) {
                    $page_type = 'checkout';
                }

                $localized_array = array( 
                    'prdd_delivery_params' => $cart_item['prdd_delivery'][0],
                    'prdd_cart_item' => $cart_item,
                    'prdd_cart_item_key' => $cart_item_key,
                    'prdd_page_type' => $page_type
                );

                self::prdd_load_template( 
                    $cart_item['prdd_delivery'][0], 
                    $cart_item['data'], 
                    $product_id, 
                    $localized_array,
                    $cart_item_key,
                    $variation_id
                );

                return $product_title;
            } else {
                return $product_title;
            }
        }

        /**
         * Add Edit Delivery link on My Account Page
         * 
         * @hook woocommerce_order_item_meta_end
         *
         * @param srting $item_id Order Item ID
         * @param WC_Order_Item $item Order Item
         * @param WC_Order $order Order Object
         *
         * @since 2.4
         */
        public function prdd_add_reschedule_link( $item_id, $item, $order ) {
            if ( is_wc_endpoint_url( 'view-order' ) ) {
                $order_status = $order->get_status();
                if( isset( $order_status ) && ( $order_status !== 'cancelled' ) && ( $order_status !== 'refunded' ) && ( $order_status !== 'trash' ) && ( $order_status !== '' ) && ( $order_status !== 'failed' ) && ( 'auto-draft' !== $order_status ) ) {

                    $prdd_details = array(
                        'date' => '',
                        'hidden_date' => '',
                        'price' => '' );

                    foreach ( $item->get_meta_data() as $meta_index => $meta ) {
                        if ( isset( $meta->key ) && $meta->key === get_option( 'delivery_item-meta-date' ) ) {
                            $prdd_details[ 'date' ] = $meta->value;
                        } elseif ( isset( $meta->key ) && $meta->key === '_prdd_date' ) {
                            $hidden_date = explode( '-', $meta->value );
                            $prdd_details[ 'hidden_date' ] = $hidden_date[2] . '-' . $hidden_date[1] . '-' . $hidden_date[0];
                        } elseif ( isset( $meta->key ) && $meta->key === get_option( 'delivery_item-meta-time' ) ){
                            $prdd_details[ 'time_slot' ] = $meta->value;
                        }
                    }

                    $diff_days = (strtotime($prdd_details['hidden_date']) - current_time('timestamp'))/60/60/24;
                    $global_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );

                    if( isset( $global_settings->prdd_enable_delivery_reschedule ) &&
                        isset( $global_settings->prdd_delivery_reschedule_days ) &&
                        $diff_days >= $global_settings->prdd_delivery_reschedule_days && 
                        $global_settings->prdd_enable_delivery_reschedule === 'on' &&
                        $prdd_details[ 'date' ] !== '' ) {

                        printf( '<input type="button" onclick="prdd_edit_delivery_class.prdd_edit_deliveries(%d,%s)" value="%s">', $item->get_product_id( 'view' ), $item_id, __( 'Edit Deliveries', 'woocommerce-prdd' ) );

                        $localized_array = array( 
                            'prdd_delivery_params' => $prdd_details,
                            'prdd_cart_item' => $item,
                            'prdd_cart_item_key' => $item_id,
                            'prdd_order_id' => $order->get_id(),
                            'prdd_page_type' => 'view-order'
                        );

                        self::prdd_load_template( 
                            $prdd_details, 
                            $item->get_product(), 
                            $item->get_product_id( 'view' ), 
                            $localized_array,
                            $item_id,
                            $item->get_variation_id( 'view' ) );
                    }
                }
            }
        }

        /**
         * Enqueue JS files for edit deliveries
         * 
         * @param string $prdd_cart_item_key Unique ID used for Modal ID
         * @param string $plugin_version_number Plugin Version number
         * @param array $localized_array Localized array to be passed to JS
         *
         * @since 2.4
         */
        public static function prdd_enqueue_edit_deliveries_scripts( $prdd_cart_item_key, $plugin_version_number, $localized_array ) {
            
            wp_register_script( 
                "prdd-edit-delivery", 
                plugins_url( '/js/prdd-edit-delivery.js', __FILE__ ), 
                '', 
                $plugin_version_number, 
                false );

            wp_localize_script( "prdd-edit-delivery", "prdd_edit_params_$prdd_cart_item_key", $localized_array );

            wp_enqueue_script( "prdd-edit-delivery" );
        }

        /**
         * Enqueue CSS files
         * 
         * @param string $plugin_version_number Plugin version number
         *
         * @since 2.4
         */
        public static function prdd_enqueue_edit_deliveries_styles( $plugin_version_number ) {
            wp_enqueue_style( 
                'prdd-edit-delivery-styles', 
                plugins_url( '/css/prdd-edit-delivery.css', __FILE__ ) , 
                '', 
                $plugin_version_number, 
                false );
        }

        /**
         * Ajax callback when confirm bookings is clicked on either Cart, Checkout or My Account Page.
         * 
         * @hook wp_ajax_nopriv_prdd_update_edited_deliveries.
         * @hook wp_ajax_prdd_update_edited_deliveries.
         *
         * @globals resource $wpdb WordPress object.
         *
         * @since 2.4
         */
        public function prdd_update_edited_deliveries() {
            global $wpdb;

            if ( isset( $_POST['page_type'] ) && $_POST['page_type'] !== 'view-order' ) {
                $session_cart = WC()->session->cart;
                $cart_item_obj = $_POST[ 'cart_item_obj' ];
                $session_cart[ $_POST[ 'cart_item_key' ] ][ 'prdd_delivery' ] = $cart_item_obj[ 'prdd_delivery' ];
                $session_cart[ $_POST[ 'cart_item_key' ] ][ 'line_total' ] = $session_cart[ $_POST[ 'cart_item_key' ] ][ 'line_total' ][ 'line_subtotal' ] = $cart_item_obj[ 'line_total' ];
                WC()->session->set( 'cart', $session_cart );
            } elseif ( isset( $_POST[ 'page_type' ] ) && $_POST[ 'page_type' ] === 'view-order' ) {
                $order_id = $_POST[ 'order_id' ];
                $item_id = $_POST[ 'item_id' ];
                $delivery_data = $_POST[ 'delivery_data' ];
                $product_id = $_POST[ 'product_id' ];
                $variation_id = $_POST[ 'variation_id' ];

                $old_deliveries = array();
                $old_deliveries[ 'delivery_date' ] = wc_get_order_item_meta( $item_id, get_option( 'delivery_item-meta-date' ), true );
                $old_deliveries[ 'hidden_date' ] = wc_get_order_item_meta( $item_id, '_prdd_date', true );
                $old_deliveries[ 'time_slot' ] = wc_get_order_item_meta( $item_id, get_option( '
                    delivery_item-meta-time' ), true );

                $old_start_date = wc_get_order_item_meta( $item_id, '_prdd_date' );
                $old_start = date( 'Y-m-d', strtotime( $old_start_date ) );
                $old_time = wc_get_order_item_meta( $item_id, '_prdd_time_slot' );
                $old_line_total = wc_get_order_item_meta( $item_id, '_line_total' );
                $item_obj = new WC_Order_Item_Product( $item_id );
                $product_obj = wc_get_product( $product_id );
                $quantity = $item_obj->get_quantity();

                self::prdd_update_item_deliveries( 
                    $order_id, 
                    $item_id, 
                    $old_start, 
                    $old_time, 
                    $product_id,
                    $variation_id, 
                    $delivery_data,
                    $quantity );

                $gcal = new TsGcal();
                if( $gcal->get_api_mode() == "directly" ) {
                    $values = array();
                    $values[ 'prdd_delivery' ][0][ 'date' ] = wc_get_order_item_meta( $item_id, get_option( 'delivery_item-meta-date' ) );;
                    $values[ 'prdd_delivery' ][0][ 'hidden_date' ] = $delivery_data[ 'hidden_date' ];
                    if ( isset( $delivery_data[ 'time_slot' ] ) && $delivery_data[ 'time_slot' ] !== '' ) {
                        $values[ 'prdd_delivery' ][0][ 'time_slot' ] = $delivery_data[ 'time_slot' ];
            
                    }
                    $values[ 'data' ] = $product_obj;
                    $values[ 'quantity' ] = $quantity;
                    $event_details = prdd_common::prdd_get_event_details( $values, $order_id );
                    $gcal->insert_event( $event_details, $item_id, false );         
                }   

                $difference_amount = self::prdd_get_difference_amount( $item_id, $item_obj, $order_id, $product_id, $variation_id, $product_obj, $old_deliveries, $delivery_data );

                $additional_note = '';
                if ( $difference_amount > 0 ) {
                    $item = array(
                        'product'   => $product_obj,
                        'qty'       => $quantity,
                        'amount'    => $difference_amount
                        );

                    $new_order_id = prdd_rescheduled_order_class::prdd_rescheduled_create_order( $order_id, $item );
                    wc_update_order_item_meta( $item_id, '_prdd_resch_rem_bal_order_id', $new_order_id, '' );

                    $additional_note = sprintf( __( 'Please pay difference amount via Order #%s', 'woocommerce-prdd' ), $new_order_id );
                } else if ( $difference_amount < 0 ) {
                    $additional_note = __( "Please contact shop manager for differences in amount", 'woocommerce-prdd' );
                }

                self::prdd_add_reschedule_order_note( $order_id, $old_deliveries, $delivery_data, $item_obj->get_name('view'), $additional_note );

                // Trigger invoice email for additional order. This needs to be done after adding order notes
                if ( $difference_amount > 0 ) {
                    $invoice_email = new WC_Email_Customer_Invoice();
                    $invoice_email->trigger( $new_order_id );
                }

                do_action( 'prdd_delivery_rescheduled_admin', $item_id );
            }
            
            die();
        }

        /**
         * Returns the different amount for the new selected date and the old delivery date. 
         *
         * @globals resource $wpdb WordPress object.
         *
         * @param string $item_id Item ID. 
         * @param resource $item_obj Cart item object. 
         * @param string $order_id Order ID.
         * @param string $product_id Product ID. 
         * @param string $variation_id Variation ID. 
         * @param resource $product_obj Product object. 
         * @param array $old_deliveries Delivery data array. 
         * @param array $delivery_data Delivery data array. 
         * 
         * @return int|string Difference Amount. 
         *
         * @since 2.4
         */
        public static function prdd_get_difference_amount( $item_id, $item_obj, $order_id, $product_id, $variation_id, $product_obj, $old_deliveries, $delivery_data ) {
            global $wpdb;
            if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
                $product_type = $product_obj->get_type();
            } else {
                if ( $variation_id == '' || $variation_id == '0' ) {
                    $product_type = $product_obj->product_type;
                } else {
                    $product_type = $product_obj->parent->product_type;
                }
            }
            
            $price = prdd_common::prdd_get_price( $product_id, $variation_id, $product_type );
            $wpa_charges = wc_get_order_item_meta( $item_id, '_prdd_wpa_prices', true );

            $old_delivery_charges = wc_get_order_item_meta( $item_id, get_option( 'delivery_item-meta-charges' ), true );
            
            if( $old_delivery_charges == '' ) {
                $old_delivery_charges = 0;
            }

            $old_product_total = $price + $wpa_charges + $old_delivery_charges;
            
            $difference_amount = 0;
            if( isset( $delivery_data[ 'delivery_price' ] ) && $delivery_data[ 'delivery_price' ] != '' ) {
                $new_total = $price + $wpa_charges + $delivery_data[ 'delivery_price' ] ;
                $difference_amount = $new_total - $item_obj->get_total( 'view' );

            }

            return $difference_amount;
        }

        /**
         * Used for updating the delivery details for a particular Item ID
         * 
         * @globals resource $wpdb WordPress object.
         *
         * @param string $order_id Order ID
         * @param string $item_id Item ID
         * @param string $old_start Old Start Date
         * @param string $old_end Old End Date
         * @param string $old_time Old Time
         * @param string $product_id Product ID
         * @param array $booking_data Booking Data
         * @param string $booking_id Booking ID
         * @param int $quantity Quantity
         *
         * @since 2.4
         */
        public static function prdd_update_item_deliveries( $order_id, $item_id, $old_start, $old_time, $product_id, $variation_id, $delivery_data, $quantity ) {

            global $wpdb;

            $date_to_convert = date( 'Y-m-d', strtotime( $delivery_data[ 'hidden_date' ] ) );
            $time_slot_price = "";
            wc_update_order_item_meta( $item_id, get_option( 'delivery_item-meta-date' ), $delivery_data[ 'delivery_date' ], '' );
            wc_update_order_item_meta( $item_id, '_prdd_date', $date_to_convert, '' );

            if ( isset( $delivery_data[ 'time_slot' ] ) && $delivery_data[ 'time_slot' ] !== '' ) {

                $timeslot = $delivery_data['time_slot'];
                $timeslots = explode( '-', $timeslot );

                $db_timeslot = date( 'G:i', strtotime( $timeslots[ 0 ] ) );
            
                wc_update_order_item_meta( $item_id, get_option( 'delivery_item-meta-time' ), $delivery_data['time_slot'], '' );
                wc_update_order_item_meta( $item_id, '_prdd_time_slot', $db_timeslot, '' );
            }
        }

        /**
         * Add Order Notes when deliveries are rescheduled
         * 
         * @param string|int $order_id Order ID
         * @param array $old_deliveries Old Booking data array
         * @param array $delivery_data New Booking data array
         * 
         * @since 2.4
         */
        public function prdd_add_reschedule_order_note( $order_id, $old_deliveries, $delivery_data, $item_name, $additional_note ) {
            $order_obj = wc_get_order( $order_id );
            if( isset( $old_deliveries[ 'delivery_date'] ) && $old_deliveries[ 'delivery_date' ] !== '' &&
                isset( $delivery_data[ 'delivery_date'] ) && $delivery_data[ 'delivery_date' ] !== '' && 
                isset( $old_deliveries[ 'time_slot' ] ) && $old_deliveries[ 'time_slot' ] !== '' &&
                isset( $delivery_data[ 'time_slot' ] ) && $delivery_data[ 'time_slot' ] !== '' ) {
                $note_details_old = $old_deliveries[ 'delivery_date' ] . ' ' . $old_deliveries[ 'time_slot' ];
                $note_details_new = $delivery_data[ 'delivery_date' ] . ' ' . $delivery_data[ 'time_slot' ];
            } else {
                $note_details_old = $old_deliveries[ 'delivery_date' ];
                $note_details_new = $delivery_data[ 'delivery_date' ];
            }

            $order_note = sprintf( __( 'Delivery has been rescheduled from <strong>%s</strong> to <strong>%s</strong> for <strong>%s</strong>.', 'woocommerce-booking' ), $note_details_old, $note_details_new, $item_name );

            $order_note = $order_note . $additional_note;
            $order_obj->add_order_note( $order_note, 1, false );
        }


        /**
         * Register additional settings for Edit Deliveries
         * 
         * @hook admin_init
         *
         * @since 2.4
         */
        public function prdd_add_edit_settings() {
            add_settings_field(
                'prdd_enable_delivery_edit',
                __( 'Allow Deliveries to be editable:', 'woocommerce-prdd' ),
                array( &$this, 'prdd_allow_deliveries_callback' ),
                'prdd_settings_page',
                'prdd_delivery_settings_section',
                array( __( 'Enabling this option will allow Deliveries to be editable from Cart and Checkout page', 'woocommerce-prdd' ) )
            );

            add_settings_field(
                'prdd_enable_delivery_reschedule',
                __( 'Allow Deliveries to be reschedulable:', 'woocommerce-prdd' ),
                array( &$this, 'prdd_allow_reschedulable_callback' ),
                'prdd_settings_page',
                'prdd_delivery_settings_section',
                array( __( 'Enabling this option will allow Deliveries to be reschedulable from My Account page', 'woocommerce-prdd' ) )
            );

            add_settings_field(
                'prdd_delivery_reschedule_days',
                __( 'Minimum number of days for rescheduling:', 'woocommerce-prdd' ),
                array( &$this, 'prdd_reschedulable_days_callback' ),
                'prdd_settings_page',
                'prdd_delivery_settings_section',
                array( __( 'Minimum number of days before the delivery date, after which Delivery cannot be rescheduled.', 'woocommerce-prdd' ) )
            );
        }

        /**
         * Call back for displaying settings option for Cart/Checkout page
         *
         * @param array $args Additional data for the settings field.
         *
         * @since 2.4
         */
        public function prdd_allow_deliveries_callback( $args ) {
            $saved_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            $prdd_enable_delivery_option = '';
            if( isset( $saved_settings->prdd_enable_delivery_edit ) && 
                $saved_settings->prdd_enable_delivery_edit === 'on' ){
                $prdd_enable_delivery_option = 'checked';
            }
            
            ?>
                <input 
                    type="checkbox" 
                    id="prdd_enable_delivery_edit" 
                    name="woocommerce_prdd_global_settings[prdd_enable_delivery_edit]"
                    <?php echo $prdd_enable_delivery_option; ?>
                />
                <label for="prdd_enable_delivery_edit">
                    <?php echo $args[ 0 ]; ?>
                </label>
            <?php
        }

        /**
         * Call back for displaying settings option for My Account page
         *
         * @param array $args Additional data for the settings field.
         *
         * @since 2.4
         */
        public function prdd_allow_reschedulable_callback( $args ) {
            $saved_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            $prdd_enable_delivery_reschedule = '';
            if( isset( $saved_settings->prdd_enable_delivery_reschedule ) && 
                $saved_settings->prdd_enable_delivery_reschedule === 'on' ){
                $prdd_enable_delivery_reschedule = 'checked';
            }
            
            ?>
                <input 
                    type="checkbox" 
                    id="prdd_enable_delivery_reschedule" 
                    name="woocommerce_prdd_global_settings[prdd_enable_delivery_reschedule]"
                    <?php echo $prdd_enable_delivery_reschedule; ?>
                />
                <label for="prdd_enable_delivery_reschedule">
                    <?php echo $args[ 0 ]; ?>
                </label>
            <?php
        }

        /**
         * Call back for displaying settings option for rescheduling period
         *
         * @param array $args Additional data for the settings field.
         *
         * @since 2.4
         */
        public function prdd_reschedulable_days_callback( $args ) {
            
            $saved_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            $prdd_delivery_reschedule_days = 0;
            if( isset( $saved_settings->prdd_delivery_reschedule_days ) && 
                $saved_settings->prdd_delivery_reschedule_days !== '' ){

                $prdd_delivery_reschedule_days = $saved_settings->prdd_delivery_reschedule_days;
            }
            
            ?>
                <input 
                    type="text" 
                    id="prdd_delivery_reschedule_days" 
                    name="woocommerce_prdd_global_settings[prdd_delivery_reschedule_days]"
                    value="<?php echo $prdd_delivery_reschedule_days; ?>"
                />
                <label for="prdd_delivery_reschedule_days">
                    <?php echo $args[ 0 ]; ?>
                </label>
            <?php
        }

    }
}
$prdd_edit_deliveries_class = new prdd_edit_deliveries_class();
API documentation generated by ApiGen