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 
<?php
/**
 * PRDD Delivery charges for timeslots. 
 *
 * @author  Tyche Softwares
 * @package Product-Delivery-Date-Pro-for-WooCommerce/Delivery-Charges
 * @since   1.0
 */

if ( !class_exists( 'prdd_timeslot_price' ) ) {

    /**
     * Timeslot delivery charges class.
     *
     * @since 1.0
     */
    class prdd_timeslot_price {

        /**
         * Default Constructor
         * 
         * @since 1.0
         */
        public function __construct() {
            add_action( 'prdd_after_lockout_time', array( &$this, 'timeslot_price_field' ) );
            add_filter( 'prdd_save_slot_field_settings', array( &$this, 'timeslot_price_save' ), 10, 2 );
            add_action( 'prdd_add_column_names', array( &$this,'timeslot_price_column_name' ), 10, 1 ); 
            add_filter( 'prdd_add_column_value', array( &$this, 'timeslot_price_column_value' ), 10, 2 );
            //add_action( 'prdd_display_price_div', array( &$this, 'timeslot_price_div' ), 20, 1 );
            add_action( 'prdd_print_hidden_fields', array( &$this, 'timeslot_hidden_fields' ), 10, 1 );
            //add_action( 'prdd_display_updated_addon_price', array( &$this, 'timeslot_display_updated_price' ), 3, 3 );
            add_filter( 'prdd_addon_add_cart_item_data', array( &$this, 'timeslot_add_to_cart' ), 9, 4 );
            add_filter( 'prdd_get_cart_item_from_session', array( &$this, 'get_timeslot_cart_item_from_session' ), 9, 2 );
            add_filter( 'prdd_get_item_data', array( &$this, 'timeslot_get_item_data' ), 9, 2 );
            add_action( 'prdd_update_order', array( &$this, 'timeslot_order_item_meta' ), 9, 2 );
        }
            
        /**
         * Time slot charges field on admin edit product page. 
         * 
         * @hook prdd_after_lockout_time
         * @since 1.0
         */

        function timeslot_price_field() {
            ?>
            <tr>
                <th>
                    <label for="delivery_price_time"><?php _e( 'Delivery charge added for the time slot:', 'woocommerce-prdd' ); ?></label><br>
                </th>
                <td style="width:380px">
                    <input type="text" style="width:100px;" name="prdd_price_time[0]" id="prdd_price_time[0]" value="" />
                    <input type="hidden" id="prdd_slot_count" name="prdd_slot_count" value="[0]" />
                </td>
                <td>
                    <img class="help_tip" width="16" height="16" data-tip="<?php _e( 'Please enter price for the timeslot.', 'woocommerce-prdd' ); ?>" src="<?php echo plugins_url() ;?>/woocommerce/assets/images/help.png" />
                </td>
            </tr>
            <?php
        }
        
        /**
         * Save time slot charges on admin edit product page. 
         * 
         * @hook prdd_save_slot_field_settings
         *
         * @param array $date_time_settings Time slots settings to save. 
         * @param int|string $post_id Product ID. 
         *
         * @return array Time slots settings to save with time slot charges.
         * @since 1.0
         */
        function timeslot_price_save( $date_time_settings, $post_id ) {
            $woo_prdd_dates = get_post_meta( $post_id, 'woocommerce_prdd_settings', true );
            $weekdays = prdd_get_delivery_arrays( 'prdd_weekdays' );
            foreach ( $weekdays as $n => $day_name ) {
                if ( isset( $_POST[ $n ] ) && $_POST[ $n ] == 'on' || isset( $_POST[ $n ] ) && $_POST[ $n ] == '') {
                    $new_day_arr[ $n ] = $_POST[ $n ];
                }
            }
        
            $slot_count = explode( "[", $_POST[ 'prdd_slot_count' ] );
            $slot_count_value = intval( $slot_count[ 1 ] );
            $specific_delivery = array();
            if ( isset( $_POST[ 'prdd_specific_date' ] ) ) {
                $specific_delivery = $_POST[ 'prdd_specific_date' ];
            }
            $specific_delivery_dates = explode( ",", $specific_delivery );
            if( $specific_delivery != "" ) {
                foreach ( $specific_delivery_dates as $day_key => $day_value ) {
                    $date_tmstmp = strtotime( $day_value );
                    $date_save = date( 'Y-m-d',$date_tmstmp );
                    if ( isset( $_POST[ 'prdd_enable_time' ] ) && $_POST[ 'prdd_enable_time'] == "on" ) {
                        $j = 1;
                        if ( isset($woo_prdd_dates[ 'prdd_time_settings' ] ) && is_array( $woo_prdd_dates[ 'prdd_time_settings' ] ) ) { 
                            if ( array_key_exists( $day_value, $woo_prdd_dates[ 'prdd_time_settings' ] ) ) {
                                foreach ( $woo_prdd_dates[ 'prdd_time_settings' ][ $day_value ] as $dtkey => $dtvalue ) {
                                    $date_time_settings[ $day_value ][ $j ] = $dtvalue;
                                    $j++;
                                }
                            }
                        }
                        $k = 1;
                        for( $i = ( $j + 1 ); $i <= ( $j + $slot_count_value ); $i++ ) {
                            if( $_POST[ 'prdd_from_slot_hrs' ][ $k ] != 0 ) {
                                $time_settings[ 'slot_price' ] = $_POST[ 'prdd_price_time' ][ $k ];
                                $date_time_settings[ $day_value ][ $i ] = array_merge( $time_settings, $date_time_settings[ $day_value ][ $i ]);
                            }
                            $k++;
                        }
                    }
                }
            }
            if ( isset( $new_day_arr ) && count( $new_day_arr ) > 0 ) {
                foreach ( $new_day_arr as $wkey => $wvalue ) {
                    if( $wvalue == 'on' ) {
                        if ( isset( $_POST[ 'prdd_enable_time' ] ) && $_POST['prdd_enable_time' ] == "on" ) {
                            $j = 1;
                            if ( isset( $woo_prdd_dates[ 'prdd_time_settings' ] ) && is_array( $woo_prdd_dates[ 'prdd_time_settings' ] ) ) { 
                                if ( array_key_exists( $wkey, $woo_prdd_dates[ 'prdd_time_settings' ] ) ) {
                                    foreach ( $woo_prdd_dates[ 'prdd_time_settings' ][ $wkey ] as $dtkey => $dtvalue ) {
                                        $date_time_settings[ $wkey ][ $j ] = $dtvalue;
                                        $j++;
                                    }
                                }
                            }
                            $k = 1;
                            for($i = ( $j + 1 ); $i <= ( $j + $slot_count_value ); $i++ ) {
                                if( isset( $_POST[ 'prdd_from_slot_hrs' ][ $k ] ) && $_POST[ 'prdd_from_slot_hrs' ][ $k ] != 0 ) {
                                    $time_settings[ 'slot_price' ] = $_POST[ 'prdd_price_time' ][ $k ];
                                    $date_time_settings[ $wkey ][ $i ] = array_merge( $time_settings, $date_time_settings[ $wkey ][ $i ] );
                                }
                                $k++;
                            }
                        }
                    }
                }
            }
            return $date_time_settings;
        }
        
        /**
         * Add Time slot price column on Manage Dates, Time slots tab on admin edit product page. 
         * 
         * @hook prdd_add_column_names
         *
         * @param int|string $product_id Product ID. 
         *
         * @since 1.0
         */

        function timeslot_price_column_name( $product_id ) {
            ?>
            <th> <?php _e( 'Time Slot Price', 'woocommerce-prdd' ); ?> </th>
            <?php
        }
        
        /**
         * Display Time slot price on Manage Dates, Time slots tab on admin edit product page. 
         * 
         * @hook prdd_add_column_value
         *
         * @param int|string $slot_price Time slot price. 
         * @param array $date_time_settings Time slots added. 
         *
         * @return int|string Time slot price. 
         * @since 1.0
         */
        function timeslot_price_column_value( $slot_price, $date_time_settings ) {
            foreach ( $date_time_settings as $k => $v ) {
                if ( isset( $v[ 'slot_price' ] ) ) {
                    $slot_price[] = $v[ 'slot_price' ];
                } else {
                    $slot_price[] = 0;
                }
            }
            return $slot_price;
        }
        
        /**
         * Display Time slot price on frontend product page. 
         * 
         * @hook prdd_display_price_div
         *
         * @todo Unused function.
         *
         * @param int|string $product_id Product ID. 
         *
         * @since 1.0
         */

        function timeslot_price_div( $product_id ) {
            $variable_timeslot_price = prdd_timeslot_price::get_timeslot_variable_price( $product_id );
            $currency_symbol = get_woocommerce_currency_symbol();
            $show_price = 'block';
            $print_code = '<div id=\"show_addon_price\" name=\"show_addon_price\" class=\"show_addon_price\" style=\"display:' . $show_price . ';\">' . $currency_symbol . '0<\/div>';
            if( isset( $variable_timeslot_price ) && $variable_timeslot_price == 'yes' ) {
                print('<script type="text/javascript">
                    if ( jQuery( "#show_addon_price" ).length == 0 ) {
                        document.write( "' . $print_code . '" );
                    } 
                </script>');
            }
        }
        
        /**
         * Add hidden field required for time slot charges on frontend product page.  
         *
         * @hook prdd_print_hidden_fields
         *
         * @param int|string $product_id Product ID. 
         *
         * @since 1.0
         */
        function timeslot_hidden_fields( $product_id ) {
            $variable_timeslot_price = prdd_timeslot_price::get_timeslot_variable_price( $product_id );
            print( '<input type="hidden" id="wapbk_hidden_variable_timeslot_price" name="wapbk_hidden_variable_timeslot_price" value="' . $variable_timeslot_price . '">' );
        }
        
        /**
         * Checks if the time slot price is added for any of the time slot for the product. 
         *
         * @param int|string $product_id Product ID. 
         *
         * @return string 'yes' if time slot price is added, else 'no'.
         * @since 1.0
         */
        function get_timeslot_variable_price( $product_id ) {
            $slot_price = array();
            $prdd_settings = get_post_meta( $product_id, 'woocommerce_prdd_settings', true);
            if ( isset( $prdd_settings[ 'prdd_enable_time' ] ) && $prdd_settings[ 'prdd_enable_time' ] == 'on' ) {
                $time_slot_arr = $prdd_settings[ 'prdd_time_settings' ];
                if( $time_slot_arr == '' || $time_slot_arr == '' ) {
                    $time_slot_arr = array();
                }
                if ( is_array( $time_slot_arr ) && count( $time_slot_arr ) > 0 ) {
                    foreach( $time_slot_arr as $key => $value ) {
                        foreach ( $value as $k => $v ) {
                            if ( isset( $v[ 'slot_price' ] ) && $v[ 'slot_price' ] > 0 ) {
                                $slot_price[] = $v[ 'slot_price' ];
                            }
                        }
                    }
                }
            }
            $variable_timeslot_price = 'no';
            if( count( $slot_price ) > 0 ) {
                $variable_timeslot_price = 'yes';
            }
            return $variable_timeslot_price;
        }
        
        /**
         * Add time slot delivery charges to the cart item when add to cart button is clicked
         *
         * @hook prdd_addon_add_cart_item_data
         *
         * @param array $cart_arr WooCommerce cart array.
         * @param int|string $product_id Product ID. 
         * @param int|string $variation_id Variation ID for the selected attributes. 
         * @param array $cart_item_meta Cart item meta array. 
         *
         * @return array WooCommerce cart array.
         *
         * @since 1.0
         */

        function timeslot_add_to_cart( $cart_arr, $product_id, $variation_id, $cart_item_meta ) {
            $global_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            // product type
            $_product = wc_get_product( $product_id );
            if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
                $product_type = $_product->get_type();
            } else {
                $product_type = $_product->product_type;    
            }
            // delivery date and time slot
            $delivery_date = '';
            if( isset( $cart_arr[ 'hidden_date' ] ) ) {
                $delivery_date = $cart_arr[ 'hidden_date' ];    
            }
            
            $price = prdd_common::prdd_get_price( $product_id, $variation_id, $product_type );

            $wpa_options_price = prdd_common::woo_product_addons_compatibility_cart( $cart_item_meta );
            $price = $price + $wpa_options_price;

            if ( isset( $cart_arr[ 'time_slot' ] ) ) {
                if ( is_array( $cart_arr[ 'time_slot' ] ) ) {
                    $time_slot_str = "";
                    foreach ( $cart_arr['time_slot'] as $key => $value ) {
                        $time_slot_str .= $value . ",";
                    }
                    $time_slot_length = strlen( $time_slot_str );
                    $time_slot = substr( $time_slot_str,0,$time_slot_length - 1 );
                } else {
                    $time_slot = $cart_arr[ 'time_slot' ];
                }

                $time_slot_price = $this->get_price( $product_id, $variation_id, $product_type, $delivery_date, $time_slot );
                if( $time_slot_price != '' && $time_slot_price != 0 ) {
                    // Prices
                    $cart_arr[ 'price' ] = $price + $time_slot_price;
                    $cart_arr[ 'time_slot_charges' ] = $time_slot_price;
                    if ( isset( $global_settings->prdd_enable_rounding ) && $global_settings->prdd_enable_rounding == "on" && isset( $cart_arr[ 'price' ] ) ) {
                        if ( isset( $cart_arr[ 'price' ] ) ) {
                            $cart_arr[ 'price' ] = round( $cart_arr[ 'price' ] );
                        }
                    }
                }
            }
            return $cart_arr;
        }
        
        /**
         * This function adjust the prices calculated from the plugin in the cart session.
         *  
         * @hook prdd_get_cart_item_from_session
         * 
         * @param array $cart_item Cart item data.
         * @param array $values $_POST values.
         * 
         * @return array Cart item data with delivery details.
         * @since 1.0
         */
        function get_timeslot_cart_item_from_session( $cart_item, $values ) {
            // fetch the delivery settings
            $prdd_settings = get_post_meta( $cart_item[ 'product_id' ], 'woocommerce_prdd_settings', true );
            if ( isset( $prdd_settings[ 'prdd_enable_time' ] ) && $prdd_settings[ 'prdd_enable_time' ] == 'on' ) {
                if ( isset( $values[ 'prdd_delivery' ] ) ) {
                    $cart_item[ 'prdd_delivery' ] = $values[ 'prdd_delivery' ];
                    if( $cart_item[ 'prdd_delivery' ][0][ 'date' ] != '' ) {
                        // do not adjust the price if seasonal pricing is active for the product
                        $cart_item = $this->add_cart_item( $cart_item );
                    }
                }
            }
            return $cart_item;
        }
        
        /**
         * This function adds the time slot prices data on the Cart and Checkout page.
         *
         * @hook prdd_get_item_data
         *
         * @param array $other_data Additional data to be displayed.
         * @param array $cart_item Cart item data.
         * 
         * @return array Additional data to be displayed with delivery fields.
         * @since 1.0
         */

        function timeslot_get_item_data( $other_data, $cart_item ) {
            $global_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            $currency_symbol = get_woocommerce_currency_symbol();
            if ( isset( $cart_item[ 'prdd_delivery' ] ) ) {
                $price = '';
                foreach ( $cart_item['prdd_delivery'] as $delivery ) {
                    if ( isset( $delivery['time_slot_charges'] ) ) {
                        if ( isset( $global_settings->prdd_enable_rounding ) && $global_settings->prdd_enable_rounding == "on" ) {
                            $delivery['time_slot_charges'] = round( $delivery['time_slot_charges'] );
                        } else {
                            $delivery['time_slot_charges']  =   $delivery['time_slot_charges'];
                        }
                        $time_slot_charges = get_option( 'delivery_item-cart-charges' );
                        $price .= "$currency_symbol" . $delivery[ 'time_slot_charges'];
                    }
                }
            }
             
            if ( isset( $delivery[ 'time_slot_charges' ] ) ) {
                $other_data[]           = array(
                    'name'    => get_option( 'delivery_item-cart-charges' ),
                    'display' => $price
                );
            }
            return $other_data;
        }
        
        /**
         * This function adjust the extra prices for the product with the price calculated from the plugin.
         *
         * @globals resource $wpdb WordPress object
         *
         * @param array $cart_item Cart item array
         * @return array Cart item array with adjusted price
         *
         * @since 1.0 
         */

        function add_cart_item( $cart_item ) {
            global $wpdb;
            $product_type = 'simple';
            if ( $cart_item[ 'variation_id' ] != '' ) {
                $product_type = 'variable';
            }
            $price = prdd_common::prdd_get_price( $cart_item[ 'product_id' ], $cart_item[ 'variation_id' ], $product_type );
            
            // Adjust price if addons are set
            if ( isset( $cart_item[ 'prdd_delivery' ] ) ) {
                $extra_cost = 0;
                foreach ( $cart_item[ 'prdd_delivery' ] as $addon ) {
                    if ( isset( $addon[ 'price' ] ) && $addon[ 'price' ] > 0 ) {
                        $extra_cost += $addon[ 'price' ];
                    }
                }
                
                if( version_compare( get_option( 'woocommerce_version' ), "3.0.0", ">=" ) ) {
                    $cart_item['data']->set_price( $extra_cost );
                } else {
                    $extra_cost = $extra_cost - $price;
                    $cart_item['data']->adjust_price( $extra_cost );
                }
            }       
            return $cart_item;
        }
        
        /**
         * Returns time slot prices added for the selected delivery date and time slot for the product.
         *
         * @param int|string $product_id Product ID. 
         * @param int|string $variation_id Variation ID. 
         * @param string $product_type Product type. 
         * @param string $delivery_date Selected delivery date. 
         * @param string $time_slot Selected time slot. 
         *
         * @return string Time slot price.
         *
         * @since 1.0
         */

        public static function get_price( $product_id, $variation_id, $product_type, $delivery_date, $time_slot ) {
            // set the slot price as the product base price
            $time_slot_price = $time_slot_price_total = 0;
            
            $prdd_settings = get_post_meta( $product_id, 'woocommerce_prdd_settings', true);
            if ( $time_slot != '' ) {
                // Check if multiple time slots are enabled
                $seperator_pos = strpos( $time_slot, "," );
                if ( isset( $seperator_pos ) && $seperator_pos != "" ) {
                    $time_slot_array = explode( ",", $time_slot );
                } else {
                    $time_slot_array = array();
                    $time_slot_array[] = $time_slot;
                }
                for( $i = 0; $i < count( $time_slot_array ); $i++ ) {
                    $timeslot_explode = explode( '-', $time_slot_array[ $i ] );
                    $timeslot_explode[0] = date( 'G:i', strtotime( $timeslot_explode[ 0 ] ) );
                    if ( isset( $timeslot_explode[ 1 ] ) && $timeslot_explode[ 1 ] != '' ) {
                        $timeslot_explode[1] = date( 'G:i', strtotime( $timeslot_explode[ 1 ] ) );
                    }
                    $from_hrs = explode( ':', $timeslot_explode[0] );
                    $to_hrs = array(
                            '0' => '0',
                            '1' => '00');
                    if ( isset( $timeslot_explode[ 1 ] ) && $timeslot_explode[ 1 ] != '' ) {
                        $to_hrs = explode( ':', $timeslot_explode[ 1 ] );
                    }
                    if ( isset( $prdd_settings[ 'prdd_time_settings' ] ) && count( $prdd_settings[ 'prdd_time_settings' ] ) > 0 ) {
                        foreach ( $prdd_settings[ 'prdd_time_settings' ] as $key => $value ) {
                            $delivery_date_to_check = date( 'j-n-Y', strtotime( $delivery_date ) );
                            if ( $key == $delivery_date_to_check ) {
                                foreach ( $value as $k => $v ) {
                                    if ( ( intval( $from_hrs[ 0 ] ) == intval( $v[ 'from_slot_hrs' ] ) ) && ( intval( $from_hrs[ 1 ] ) == intval( $v[ 'from_slot_min' ] ) ) && ( intval( $to_hrs[ 0 ] ) == intval( $v[ 'to_slot_hrs' ] ) ) && ( intval( $to_hrs[ 1 ] ) == intval( $v[ 'to_slot_min' ] ) ) ) {
                                        if ( isset( $v[ 'slot_price' ] ) && $v[ 'slot_price' ] != '' ) {
                                            $time_slot_price_total += $v[ 'slot_price' ];
                                        }
                                    }
                                }
                            } else {
                                $weekday = date( 'w',strtotime( $delivery_date ) );
                                $delivery_weekday = 'prdd_weekday_' . $weekday;
                                if ( $key == $delivery_weekday ) {
                                    foreach ( $value as $k => $v) {
                                        if ( ( intval( $from_hrs[ 0 ] ) == intval( $v[ 'from_slot_hrs' ] ) ) && ( intval( $from_hrs[ 1 ] ) == intval( $v[ 'from_slot_min' ] ) ) && ( intval( $to_hrs[ 0 ] ) == intval( $v[ 'to_slot_hrs' ] ) ) && ( intval( $to_hrs[ 1 ] ) == intval( $v[ 'to_slot_min' ] ) ) ) {
                                            if ( isset( $v[ 'slot_price' ] ) && $v[ 'slot_price' ] != '' ) {
                                                $time_slot_price_total += $v[ 'slot_price' ];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if ( $time_slot_price_total != 0 ) {
                    $time_slot_price = $time_slot_price_total;
                    $time_slot_price = $time_slot_price / count( $time_slot_array );
                }
            }
            return $time_slot_price;
        }
        
        /**
         * Add time slot prices as order item meta when order is placed.
         *
         * @hook prdd_update_order
         * 
         * @globals resource $wpdb WordPress object.
         * 
         * @param array $values Cart item values. 
         * @param resource $order Order object. 
         *
         * @since 1.0
         */

        public static function timeslot_order_item_meta( $values, $order ) {
            global $wpdb;
            $product_id = $values['product_id'];
            $quantity = $values['quantity'];
            if( isset( $values['prdd_delivery'] ) ) {
                $delivery = $values[ 'prdd_delivery' ];
            } else {
                $delivery = array();
            }

            $currency_symbol = get_woocommerce_currency_symbol();
            $saved_settings = json_decode( get_option( 'woocommerce_prdd_global_settings' ) );
            $order_item_id = $order->order_item_id;
            $order_id = $order->order_id;
            if( isset( $delivery[ 0 ][ 'time_slot_charges' ] ) && $delivery[ 0 ][ 'time_slot_charges' ] != '' ) {
                wc_add_order_item_meta( $order_item_id, get_option( 'delivery_item-meta-charges' ), $currency_symbol . $delivery[ 0 ][ 'time_slot_charges' ] );
            }
        }
    }
}
$prdd_timeslot_price = new prdd_timeslot_price();
API documentation generated by ApiGen