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

Packages

  • BKAP
    • Addons
    • Admin-Bookings
    • Attribute-Lockout
    • Block-Pricing
    • Booking-Box
    • Booking-Confirmation
    • Booking-Process
    • Cancel-Order
    • Cart
    • Checkout-Process
    • Core
    • Date-Time
    • Emails
    • Functions
    • Global-Function
    • Global-Settings
    • Google-Calendar-Sync
    • ICS
    • Import-Booking
    • Labels
    • License
    • Menus
    • Meta-Boxes
    • Reschedule
    • Resources
    • Search-Widget
    • Special-Price
    • Uninstall
    • Validation
    • Variation-Lockout
    • Vendors
      • Dokan
      • WC-Vendors
    • View-Bookings
  • None

Classes

  • bkap_addon_compatibility_class
  • bkap_admin_bookings
  • bkap_approve_booking
  • bkap_attributes
  • bkap_block_booking
  • BKAP_Booking
  • bkap_booking_box_class
  • bkap_booking_confirmation
  • bkap_booking_process
  • BKAP_Bookings_View
  • bkap_calendar_sync
  • bkap_cancel_order
  • bkap_cart
  • bkap_checkout
  • bkap_common
  • BKAP_Customer_Meta_Box
  • BKAP_Details_Meta_Box
  • bkap_dokan_calendar_class
  • bkap_dokan_class
  • bkap_dokan_orders_class
  • bkap_dokan_products_class
  • bkap_edit_bookings_class
  • BKAP_Email_Booking_Cancelled
  • BKAP_Email_Booking_Confirmed
  • BKAP_Email_Booking_Rescheduled_Admin
  • BKAP_Email_Imported_Event
  • BKAP_Email_Manager
  • BKAP_Email_New_Booking
  • BKAP_Gcal
  • BKAP_Gcal_Event
  • bkap_gcal_sync_settings
  • bkap_global_settings
  • BKAP_Google_Events_View
  • bkap_ics
  • bkap_license
  • bkap_load_scripts_class
  • BKAP_OPC_Addon
  • BKAP_Payment_Gateway
  • BKAP_Product_Resource
  • bkap_rescheduled_order_class
  • BKAP_Resource_Details_Meta_Box
  • BKAP_Save_Meta_Box
  • bkap_special_booking_price
  • bkap_timeslot_price
  • bkap_validation
  • bkap_variations
  • BKAP_Vendors
  • bkap_wc_vendors
  • bkap_wcv_product
  • Booking_Information_In_Voucher_Template
  • Class_Bkap_Product_Resource
  • Custom_WooCommerce_Widget_Product_Search
  • EDD_BOOK_Plugin_Updater
  • global_menu
  • import_bookings
  • product_gcal_settings
  • view_bookings
  • WAPBK_Import_Bookings_Table
  • WAPBK_View_Bookings_Table
  • woocommerce_booking

Functions

  • addDayswithdate
  • bkap_400_create_meta
  • bkap_400_recurring_data
  • bkap_400_update_db_tab
  • bkap_400_update_enable_specific
  • bkap_400_update_enable_week_blocking
  • bkap_400_update_holidays
  • bkap_400_update_ranges
  • bkap_400_update_recurring_lockout
  • bkap_400_update_settings
  • bkap_400_update_special
  • bkap_400_update_specific
  • bkap_410_create_meta
  • bkap_410_update_block_pricing_option_values_in_new_way
  • bkap_410_update_fixed_blocks
  • bkap_410_update_price_ranges
  • bkap_410_update_settings
  • bkap_420_add_gcal_posts
  • bkap_420_add_gcal_tour_posts
  • bkap_420_gcal_batch_size
  • bkap_420_gcal_meta
  • bkap_420_update_settings
  • bkap_add_days_to_date
  • bkap_array_of_given_date_range
  • bkap_booked_resources
  • bkap_booking_posts_for_resource
  • bkap_calculate_bookings_for_resource
  • bkap_check_booking_available
  • bkap_check_day_booking_available
  • bkap_check_for_max_date
  • bkap_check_for_min_date
  • bkap_check_holiday
  • bkap_check_in_custom_holiday_range
  • bkap_check_resource_available
  • bkap_check_resource_booked_in_date_range
  • bkap_db_420_1
  • bkap_db_420_2
  • bkap_delete_event_from_gcal
  • bkap_delete_folder_and_files
  • bkap_delete_options
  • bkap_delete_tables
  • bkap_find_matching_product_variation
  • bkap_generate_bookable_data
  • bkap_get_book_arrays
  • bkap_get_book_t
  • bkap_get_booked
  • bkap_get_booked_checkout
  • bkap_get_custom_posts
  • bkap_get_dateToCal
  • bkap_get_day_between_Week
  • bkap_get_db_count
  • bkap_get_escapeString
  • bkap_get_lockout
  • bkap_get_month_range
  • bkap_get_post_meta
  • bkap_get_posted_availability
  • bkap_get_total_timeslot_maximum_booking
  • bkap_get_week_range
  • bkap_import_events_cron
  • bkap_insert_event_to_gcal
  • bkap_manual_db_update_v420
  • bkap_orderby_date_key
  • bkap_save_resources
  • bkap_sort_by_from_time
  • bkap_update_po_file
  • bkap_vendors_get_bookings
  • bkap_widgets_init
  • bkapSortByPriority
  • calback_bkap_max_date
  • check_in_fixed_block_booking
  • check_in_range
  • check_in_range_abp
  • check_in_range_holidays
  • check_in_range_weekdays
  • create_posts
  • get_availability_for_date
  • get_booked_multiple
  • get_bookings_for_date
  • get_bookings_for_range
  • get_date_lockout
  • get_slot_availability
  • get_slot_lockout
  • get_standard_decimal_thousand_separator_price
  • is_booking_active
  • woocommerce_bkap_add_cron_schedule
  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 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 
<?php
/**
 * Bookings and Appointment Plugin for WooCommerce
 *
 * Import Booking related functionalities handled in this class
 *
 * @author      Tyche Softwares
 * @package     BKAP/Import-Booking
 * @since       3.6
 * @category    Classes
 */

class import_bookings {

    /**
     * This function will map the imported calendar events to the product and generate the booking.
     *
     * @since 3.6
     * @global object $wpdb Global wpdb Object
     */

    public static function bkap_map_imported_event() {
    
        // default notices to blanks
        $notice                 = '';
        $message                = '';
        global $bkap_date_formats;
    
        $google_post_id         = $_POST[ 'ID' ]; 
        $option_name            = get_post_meta( $google_post_id, '_bkap_event_option_name', true ); 
        $imported_event_details = json_decode( get_option( $option_name ) );
        
        $product_id             = $_POST[ 'product_id' ];
        
        if( $_POST[ 'type' ] == "by_post" ) {
            
            if ( get_post_type( $google_post_id ) === 'bkap_gcal_event' ) {
                $booking = new BKAP_Gcal_Event( $google_post_id );
            }
            
            $booking_details[ 'product_id' ]    = $product_id;
            $booking_details[ 'start' ]         = $booking->start;
            $booking_details[ 'end' ]           = $booking->end;
            $booking_details[ 'summary' ]       = $booking->summary;
            $booking_details[ 'description' ]   = $booking->description;
            $booking_details[ 'uid' ]           = $booking->uid;
        }
        
        $status = self::bkap_create_order( $booking_details, true );
       
        $backdated_event    = $status[ 'backdated_event' ];
        $validation_check   = $status[ 'validation_check' ];
        $grouped_product    = $status[ 'grouped_product' ];
        
        if ( 0 == $backdated_event && 0 == $validation_check && 0 == $grouped_product ) {

            // finally move the imported event details to item meta and delete the record from wp_options table
            $archive_events = 0; // 0 - archive (move from wp_options to item meta), 1 - delete from wp_options and don't save as item meta
            
                        
            if ( 0 == $archive_events ) {
                
                // save as item meta for future reference
                wc_add_order_item_meta( $status[ 'item_id' ], '_gcal_event_reference', $imported_event_details );
                // delete the data frm wp_options
                delete_option( $option_name );
                
                // Update post and its post meta.
                
                $update_parent_post_id = array(
                    'ID'            => $google_post_id,
                    'post_parent'   => $status[ 'order_id' ],
                );
                
                // Update the parent ID of post into the database
                wp_update_post( $update_parent_post_id );
                
                update_post_meta( $google_post_id, '_bkap_product_id', $status['parent_id'] );
                update_post_meta( $google_post_id, '_bkap_variation_id', $status['variation_id'] );
                
                $booking->update_status( "bkap-mapped" );
                
                
            } else if ( 1 == $archive_events ) {
                
                // delete the data from wp_options
                delete_option( $option_name );
            } 
        }
        
        if ( 1 == $backdated_event ) {
            $message = __( 'Back Dated Events cannot be imported. Please discard them.', 'woocommerce-booking' );
            $notice = '<div class="error"><p>' . sprintf( __( '%s', 'woocommerce-booking' ), $message ) . '</p></div>';
        }
        
        if ( 1 == $validation_check ) {
            
            $message = __( 'The product is not available for the given date for the desired quantity.', 'woocommerce-booking' );

            $notice = '<div class="error"><p>' . sprintf( __( '%s', 'woocommerce-booking' ), $message ) . '</p></div>';
        }
        
        if ( 1 == $grouped_product ) {
            $message = __( 'Imported Events cannot be mapped to grouped products.', 'woocommerce-booking' );
            $notice = '<div class="error"><p>' . sprintf( __( '%s', 'woocommerce-booking' ), $message ) . '</p></div>';
        }
        
        update_post_meta( $google_post_id, '_bkap_reason_of_fail', $message );
        
        echo $notice;
        
        if ( ! isset( $_POST[ 'automated' ] ) || ( isset( $_POST[ 'automated' ] ) && 0 == $_POST[ 'automated' ] ) ) {
            die();
        }

    }

    /**
     * This function will map the imported calendar events to the product and generate the booking and create WooCommerce Order.
     *
     * @since 3.6
     * @param array $booking_details Array of all booking details
     * @param boolean $gcal true if called from google event functionality and false if it is called from manual booking
     * @return array $status Array which contains validation result, new order id, item id, variation id, and parent id
     */
    
    static function bkap_create_order( $booking_details, $gcal = false ) {

        global $bkap_date_formats;
        
        $global_settings        = json_decode( get_option( 'woocommerce_booking_global_settings' ) );
        
        $date_format_to_display = $global_settings->booking_date_format;
        $time_format_to_display = $global_settings->booking_time_format;
        
        $order_created          = false;
        $product_id             = $booking_details[ 'product_id' ];
        
        // default the variables
        $booking_date_to_display    = '';
        $checkout_date_to_display   = '';
        $booking_from_time          = '';
        $booking_to_time            = '';        
        
        if ( !current_time( 'timestamp' ) ) {
            $tdif = 0;
        } else {
            $tdif = current_time( 'timestamp' ) - time();
        }
        
        if( $booking_details[ 'end' ] != "" && $booking_details[ 'start' ] != "" ) {
            
            // admin bookings passes time as per WP timezone
            $event_start                = $booking_details[ 'start' ];
            $event_end                  = $booking_details[ 'end' ];
            
            $booking_date_to_display    = date( $bkap_date_formats[ $date_format_to_display ], $event_start );
            $checkout_date_to_display   = date( $bkap_date_formats[ $date_format_to_display ], $event_end );
            
            $event_start_time           = $event_start;
            $event_end_time             = $event_end;
            
            if ( $gcal ) { // GCAL passes UTC
                $event_start_time = $event_start + $tdif;
                $event_end_time   = $event_end + $tdif;
            }
             
            if ( $time_format_to_display == '12' ) {
                $booking_from_time  = date( "h:i A", $event_start_time );
                $booking_to_time    = ( date( "h:i A", $event_end_time ) === '12:00 AM' ) ? '' : date( "h:i A", $event_end_time ); // open ended slot compatibility
            } else {
                $booking_from_time  = date( "H:i", $event_start_time );
                $booking_to_time    = ( date( "H:i", $event_end_time ) === '00:00' ) ? '' : date( "H:i", $event_end_time ); // open ended slot compatibility
            }
        } else if( $booking_details[ 'start' ] != "" && $booking_details[ 'end' ] == "" ) {
        
            $event_start                = $booking_details[ 'start' ];
            
            $booking_date_to_display    = date( $bkap_date_formats[ $date_format_to_display ], $event_start );
            
            $event_start_time           = $event_start;
            
            if ( $gcal ) {
                $event_start_time = $event_start + $tdif;
            }

            if ( $time_format_to_display == '12' ) {
                $booking_from_time = date( "h:i A", $event_start_time );
            } else {
                $booking_from_time = date( "H:i", $event_start_time );
            }
        }

        $resource_id = 0;
        if( $booking_details['bkap_resource_id'] && $booking_details['bkap_resource_id'] != "" ){
            $resource_id = $booking_details['bkap_resource_id'];
        }
        
        $sanity_check[ 'start' ]        = $event_start;
        $sanity_check[ 'end' ]          = ( isset( $event_end ) ) ? $event_end : '';
        $sanity_check[ 'product_id' ]   = $product_id;
        
        $sanity_return                  = self::bkap_sanity_check( $sanity_check, $gcal );
        
        $backdated_event                = ( isset( $sanity_return[ 'backdated_event' ] ) ) ? $sanity_return[ 'backdated_event' ] : 0;
        $validation_check               = ( isset( $sanity_return[ 'validation_check' ] ) ) ? $sanity_return[ 'validation_check' ] : 0;
        $grouped_product                = ( isset( $sanity_check[ 'grouped_event' ] ) ) ? $sanity_check[ 'grouped_event' ] : 0;
        
        $quantity_return                = self::bkap_quantity_setup( $sanity_check, $sanity_return );
        
        
        $quantity                       = $quantity_return[ 'quantity' ];
        $lockout_quantity               = $quantity_return[ 'lockout_qty' ];
        $parent_id                      = $quantity_return[ 'parent_id' ];
        $variation_id                   = $quantity_return[ 'variation_id' ];
        $variationsArray                = $quantity_return[ 'variationsArray' ];
        
        /* Validate the booking details. Check if the product is available in the desired quantity for the given date and time */
        $_product           = wc_get_product( $product_id );
                
        $hidden_date        = date( 'Y-m-d', $event_start );

        $booking_settings   = get_post_meta( $parent_id, 'woocommerce_booking_settings', true );
        
        if( 'variation' == $_product->get_type() ) {
            $product_type = 'variable';
        } else {
            $product_type = $_product->get_type();
        }
        
        $totals = 0;

        if ( isset( $booking_settings[ 'booking_enable_multiple_day' ] ) && 'on' == $booking_settings[ 'booking_enable_multiple_day' ] ) {
            $booking_date           = new DateTime( $hidden_date );
            $hidden_checkout_date   = date( 'Y-m-d', $event_end );
            $checkout_date          = new DateTime( $hidden_checkout_date );
        
            $difference = $checkout_date->diff( $booking_date );
        
            if ( $gcal ) {
                $price  =  bkap_common::bkap_get_price( $parent_id, $variation_id, $product_type );
                $totals = $price * $difference->days;
            } else {
                $totals = $booking_details[ 'price' ];
            }
            $variationsArray[ 'totals' ] = array(
                'subtotal'     => $totals,
                'total'        => $totals,
                'subtotal_tax' => 0,
                'tax'          => 0
            );
        } else if ( isset( $booking_settings[ 'booking_enable_time' ] ) && 'on' == $booking_settings[ 'booking_enable_time' ] ) {
        
            $from_hrs   = date( 'G:i', strtotime( $booking_from_time ) );
            $to_hrs     = date( 'G:i', strtotime( $booking_to_time ) );
        
            if ( 1 != $validation_check ) {
        
                $timeslot = "$from_hrs - $to_hrs";
                 
                $price = ( $gcal ) ? bkap_timeslot_price::get_price( $parent_id, $variation_id, $product_type, $hidden_date, $timeslot, 'product' ) : $booking_details[ 'price' ];
        
                $variationsArray[ 'totals' ] = array(
                    'subtotal'     => $price,
                    'total'        => $price,
                    'subtotal_tax' => 0,
                    'tax'          => 0
                );
            }

            if ( $gcal ) {
                $totals = $price;
            }

        } else {
            // Single Day
            if ( $gcal ) {
                $totals = bkap_common::bkap_get_price( $product_id, $variation_id, $product_type, $hidden_date );
            }
        }

        
        if ( 0 == $backdated_event && 0 == $validation_check && 0 == $grouped_product ) {
            $order_created = true;
            // create an order
            
            if ( $gcal ) {
                
            $args = array( 'status' => 'pending',
                'customer_note' => $booking_details[ 'summary' ],
                'created_via' => 'GCal' );
            
            } else {
                $args = array( 'status' => 'pending',
                    'created_via' => 'manual_booking',
                    'customer_id' => $booking_details[ 'customer_id' ]
                );
                
                // Create the billing address array to be added to the order
                if ( $booking_details[ 'customer_id' ] > 0 ) {
                    $user_meta = array_map( function( $a ){ return $a[0]; }, get_user_meta( $booking_details[ 'customer_id' ] ) );
                
                    $addr_args = array(
                        'first_name'    => ( isset( $user_meta[ 'billing_first_name' ] ) ) ? $user_meta[ 'billing_first_name' ] : '',
                        'last_name'     => ( isset( $user_meta[ 'billing_last_name' ] ) ) ? $user_meta[ 'billing_last_name' ] : '',
                        'email'         => ( isset( $user_meta[ 'billing_email' ] ) ) ? $user_meta[ 'billing_email' ] : '',
                        'phone'         => ( isset( $user_meta[ 'billing_phone' ] ) ) ? $user_meta[ 'billing_phone' ] : '',
                        'address_1'     => ( isset( $user_meta[ 'billing_address_1' ] ) ) ? $user_meta[ 'billing_address_1' ] : '',
                        'address_2'     => ( isset( $user_meta[ 'billing_address_2' ] ) ) ? $user_meta[ 'billing_address_2' ] : '',
                        'city'          => ( isset( $user_meta[ 'billing_city' ] ) ) ? $user_meta[ 'billing_city' ] : '',
                        'state'         => ( isset( $user_meta[ 'billing_state' ] ) ) ? $user_meta[ 'billing_state' ] : '',
                        'postcode'      => ( isset( $user_meta[ 'billing_postcode' ] ) ) ? $user_meta[ 'billing_postcode' ] : '',
                        'country'       => ( isset( $user_meta[ 'billing_country' ] ) ) ? $user_meta[ 'billing_country' ] : '',
                    );
                } else {
                    $addr_args = array(
                        'first_name' => 'Guest',
                    );
                }
                
            }
            
            $order = wc_create_order( $args );
            
            $order_id = $order->get_id();
            
            if ( $gcal ) {
                if ( isset( $booking_details[ 'summary' ] ) && $booking_details[ 'summary' ] != '' ) {
                    $order->add_order_note( $booking_details[ 'summary' ] );
                }
                if ( isset( $booking_details[ 'description' ] ) && $booking_details[ 'description' ] != '' ) {
                    $order->add_order_note( $booking_details[ 'description' ] );
                }
                $order->add_order_note( 'Reserved by GCal' );
            } else {
                $order->add_order_note( 'Manual Booking' );
                // Add the Billing Address
                $order->set_address( $addr_args, 'billing' );
            }
            // add the product to the order
            
            $item_id = $order->add_product( $_product, $quantity, $variationsArray );
            
            if ( $gcal ) {
                // insert records to ensure we're aware the item has been imported
                $event_items = get_option( 'bkap_event_item_ids' );
                if( $event_items == '' || $event_items == '{}' || $event_items == '[]' || $event_items == 'null' ) {
                    $event_items = array();
                }
                array_push( $event_items, $item_id );
                update_option( 'bkap_event_item_ids', $event_items );
            }
            
            // calculate order totals
            $order->calculate_totals();

            if ( isset( $parent_id ) && 0 != $parent_id ) {
                $meta_update_id = $parent_id;
            } else {
                $meta_update_id = $product_id;
            }
            
            // create the booking details array
            $booking[ 'date' ]          = $booking_date_to_display;
            $booking[ 'hidden_date' ]   = date( 'j-n-Y', $event_start );
            $booking[ 'price' ]         = ( ! $gcal ) ? $booking_details[ 'price' ] : $totals; // price is to be passed only if it's an admin booking
            $booking[ 'uid' ]           = isset( $booking_details['uid'] ) ? $booking_details['uid'] : "";
            $booking[ 'resource_id']    = $resource_id;
            
            $hidden_checkout_date       = '';
            
            if ( isset( $checkout_date_to_display ) && '' != $checkout_date_to_display ) {
                $hidden_checkout_date = date( 'j-n-Y', $event_end );
            }
            
            $booking_method = get_post_meta( $meta_update_id, '_bkap_booking_type', true );
            
            if ( 'multiple_days' === $booking_method ) {
                $booking[ 'date_checkout' ] = $checkout_date_to_display;
                $booking[ 'hidden_date_checkout' ] = $hidden_checkout_date;
            }
            if ( isset( $booking_from_time ) && '' != $booking_from_time && $booking_from_time != $booking_to_time ) {
                $time_slot = $booking_from_time;
                if ( isset( $booking_to_time ) && '' != $booking_to_time ) {
                    $time_slot .= ' - ' . $booking_to_time;
                }
                // check the booking method
                if ( 'date_time' === $booking_method ) {
                    $booking[ 'time_slot' ] = $time_slot;
                }
            }
            
            if ( isset( $parent_id ) && 0 != $parent_id ) {
                $meta_update_id = $parent_id;
            } else {
                $meta_update_id = $product_id;
            }
            bkap_common::bkap_update_order_item_meta( $item_id, $meta_update_id, $booking, true );
            
            // adjust lockout
            $product = wc_get_product( $meta_update_id );
            // for grouped products
            $parent_id = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $product->get_parent() : bkap_common::bkap_get_parent_id( $meta_update_id );
            
            $details = bkap_checkout::bkap_update_lockout( $order_id, $meta_update_id, $parent_id, $lockout_quantity, $booking );
            
            // update the global time slot lockout
            if ( isset( $booking[ 'time_slot' ] ) && '' != $booking[ 'time_slot' ] ) {
                bkap_checkout::bkap_update_global_lockout( $meta_update_id, $lockout_quantity, $details, $booking );
            }
            
            // Add the booking as a post
            $booking[ 'gcal_uid' ] = ( $gcal ) ? $booking_details[ 'uid' ] : false;
            bkap_checkout::bkap_create_booking_post( $item_id, $meta_update_id, $lockout_quantity, $booking, $variation_id );
            
            // update the order status to processing
            $order_obj = wc_get_order( $order_id ); // this needs to be done to ensure the booking details are displayed in Woo emails.
            $order_status   = apply_filters( 'bkap_manual_gcal_booking_order_status', 'processing' );
            $order_obj->update_status( $order_status );

            if ( !$gcal ) {

                $g_cal = new BKAP_Gcal();                

                $user = get_user_by( 'email', get_option( 'admin_email' ) );
                
                $admin_id = 0;
                
                if ( isset( $user->ID ) ) {
                    $admin_id = $user->ID;
                } else {
                    // get the list of administrators
                    $args = array( 'role' => 'administrator', 'fields' => array( 'ID' ) );
                    $users = get_users( $args );
                    if ( isset( $users ) && count( $users ) > 0 ) {
                        $admin_id = $users[ 0 ]->ID;
                    }
                }

                if( $g_cal->get_api_mode( $admin_id, $meta_update_id ) == "directly" ) {
                    

                    $booking_settings = get_post_meta( $meta_update_id, 'woocommerce_booking_settings', true );

                    // check the booking status, if pending confirmation, then do not insert event in the calendar
                    $booking_status = wc_get_order_item_meta( $item_id, '_wapbk_booking_status' );

                    if ( ( isset( $booking_status ) && 'pending-confirmation' != $booking_status ) || ( ! isset( $booking_status ) ) ) {
                        // ensure it's a future dated event
                        $is_date_set = false;

                        if ( isset( $booking[ 'hidden_date' ] ) ) {
                            $day = date( 'Y-m-d', current_time( 'timestamp' ) );
                            
                            if ( strtotime( $booking[ 'hidden_date' ] ) >= strtotime( $day ) ) {
                                $is_date_set = true;
                            } 
                        }


                        if( $is_date_set ) {

                            $event_details = array();

                            $event_details[ 'hidden_booking_date' ] = $booking[ 'hidden_date' ];

                            if ( isset( $booking[ 'hidden_date_checkout' ] ) && $booking[ 'hidden_date_checkout' ] != '' ) {
                                
                                if ( isset( $booking_settings[ 'booking_charge_per_day' ] ) && 'on' == $booking_settings[ 'booking_charge_per_day' ] ) {
                                    $event_details[ 'hidden_checkout_date' ] = date( 'j-n-Y', strtotime( '+1 day', strtotime( $booking[ 'hidden_date_checkout' ] ) ) );
                                } else {
                                    $event_details[ 'hidden_checkout_date' ] = $booking[ 'hidden_date_checkout' ];
                                }
                            }
                            
                            if ( isset( $booking[ 'time_slot' ] ) && $booking[ 'time_slot' ] != '' ) {
                                $event_details[ 'time_slot' ] = $booking[ 'time_slot' ];
                            }
                            
                            $event_details[ 'billing_email' ]       = ( isset( $addr_args['email'] ) ) ? $addr_args['email'] : '';                        
                            $event_details[ 'billing_first_name' ]  = ( isset( $addr_args['first_name'] ) ) ? $addr_args['first_name'] : '';
                            $event_details[ 'billing_last_name' ]   = ( isset( $addr_args['last_name'] ) ) ? $addr_args['last_name'] : '';                    
                            $event_details[ 'billing_address_1' ]   = ( isset( $addr_args['address_1'] ) ) ? $addr_args['address_1'] : '';                    
                            $event_details[ 'billing_address_2' ]   = ( isset( $addr_args['address_2'] ) ) ? $addr_args['address_2'] : '';                    
                            $event_details[ 'billing_city' ]        = ( isset( $addr_args['city'] ) ) ? $addr_args['city'] : '';                   
                            $event_details[ 'billing_phone' ]       = ( isset( $addr_args['phone'] ) ) ? $addr_args['phone'] : '';  
                            $event_details[ 'order_id' ]            = $order_id;
                            $event_details[ 'order_comments' ]      = '';
                            $event_details[ 'product_name' ]        = $_product->get_title();;
                            $event_details[ 'product_qty' ]         = 1;                        
                            $event_details[ 'product_total' ]       = $totals;
                            
                            if ( ( ! isset( $booking_settings[ 'product_sync_integration_mode' ] ) ) || ( isset( $booking_settings[ 'product_sync_integration_mode' ] ) && 'disabled' == $booking_settings[ 'product_sync_integration_mode' ] ) ) {
                                $meta_update_id = 0;
                            }

                            $g_cal->insert_event( $event_details, $item_id, $booking_details[ 'customer_id' ], $meta_update_id , false );
                        }
                    }
                }                
            }   
        }
        
        $status[ 'backdated_event' ]    = $backdated_event; 
        $status[ 'validation_check' ]   = $validation_check; 
        $status[ 'grouped_product' ]    = $grouped_product; 
        $status[ 'new_order' ]          = $order_created;
        $status[ 'order_id' ]           = ( $order_created ) ? $order_id : 0;
        $status[ 'item_id' ]            = ( $order_created ) ? $item_id : 0;
        $status[ 'parent_id' ]          = $parent_id;
        $status[ 'variation_id' ]       = $variation_id;
        
        
        return $status;
    }

    /**
     * This function will generate the booking and update the lockout for the product.
     *
     * @since 3.6
     * @param array $booking_details array of booking details
     * @param boolean $gcal true if called from google event functionality and false if it is called from manual booking
     * @return array $status Returns array of validation checks, order id, item id, 
     */
    
    static function bkap_create_booking( $booking_details, $gcal = false ) {
        
        global $bkap_date_formats;
        
        $global_settings = json_decode( get_option( 'woocommerce_booking_global_settings' ) );
        
        $date_format_to_display = $global_settings->booking_date_format;
        $time_format_to_display = $global_settings->booking_time_format;
        
        $item_added = false;
        $product_id = $booking_details[ 'product_id' ];
        
        // default the variables
        $booking_date_to_display = '';
        $checkout_date_to_display = '';
        $booking_from_time = '';
        $booking_to_time = '';
        
        if ( !current_time( 'timestamp' ) ) {
            $tdif = 0;
        } else {
            $tdif = current_time( 'timestamp' ) - time();
        }
        
        if( $booking_details[ 'end' ] != "" && $booking_details[ 'start' ] != "" ) {
        
            if ( $gcal ) { // GCAL passes UTC
                $event_start = $booking_details[ 'start ' ]+ $tdif;
                $event_end = $booking_details[ 'end' ] + $tdif;
            } else { // admin bookings passes time as per WP timezone
                $event_start = $booking_details[ 'start' ];
                $event_end = $booking_details[ 'end' ];
            }
        
            $booking_date_to_display = date( $bkap_date_formats[ $date_format_to_display ], $event_start );
            $checkout_date_to_display = date( $bkap_date_formats[ $date_format_to_display ], $event_end );
            
            if ( $time_format_to_display == '12' ) {
                $booking_from_time  = date( "h:i A", $event_start );
                $booking_to_time    = ( date( "h:i A", $event_end ) === '12:00 AM' ) ? '' : date( "h:i A", $event_end ); // open ended slot compatibility
            } else {
                $booking_from_time  = date( "H:i", $event_start );
                $booking_to_time    = ( date( "H:i", $event_end ) === '00:00' ) ? '' : date( "H:i", $event_end ); // open ended slot compatibility
            }
             
        } else if( $booking_details[ 'start' ] != "" && $booking_details[ 'end' ] == "" ) {
        
            $event_start = $booking_details[ 'start' ] + $tdif;
            $booking_date_to_display = date( $bkap_date_formats[ $date_format_to_display ], $event_start );
            
            if ( $time_format_to_display == '12' ) {
                $booking_from_time = date( "h:i A", $event_start );
            } else {
                $booking_from_time = date( "H:i", $event_start );
            }
             
        }
        
        $sanity_check[ 'start' ] = $event_start;
        $sanity_check[ 'end' ] = ( isset( $event_end ) ) ? $event_end : '';
        $sanity_check[ 'product_id' ] = $product_id;
        
        $sanity_return = self::bkap_sanity_check( $sanity_check, $gcal );
        
        $backdated_event    = ( isset( $sanity_return[ 'backdated_event' ] ) ) ? $sanity_return[ 'backdated_event' ] : 0;
        $validation_check   = ( isset( $sanity_return[ 'validation_check' ] ) ) ? $sanity_return[ 'validation_check' ] : 0;
        $grouped_product    = ( isset( $sanity_check[ 'grouped_event' ] ) ) ? $sanity_check[ 'grouped_event' ] : 0;
        
        $quantity_return = self::bkap_quantity_setup( $sanity_check, $sanity_return );
        
        $quantity = $quantity_return[ 'quantity' ];
        $lockout_quantity = $quantity_return[ 'lockout_qty' ];
        $parent_id = $quantity_return[ 'parent_id' ];
        $variation_id = $quantity_return[ 'variation_id' ];
        $variationsArray = $quantity_return[ 'variationsArray' ];
        
        if ( 0 == $backdated_event && 0 == $validation_check && 0 == $grouped_product ) {
            $order = new WC_Order( $booking_details[ 'order_id' ] );
            $item_added = true;
            
            $order_id = $booking_details[ 'order_id' ];
            $_product = wc_get_product( $product_id );
            $product_title = $_product->get_name();

            // set the price
            $totals = $booking_details[ 'price' ];
            $variationsArray[ 'totals' ] = array(
                'subtotal'     => $totals,
                'total'        => $totals,
                'subtotal_tax' => 0,
                'tax'          => 0
            );
            
            $order->add_order_note( "Added $product_title manually." );
        
            // add the product to the order
            $item_id = $order->add_product( $_product, $quantity, $variationsArray );
            
            // calculate order totals
            $order->calculate_totals();
            
            if ( isset( $parent_id ) && 0 != $parent_id ) {
                $meta_update_id = $parent_id;
            } else {
                $meta_update_id = $product_id;
            }
            
            // create the booking details array
            $booking[ 'date' ] = $booking_date_to_display;
            $booking[ 'hidden_date' ] = date( 'j-n-Y', $event_start );
            $booking[ 'price' ] = $booking_details[ 'price' ]; 
            $hidden_checkout_date = '';
            
            if ( isset( $checkout_date_to_display ) && '' != $checkout_date_to_display ) {
                $hidden_checkout_date = date( 'j-n-Y', $event_end );
            }
            
            $booking_method = get_post_meta( $meta_update_id, '_bkap_booking_type', true );
            
            if ( 'multiple_days' === $booking_method ) {
                $booking[ 'date_checkout' ] = $checkout_date_to_display;
                $booking[ 'hidden_date_checkout' ] = $hidden_checkout_date;
            }
            
            if ( isset( $booking_from_time ) && '' != $booking_from_time && $booking_from_time != $booking_to_time ) {
                $time_slot = $booking_from_time;
                if ( isset( $booking_to_time ) && '' != $booking_to_time ) {
                    $time_slot .= ' - ' . $booking_to_time;
                }
                if( 'date_time' === $booking_method ) {
                    $booking[ 'time_slot' ] = $time_slot;
                }
            }

            if( $booking_details['bkap_resource_id'] && $booking_details['bkap_resource_id'] != "" ){
                
                $booking[ 'resource_id']    = $booking_details['bkap_resource_id'];
            }
            
            bkap_common::bkap_update_order_item_meta( $item_id, $meta_update_id, $booking, true );
            
            // adjust lockout
            $product = wc_get_product( $meta_update_id );
            // for grouped products
            $parent_id = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $product->get_parent() : bkap_common::bkap_get_parent_id( $meta_update_id );
            
            $details = bkap_checkout::bkap_update_lockout( $order_id, $meta_update_id, $parent_id, $lockout_quantity, $booking );
            
            // update the global time slot lockout
            if ( isset( $booking[ 'time_slot' ] ) && '' != $booking[ 'time_slot' ] ) {
                bkap_checkout::bkap_update_global_lockout( $meta_update_id, $lockout_quantity, $details, $booking );
            }
            
            // Add the booking as a post
            $booking[ 'gcal_uid' ] = false;
            bkap_checkout::bkap_create_booking_post( $item_id, $meta_update_id, $lockout_quantity, $booking, $variation_id );
            
        }
        
        $status[ 'backdated_event' ] = $backdated_event;
        $status[ 'validation_check' ] = $validation_check;
        $status[ 'grouped_product' ] = $grouped_product;
        $status[ 'item_added' ] = $item_added;
        $status[ 'order_id' ] = $booking_details[ 'order_id' ];
        return $status;
    }

    /**
     * This function will validate if the give booking details is valid for creating the booking for the product or not.
     *
     * @since 3.6
     * @param array $booking_details Array of booking details
     * @param boolean $gcal true if called from google event functionality and false if it is called from manual booking
     * @return array $sanity_results Returns result of the validation
     */
    
    static function bkap_sanity_check( $booking_data, $gcal ) {
        
        global $bkap_date_formats;
        
        $event_start    = $booking_data[ 'start' ];
        $event_end      = $booking_data[ 'end' ];
        $product_id     = $booking_data[ 'product_id' ];
        
        // default  variables
        $backdated_event    = 0; // it's a future event
        $validation_check   = 0; // product is available for desired quantity
        $grouped_product    = 0; // for grouped product
        
        $global_settings    = json_decode( get_option( 'woocommerce_booking_global_settings' ) );
        
        $date_format_to_display = $global_settings->booking_date_format;
        $time_format_to_display = $global_settings->booking_time_format;
        
        if ( !current_time( 'timestamp' ) ) {
            $tdif = 0;
        } else {
            $tdif = current_time( 'timestamp' ) - time();
        }
        
        if( ! $gcal ) {
            $tdif = 0;
        }
        
        // lets compare with only date start to ensure current dated bookings can go through
        $current_time = current_time( 'timestamp' );
        $date_start = strtotime( date( 'Ymd', $current_time ) );
        
        if ( $event_start !== '' && $event_end !== '' ) {
            if( $event_end >= $date_start || $event_start >= $date_start ) {
            
                if ( $time_format_to_display == '12' ) {
                    $booking_from_time = date( "h:i A", $event_start + $tdif );
                    $booking_to_time = date( "h:i A", $event_end + $tdif );
                } else {
                    $booking_from_time = date( "H:i", $event_start + $tdif);
                    $booking_to_time = date( "H:i", $event_end + $tdif );
                }
            
                $booking_date_to_display    = date( $bkap_date_formats[ $date_format_to_display ], $event_start );
                $checkout_date_to_display   = date( $bkap_date_formats[ $date_format_to_display ], $event_end );
                
            } else {
                $backdated_event = 1;
            }
        } else {
            if( $event_start >= $date_start ) {
            
                if ( $time_format_to_display == '12' ) {
                    $booking_from_time = date( "h:i A", $event_start + $tdif );
                } else {
                    $booking_from_time = date( "H:i", $event_start + $tdif );
                }
            
                $booking_date_to_display = date( $bkap_date_formats[ $date_format_to_display ], $event_start );
            } else {
                $backdated_event = 1;
            }
            
        }
        
        /* Validate the booking details. Check if the product is available in the desired quantity for the given date and time */
        $_product = wc_get_product( $product_id );
        if ( 'grouped' == $_product->get_type() ) {
            $grouped_product = 1;
        }
        
        $variationsArray = array();
        
        // if the product ID has a parent post Id, then it means it's a variable product
        $variation_id       = 0;
        $lockout_quantity   = 1;
        
        if( $_product->get_type() == "variation" ){
            
            $check_variation = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $_product->variation_id : $_product->get_id();
        }
        
        if ( isset( $check_variation ) && 0 != $check_variation ) {
            
            $parent_id = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $_product->parent->id : $_product->get_parent_id();
            $variation_id = $product_id;
        
            $parent_product = wc_get_product( $parent_id );
            $variations_list = $parent_product->get_available_variations();
        
            foreach ( $variations_list as $variation ) {
                if ( $variation[ 'variation_id' ] == $product_id ) {
                    $variationsArray[ 'variation' ] = $variation[ 'attributes' ];
                }
            }
        
            // Product Attributes - Booking Settings
            $attribute_booking_data = get_post_meta( $parent_id, '_bkap_attribute_settings', true );
        
            if ( is_array( $attribute_booking_data ) && count( $attribute_booking_data ) > 0 ) {
                $lockout_quantity = 1;
                foreach ( $attribute_booking_data as $attr_name => $attr_settings ) {
                    $attr_name = 'attribute_' . $attr_name;
                    if ( isset( $attr_settings[ 'booking_lockout_as_value' ] ) && 'on' == $attr_settings[ 'booking_lockout_as_value' ] ) {
                        if ( array_key_exists( $attr_name, $variationsArray[ 'variation' ] ) ) {
                            $lockout_quantity += $variationsArray[ 'variation' ][ $attr_name ];
                        }
                    }
                }
            }
        } else {
            $parent_id = $product_id;
        }
        
        $hidden_date        = date( 'Y-m-d', $event_start );
        
        $booking_settings   = get_post_meta( $parent_id, 'woocommerce_booking_settings', true );

        // if the event is not backdated
        if ( $backdated_event != 1 ) {
            // if time is enabled for the product
            if ( isset( $booking_settings[ 'booking_enable_time' ] ) && 'on' == $booking_settings[ 'booking_enable_time' ] ) {
            
                $from_hrs   = date( 'G:i', strtotime( $booking_from_time ) );
                $to_hrs     = date( 'G:i', strtotime( $booking_to_time ) );
                
                if( $to_hrs == '0:00' ){
                    $to_hrs = "";
                }
            
                $availability = bkap_booking_process::bkap_get_time_availability( $parent_id, $hidden_date, $from_hrs, $to_hrs, 'YES' );

                if( $availability == 0 ) {

                    $from_hrss   = date( 'H:i', strtotime( $booking_from_time ) );
                    $to_hrss     = date( 'H:i', strtotime( $booking_to_time ) );

                    if( $to_hrss == '00:00' ){
                        $to_hrss = "";
                    }
                    
                    $availability = bkap_booking_process::bkap_get_time_availability( $parent_id, $hidden_date, $from_hrss, $to_hrss, 'YES' );
                }

                $unlimited_lang = trim ( __( 'Unlimited ', 'woocommerce-booking' ) );
                 
                if ( $availability > 0 || trim( $availability ) == $unlimited_lang ) {
                    if ( $availability > 0 ) {
                        $new_availability = $availability - $lockout_quantity;
                        if ( $new_availability < 0 ) {
                            $validation_check = 1; // product is unavailable for the desired quantity
                        }
                    }
                } else {
                    $validation_check = 1; // product is not available
                }
            
            } else {
            
                $hidden_checkout_date = '';
                if ( isset( $checkout_date_to_display ) && $checkout_date_to_display != '' ) {
                    $hidden_checkout_date = date( 'Y-m-d', $event_end );
                }
                $bookings_placed        = '';
                $attr_bookings_placed   = '';
                                    
                $variation_booked_dates_array = bkap_variations::bkap_get_booked_dates_for_variation( $parent_id, $variation_id );

                $bookings_placed = ( isset( $variation_booked_dates_array['wapbk_bookings_placed_'] ) && $variation_booked_dates_array['wapbk_bookings_placed_'] != '' ) ? $variation_booked_dates_array['wapbk_bookings_placed_'] : '';
                
                $availability = bkap_booking_process::bkap_get_date_availability( $parent_id, $variation_id, $hidden_date, $booking_date_to_display, $bookings_placed, $attr_bookings_placed, $hidden_checkout_date, false );

                $unlimited_lang = trim ( __( 'Unlimited ', 'woocommerce-booking' ) );

            
                if ( $availability > 0 || trim( $availability ) == $unlimited_lang ) {
                    if ( $availability > 0 ) {
                        $new_availability = $availability - $lockout_quantity;
                        if ( $new_availability < 0 ) {
                            $validation_check = 1; // product is unavailable for the desired quantity
                        }
                    }
                } else {
                    $validation_check = 1; // product is not available
                }
            }
        } else {
            $validation_check = 1;
        }
        $sanity_results = array( 'backdated_event'  => $backdated_event,
                                 'validation_check' => $validation_check,
                                 'grouped_event'    => $grouped_product
        );
        
        return $sanity_results;
    }

    /**
     * This function is to calculate the parent id and its data.
     *
     * @since 3.6
     * @param array $booking_details Array of Booking details
     * @param array $sanity_check Array of validation result
     * @return array $quantity_return Return array of parent id, quantity, lockout quantity, variation id and variation array
     */
    
    static function bkap_quantity_setup( $booking_data, $sanity_check ) {
        $quantity           = 1;
        $lockout_quantity   = 1; // this is the qty which will be used to update lockout. Item and lockout qty can be different in case of attribute vaues being used as lockout qty
        
        $product_id         = $booking_data[ 'product_id' ];
        $_product           = wc_get_product( $product_id );
        
        $variationsArray    = array();
        
        // if the product ID has a parent post Id, then it means it's a variable product
        $variation_id = 0;
        
        $parent_id = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $_product->parent->id : $_product->get_parent_id();
        if ( $parent_id > 0 ) {
            $variation_id = $product_id;
        
            $parent_product = wc_get_product( $parent_id );
            $variations_list = $parent_product->get_available_variations();
        
            foreach ( $variations_list as $variation ) {
                if ( $variation[ 'variation_id' ] == $product_id ) {
                    $variationsArray[ 'variation' ] = $variation[ 'attributes' ];
                }
            }
        
            // Product Attributes - Booking Settings
            $attribute_booking_data = get_post_meta( $parent_id, '_bkap_attribute_settings', true );
        
            if ( is_array( $attribute_booking_data ) && count( $attribute_booking_data ) > 0 ) {
                $lockout_quantity = 1;
                foreach ( $attribute_booking_data as $attr_name => $attr_settings ) {
                    $attr_name = 'attribute_' . $attr_name;
                    if ( isset( $attr_settings[ 'booking_lockout_as_value' ] ) && 'on' == $attr_settings[ 'booking_lockout_as_value' ] ) {
                        if ( array_key_exists( $attr_name, $variationsArray[ 'variation' ] ) ) {
                            $lockout_quantity += $variationsArray[ 'variation' ][ $attr_name ];
                        }
                    }
                }
            }
        } else {
            $parent_id = $product_id;
        }
        
        $quantity_return[ 'quantity' ]          = $quantity;
        $quantity_return[ 'lockout_qty' ]       = $lockout_quantity;
        $quantity_return[ 'parent_id' ]         = $parent_id;
        $quantity_return[ 'variation_id' ]      = $variation_id;
        $quantity_return[ 'variationsArray' ]   = $variationsArray;
        
        return $quantity_return;
    }
}
API documentation generated by ApiGen