public function vtprd_woo_validate_order()
 {
     //error_log( print_r(  'Function begin - vtprd_woo_validate_order', true ) );
     //v1.1.1 begin -
     // "do_no_actions" set/unset in function  vtprd_build_product_price_array
     if (!isset($_SESSION)) {
         session_start();
         header("Cache-Control: no-cache");
         header("Pragma: no-cache");
     }
     if (isset($_SESSION['do_no_actions']) && $_SESSION['do_no_actions']) {
         return;
     }
     //v1.1.1 end
     global $vtprd_rules_set, $vtprd_cart, $vtprd_setup_options, $vtprd_info, $woocommerce;
     vtprd_debug_options();
     //v1.0.5
     //Open Session Variable, get rules_set and cart if not there...
     $data_chain = $this->vtprd_get_data_chain();
     // switch from run-through at checkout time
     if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
         /* 
         if ( $vtmam_cart->error_messages_processed == 'yes' ) {  
           $woocommerce->add_error(  __('Purchase error found.', 'vtmam') );  //supplies an error msg and prevents payment from completing 
           return;
         }
         */
         if ($vtprd_cart->lifetime_limit_applies_to_cart == 'yes' && sizeof($vtprd_cart->error_messages) == 0) {
             //error msg > 0 = 2nd time through HERE, customer has blessed the reduction
             //reapply rules to catch lifetime rule logic using email and address info...
             $total_discount_1st_runthrough = $vtprd_cart->yousave_cart_total_amt;
             $vtprd_info['checkout_validation_in_process'] = 'yes';
             $vtprd_apply_rules = new VTPRD_Apply_Rules();
             $vtprd_info['checkout_validation_in_process'] = 'no';
             //v1.0.8.0
             //ERROR Message Path
             if (sizeof($vtprd_cart->error_messages) > 0 && $vtprd_cart->yousave_cart_total_amt < $total_discount_1st_runthrough) {
                 //2ND runthrough found additional lifetime limitations, need to alert customer
                 //insert error messages into checkout page
                 add_action('wp_head', array(&$this, 'vtprd_display_rule_error_msg_at_checkout'));
                 //JS to insert error msgs
                 /*  turn on the messages processed switch
                         otherwise errors are processed and displayed multiple times when the
                         wpsc_checkout_form_validation filter finds an error (causes a loop around, 3x error result...) 
                     */
                 $vtprd_cart->error_messages_processed = 'yes';
                 $woocommerce->add_error(__('Purchase error found.', 'vtprd'));
                 //supplies an error msg and prevents payment from completing
                 /*  *********************************************************************
                       Mark checkout as having ++failed edits++, and can't progress to Payment Gateway. 
                       This works only with the filter 'wpsc_checkout_form_validation', which is activated on submit of
                       "payment" button. 
                     *************************************************************************  */
                 $is_valid = false;
             }
             //v1.1.0.9 begin  need to clear this out
             if (isset($_SESSION['data_chain'])) {
                 $contents = $_SESSION['data_chain'];
                 unset($_SESSION['data_chain'], $contents);
             }
             ///v1.1.0.9 end
             /*  *************************************************
                  Load this info into session variables, to begin the 
                  DATA CHAIN - global to session back to global
                  global to session - in vtprd_process_discount
                  session to global - in vtprd_woo_validate_order
                  access global     - in vtprd_post_purchase_maybe_save_log_info   
                 *************************************************   */
             $contents_total = $woocommerce->cart->cart_contents_total;
             $applied_coupons = $woocommerce->cart->applied_coupons;
             $data_chain = array();
             $data_chain[] = $vtprd_rules_set;
             $data_chain[] = $vtprd_cart;
             $data_chain[] = vtprd_get_current_user_role();
             //v1.0.7.2
             $data_chain[] = $contents_total;
             $data_chain[] = $applied_coupons;
             $_SESSION['data_chain'] = serialize($data_chain);
         } else {
             //Get the screen data...
             vtprd_get_purchaser_info_from_screen();
         }
     }
     return;
 }
 public function vtprd_woo_validate_order()
 {
     //error_log( print_r(  'Function begin - vtprd_woo_validate_order', true ) );
     //v1.1.1 begin -
     // "do_no_actions" set/unset in function  vtprd_build_product_price_array
     if (!isset($_SESSION)) {
         session_start();
         header("Cache-Control: no-cache");
         header("Pragma: no-cache");
     }
     if (isset($_SESSION['do_no_actions']) && $_SESSION['do_no_actions']) {
         //error_log( print_r(  'Function begin - vtprd_woo_validate_order - DO NO ACTIONS return', true ) );
         //error_log( print_r(  '$vtprd_rules_set at APPLY-RULES END', true ) );
         //error_log( var_export($vtprd_rules_set, true ) );
         //error_log( print_r(  '$vtprd_cart at APPLY-RULES END', true ) );
         //error_log( var_export($vtprd_cart, true ) );
         return;
     }
     //v1.1.1 end
     global $vtprd_rules_set, $vtprd_cart, $vtprd_setup_options, $vtprd_info, $woocommerce;
     vtprd_debug_options();
     //v1.0.5
     //Open Session Variable, get rules_set and cart if not there...
     $data_chain = $this->vtprd_get_data_chain();
     // switch from run-through at checkout time
     if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
         //v1.1.1.3  begin
         if ($vtprd_cart->lifetime_limit_applies_to_cart == 'yes') {
             $do_return = false;
             switch (true) {
                 //If name already there, we've done the check last time, all good!
                 case $vtprd_cart->billto_name > ' ':
                     //all set, nothing else needed
                     $do_return = true;
                     break;
                     //If lifetime rules are checked by IP, all checks HAVE ALREADY BEEN DONE by this time. all good!
                 //If lifetime rules are checked by IP, all checks HAVE ALREADY BEEN DONE by this time. all good!
                 case $vtprd_setup_options['max_purch_rule_lifetime_limit_by_ip'] == 'yes':
                     if ($vtprd_cart->billto_name <= ' ') {
                         //then just get the screen data and return
                         vtprd_get_purchaser_info_from_screen();
                         //v1.1.0.9 begin  need to clear this out
                         if (isset($_SESSION['data_chain'])) {
                             $contents = $_SESSION['data_chain'];
                             unset($_SESSION['data_chain'], $contents);
                         }
                         ///v1.1.0.9 end
                         $contents_total = $woocommerce->cart->cart_contents_total;
                         $applied_coupons = $woocommerce->cart->applied_coupons;
                         $data_chain = array();
                         $data_chain[] = $vtprd_rules_set;
                         $data_chain[] = $vtprd_cart;
                         $data_chain[] = vtprd_get_current_user_role();
                         //v1.0.7.2
                         $data_chain[] = $contents_total;
                         $data_chain[] = $applied_coupons;
                         $_SESSION['data_chain'] = serialize($data_chain);
                     }
                     $do_return = true;
                     break;
                     //OTHERWISE - NOT testing for IP, and NAME is not there yet - do testing again.
             }
             if ($do_return) {
                 //error_log( print_r(  'Function begin - vtprd_woo_validate_order - AT NEW return', true ) );
                 //error_log( print_r(  '$vtprd_rules_set at APPLY-RULES END', true ) );
                 //error_log( var_export($vtprd_rules_set, true ) );
                 //error_log( print_r(  '$vtprd_cart at APPLY-RULES END', true ) );
                 //error_log( var_export($vtprd_cart, true ) );
                 return;
             }
         }
     }
     //v1.1.1.3  end
     if ($vtprd_cart->lifetime_limit_applies_to_cart == 'yes' && sizeof($vtprd_cart->error_messages) == 0) {
         //error msg > 0 = 2nd time through HERE, customer has blessed the reduction
         //reapply rules to catch lifetime rule logic using email and address info...
         //v1.1.1.3  begin   added this to THIS side as well- Get the screen data...
         if ($vtprd_cart->billto_name <= ' ') {
             vtprd_get_purchaser_info_from_screen();
         }
         //v1.1.1.3  end
         $total_discount_1st_runthrough = $vtprd_cart->yousave_cart_total_amt;
         $vtprd_info['checkout_validation_in_process'] = 'yes';
         //$vtprd_apply_rules = new VTPRD_Apply_Rules; //v1.1.1.3 removed, in favor of below!!!!!
         $this->vtprd_process_discount();
         $vtprd_info['checkout_validation_in_process'] = 'no';
         //v1.0.8.0
         //ERROR Message Path
         //v1.1.1.3 begin
         // if ( ( sizeof($vtprd_cart->error_messages) > 0 ) &&
         //      ($vtprd_cart->yousave_cart_total_amt < $total_discount_1st_runthrough) ) {   //2ND runthrough found additional lifetime limitations, need to alert customer
         if ($vtprd_cart->yousave_cart_total_amt < $total_discount_1st_runthrough) {
             //2ND runthrough found additional lifetime limitations, need to alert customer
             //$vtprd_cart->error_messages are not being loaded, so load here
             //REMOVE any line breaks, etc, which would cause a JS error !!
             //         $vtprd_cart->error_messages[] = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $vtprd_setup_options['lifetime_purchase_button_error_msg']);
             //v1.1.1.3 end
             //error_log( print_r(  '002', true ) );
             //insert error messages into checkout page
             //      add_action('wp_head', array(&$this, 'vtprd_display_rule_error_msg_at_checkout') );  //JS to insert error msgs
             /*  turn on the messages processed switch
                     otherwise errors are processed and displayed multiple times when the
                     wpsc_checkout_form_validation filter finds an error (causes a loop around, 3x error result...) 
                 */
             $vtprd_cart->error_messages_processed = 'yes';
             $message = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $vtprd_setup_options['lifetime_purchase_button_error_msg']);
             wc_add_notice($message, $notice_type = 'error');
             //supplies an error msg and prevents payment from completing
             /*  *********************************************************************
                   Mark checkout as having ++failed edits++, and can't progress to Payment Gateway. 
                   This works only with the filter 'wpsc_checkout_form_validation', which is activated on submit of
                   "payment" button. 
                 *************************************************************************  */
             $is_valid = false;
             //we don't pick up the new price unless we refresh the checkout!!!!!!!!!!!!
         }
         if ($total_discount_1st_runthrough != $vtprd_cart->yousave_cart_total_amt) {
             //v1.1.1.3
             //v1.1.0.9 begin  need to clear this out
             if (isset($_SESSION['data_chain'])) {
                 $contents = $_SESSION['data_chain'];
                 unset($_SESSION['data_chain'], $contents);
             }
             ///v1.1.0.9 end
             /*  *************************************************
                  Load this info into session variables, to begin the 
                  DATA CHAIN - global to session back to global
                  global to session - in vtprd_process_discount
                  session to global - in vtprd_woo_validate_order
                  access global     - in vtprd_post_purchase_maybe_save_log_info   
                 *************************************************   */
             $contents_total = $woocommerce->cart->cart_contents_total;
             $applied_coupons = $woocommerce->cart->applied_coupons;
             $data_chain = array();
             $data_chain[] = $vtprd_rules_set;
             $data_chain[] = $vtprd_cart;
             $data_chain[] = vtprd_get_current_user_role();
             //v1.0.7.2
             $data_chain[] = $contents_total;
             $data_chain[] = $applied_coupons;
             $_SESSION['data_chain'] = serialize($data_chain);
         }
         //v1.1.1.3
     } else {
         //Get the screen data...
         vtprd_get_purchaser_info_from_screen();
     }
     //error_log( print_r(  '$vtprd_rules_set at APPLY-RULES END', true ) );
     //error_log( var_export($vtprd_rules_set, true ) );
     //error_log( print_r(  '$vtprd_cart at APPLY-RULES END', true ) );
     //error_log( var_export($vtprd_cart, true ) );
     return;
 }
Example #3
0
function vtprd_load_vtprd_cart_for_processing()
{
    global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_setup_options, $vtprd_info;
    // from Woocommerce/templates/cart/mini-cart.php  and  Woocommerce/templates/checkout/review-order.php
    $woocommerce_cart_contents = $woocommerce->cart->get_cart();
    $calculator_product_in_cart = false;
    //v1.1.1
    $addons_product_in_cart = false;
    //v1.1.1
    if (sizeof($woocommerce_cart_contents) > 0) {
        //v1.0.8.0  save previous cart before creating new cart image, for lifetime confirmation processing only
        $vtprd_previous_cart = $vtprd_cart;
        //v1.0.8.0
        $vtprd_cart = new vtprd_Cart();
        $cart_has_catalog_discounts = 'no';
        //v1.1.1
        foreach ($woocommerce_cart_contents as $cart_item_key => $cart_item) {
            $_product = $cart_item['data'];
            if ($_product->exists() && $cart_item['quantity'] > 0) {
                $vtprd_cart_item = new vtprd_Cart_Item();
                //v1.1.1 begin
                //unique identifier in place of prod id, as some products DO NOT have an unique one
                $vtprd_cart_item->cart_item_key = $cart_item_key;
                //v1.1.1 end
                //the product id does not change in woo if variation purchased.
                //  Load expected variation id, if there, along with constructed product title.
                $varLabels = ' ';
                if ($cart_item['variation_id'] > ' ') {
                    // get parent title
                    $parent_post = get_post($cart_item['product_id']);
                    // get variation names to string onto parent title
                    foreach ($cart_item['variation'] as $key => $value) {
                        $varLabels .= $value . '&nbsp;';
                    }
                    $vtprd_cart_item->product_id = $cart_item['variation_id'];
                    $vtprd_cart_item->variation_array = $cart_item['variation'];
                    $vtprd_cart_item->product_name = $parent_post->post_title . '&nbsp;' . $varLabels;
                    $vtprd_cart_item->parent_product_name = $parent_post->post_title;
                    $vtprd_cart_item->variation_name_html = $woocommerce->cart->get_item_data($cart_item);
                    //v1.0.7.9
                    // added for v1.0.9.0 but unused, so commented ...
                    //  $variation_product = get_product( $vtprd_cart_item->product_id );  //v1.0.9.0
                } else {
                    $vtprd_cart_item->product_id = $cart_item['product_id'];
                    $vtprd_cart_item->product_name = $_product->get_title() . $woocommerce->cart->get_item_data($cart_item);
                }
                //v1.0.8.6  begin
                //for Variation Products with Attributes only, **there is NO product_ID difference** - the only difference is in the variation array.
                //   this info is used later to uniquely identify the product to which a discount should be added.
                $vtprd_cart_item->product_variation_key = array('product_id' => $cart_item['product_id'], 'variation_id' => $cart_item['variation_id'], 'variation' => $cart_item['variation']);
                //v1.0.8.6  end
                $product = get_product($vtprd_cart_item->product_id);
                //v1.0.7.4
                //v1.0.8.5 begin
                $varID = $cart_item['variation_id'];
                $prodID = $cart_item['product_id'];
                //v1.0.8.5 end
                $vtprd_cart_item->quantity = $cart_item['quantity'];
                $product_id = $vtprd_cart_item->product_id;
                //***always*** will be a session found
                //$session_found = vtprd_maybe_get_product_session_info($product_id);
                vtprd_maybe_get_product_session_info($product_id);
                //************************************************************************
                /*
                              v1.0.9.0 begin     this part of the routine reworked.
                               WITH V1.0.9.0 WE IGNORE THE UNIT PRICE IN THE CART,
                                as that could reflect both a CATALOG discount AND an **in-line** CART discount 
                                not a problem with coupone-based discount)
                                rather, we either go back to the ORIGINAL unit price for processing
                                OR we use the CATALOG discounted unit price.
                                (1) Original price, as taken from the DB
                                (2) Catalog pricing, taken from session variable
                                (3) Cart pricing, from running cart discount
                */
                //************************************************************************
                //By this time, there may  be a 'display' session variable for this product, if a discount was displayed in the catalog
                //  so 2nd - nth iteration picks up the discounted current price AND the original price for comparison
                if (isset($vtprd_info['product_session_info']['product_yousave_total_amt']) && $vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) {
                    //v1.0.9.0 changed to pick up FREE items...
                    //  $vtprd_cart_item->unit_price             =  vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart);     //v1.0.8.0
                    $vtprd_cart_item->unit_price = $vtprd_info['product_session_info']['product_discount_price'];
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    //v1.0.7.4  save for later comparison
                    $vtprd_cart_item->db_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    $vtprd_cart_item->db_unit_price_special = $vtprd_info['product_session_info']['product_special_price'];
                    $vtprd_cart_item->db_unit_price_list = $vtprd_info['product_session_info']['product_list_price'];
                    $vtprd_cart_item->product_list_price_catalog_correctly_taxed = $vtprd_info['product_session_info']['product_list_price_catalog_correctly_taxed'];
                    //v1.1.1
                    $cart_has_catalog_discounts = 'yes';
                    //v1.1.1
                } else {
                    $price = vtprd_get_current_active_price($product_id, $product);
                    //v1.1.1 added $product to call
                    $vtprd_previous_cart = '';
                    $price = vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart, $price);
                    $vtprd_cart_item->unit_price = $price;
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_cart_item->db_unit_price_list;
                    /*  now loaded in vtprd_get_current_active_price
                        $vtprd_cart_item->db_unit_price         = $price;
                        $vtprd_cart_item->db_unit_price_list    = $regular_price;
                        $vtprd_cart_item->db_unit_price_special = $sale_price;                  
                        */
                }
                //v1.0.9.0 end
                //v1.1.1 begin
                //*****************************************************
                // PLUGIN:: woocommerce-product-addons
                //*****************************************************
                /*
                With addons plugin, Catalog rules *do not affect the pricing of addons* - only the primary product.
                If there is a CART rule discount, both the Primary product and the addons will be discounted together.
                */
                if (class_exists('WC_Product_Addons') && isset($cart_item['addons'])) {
                    //if this is an ADDONS product
                    $vtprd_cart_item->other_plugins_info_array = $cart_item['addons'];
                    if ($vtprd_info['product_session_info']['product_has_addons']) {
                        $addons_total_price = 0;
                        foreach ($cart_item['addons'] as $key => $addon) {
                            $addons_total_price += $addon['price'];
                        }
                        $vtprd_cart_item->unit_price += $addons_total_price;
                        $vtprd_cart_item->save_orig_unit_price += $addons_total_price;
                        $vtprd_cart_item->db_unit_price += $addons_total_price;
                        $vtprd_cart_item->db_unit_price_special += $addons_total_price;
                        $vtprd_cart_item->db_unit_price_list += $addons_total_price;
                        $_SESSION['vtprd_addons_added_' . $product_id] = $addons_total_price;
                        //used in vtprd_maybe_get_price
                        $addons_product_in_cart = true;
                    }
                }
                //v1.1.1 end
                //v1.1.1 begin
                //*****************************************************
                // PLUGIN:: woocommerce-measurement-price-calculator
                //*****************************************************
                /* Overrides any other pricing from upstream pricing plugins, if there.
                   woocommerce-measurement-price-calculator provides the ability to price by weights, measures etc
                   sort of like fake variations.  However, it is all under the **original** product, with no actual
                   variation product ids.  So the data that is unique to the added product is in the
                   'pricing_item_meta_data' array, which is appended to the cart item.  It contains the 
                   current price of the item, undisturbed.  So it can always act as the original source of the pricing.
                   CATALOG rules are processed using the "woocommerce_get_price" hook, also using a calculator-specific
                   array to process successfully.                               
                   */
                if (class_exists('WC_Measurement_Price_Calculator') && $vtprd_info['product_session_info']['product_has_calculator'] && isset($cart_item['pricing_item_meta_data']) && isset($cart_item['pricing_item_meta_data']['_price'])) {
                    //if this is a calculator product
                    $vtprd_cart_item->unit_price = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->save_orig_unit_price = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->db_unit_price = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->db_unit_price_special = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->db_unit_price_list = $cart_item['pricing_item_meta_data']['_price'];
                    $_SESSION['vtprd_calculator_added_' . $product_id] = $cart_item['pricing_item_meta_data']['_price'];
                    //used in vtprd_maybe_get_price
                    $calculator_product_in_cart = true;
                }
                //v1.1.1 end
                //v1.1.1 begin
                //update old_price for later crossout use ==>> need ***cart_item_key***, can't use product_id for calculator/addons items!
                $_SESSION['vtprd_orig_cart_price_' . $vtprd_cart_item->cart_item_key] = $vtprd_cart_item->unit_price;
                //v1.1.1 end
                // db_unit_price_special CAN be zero if item is FREE!!
                //if ($vtprd_cart_item->unit_price < $vtprd_cart_item->db_unit_price_list )  {
                //v1.1.0.4 begin  added >= 0 and != null test
                if ($vtprd_cart_item->db_unit_price_special != null && $vtprd_cart_item->db_unit_price_special >= 0 && $vtprd_cart_item->db_unit_price_special < $vtprd_cart_item->db_unit_price_list) {
                    //v1.1.0.4 end
                    $vtprd_cart_item->product_is_on_special = 'yes';
                }
                /*
                if  ($vtprd_cart_item->db_unit_price_special == null) {
                $vtprd_cart_item->product_is_on_special = 'It"s null, dummy!!!';
                } else 
                if  ($vtprd_cart_item->db_unit_price_special <= 0 ) {
                $vtprd_cart_item->product_is_on_special = 'It"s not numeric, dummy!!!';
                } 
                */
                $vtprd_cart_item->total_price = $vtprd_cart_item->quantity * $vtprd_cart_item->unit_price;
                /*  *********************************
                 ***  JUST the cat *ids* please...
                 ************************************ */
                $vtprd_cart_item->prod_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['parent_plugin_taxonomy'], $args = array('fields' => 'ids'));
                $vtprd_cart_item->rule_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['rulecat_taxonomy'], $args = array('fields' => 'ids'));
                //initialize the arrays
                $vtprd_cart_item->prod_rule_include_only_list = array();
                $vtprd_cart_item->prod_rule_exclusion_list = array();
                /*  *********************************
                 ***  fill in include/exclude arrays if selected on the PRODUCT Screen (parent plugin)
                 ************************************ */
                $vtprd_includeOrExclude_meta = get_post_meta($cart_item['product_id'], $vtprd_info['product_meta_key_includeOrExclude'], true);
                //v1.0.7.8  use the parent ID at all times!
                if ($vtprd_includeOrExclude_meta) {
                    switch ($vtprd_includeOrExclude_meta['includeOrExclude_option']) {
                        case 'includeAll':
                            break;
                        case 'includeList':
                            $vtprd_cart_item->prod_rule_include_only_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeList':
                            $vtprd_cart_item->prod_rule_exclusion_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeAll':
                            $vtprd_cart_item->prod_rule_exclusion_list[0] = 'all';
                            //set the exclusion list to exclude all
                            break;
                    }
                }
                //v1.0.9.3 added if isset
                if (isset($cart_item['line_subtotal'])) {
                    $vtprd_cart_item->lifetime_line_subtotal = $cart_item['line_subtotal'];
                    //v1.0.8.0  for future lifetime processing only...
                }
                //add cart_item to cart array
                $vtprd_cart->cart_items[] = $vtprd_cart_item;
            }
        }
        //	endforeach;
    }
    //end  if (sizeof($woocommerce->cart->get_cart())>0)
    //v1.1.1 begin
    if ($calculator_product_in_cart) {
        $_SESSION['calculator_product_in_cart'] = 'yes';
    } else {
        $_SESSION['calculator_product_in_cart'] = 'no';
    }
    if ($addons_product_in_cart) {
        $_SESSION['addons_product_in_cart'] = 'yes';
    } else {
        $_SESSION['addons_product_in_cart'] = 'no';
    }
    //v1.1.1 end
    if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
        vtprd_get_purchaser_info_from_screen();
    }
    $vtprd_cart->purchaser_ip_address = $vtprd_info['purchaser_ip_address'];
    $vtprd_cart->cart_contents_count = $woocommerce->cart->cart_contents_count;
    //v1.0.9.3  used to check if cart contents have changed...
    $vtprd_info['cart_has_catalog_discounts'] = $cart_has_catalog_discounts;
    //v1.1.1
}
function vtprd_load_vtprd_cart_for_processing()
{
    global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_setup_options, $vtprd_info;
    // from Woocommerce/templates/cart/mini-cart.php  and  Woocommerce/templates/checkout/review-order.php
    $woocommerce_cart_contents = $woocommerce->cart->get_cart();
    //error_log( print_r(  'Woo Cart', true ) );
    //error_log( var_export($woocommerce_cart_contents, true ) );
    if (sizeof($woocommerce_cart_contents) > 0) {
        //error_log( print_r(  'Begin LOAD CART CONTENTS ', true ) );
        //v1.0.8.0  save previous cart before creating new cart image, for lifetime confirmation processing only
        $vtprd_previous_cart = $vtprd_cart;
        //v1.0.8.0
        $vtprd_cart = new vtprd_Cart();
        foreach ($woocommerce_cart_contents as $cart_item_key => $cart_item) {
            $_product = $cart_item['data'];
            if ($_product->exists() && $cart_item['quantity'] > 0) {
                $vtprd_cart_item = new vtprd_Cart_Item();
                //the product id does not change in woo if variation purchased.
                //  Load expected variation id, if there, along with constructed product title.
                $varLabels = ' ';
                if ($cart_item['variation_id'] > ' ') {
                    // get parent title
                    $parent_post = get_post($cart_item['product_id']);
                    // get variation names to string onto parent title
                    foreach ($cart_item['variation'] as $key => $value) {
                        $varLabels .= $value . '&nbsp;';
                    }
                    $vtprd_cart_item->product_id = $cart_item['variation_id'];
                    $vtprd_cart_item->variation_array = $cart_item['variation'];
                    $vtprd_cart_item->product_name = $parent_post->post_title . '&nbsp;' . $varLabels;
                    $vtprd_cart_item->parent_product_name = $parent_post->post_title;
                    $vtprd_cart_item->variation_name_html = $woocommerce->cart->get_item_data($cart_item);
                    //v1.0.7.9
                    // added for v1.0.9.0 but unused, so commented ...
                    //  $variation_product = get_product( $vtprd_cart_item->product_id );  //v1.0.9.0
                } else {
                    $vtprd_cart_item->product_id = $cart_item['product_id'];
                    $vtprd_cart_item->product_name = $_product->get_title() . $woocommerce->cart->get_item_data($cart_item);
                }
                //v1.0.8.6  begin
                //for Variation Products with Attributes only, **there is NO product_ID difference** - the only difference is in the variation array.
                //   this info is used later to uniquely identify the product to which a discount should be added.
                $vtprd_cart_item->product_variation_key = array('product_id' => $cart_item['product_id'], 'variation_id' => $cart_item['variation_id'], 'variation' => $cart_item['variation']);
                //v1.0.8.6  end
                $product = get_product($vtprd_cart_item->product_id);
                //v1.0.7.4
                //v1.0.8.5 begin
                $varID = $cart_item['variation_id'];
                $prodID = $cart_item['product_id'];
                //v1.0.8.5 end
                $vtprd_cart_item->quantity = $cart_item['quantity'];
                $product_id = $vtprd_cart_item->product_id;
                //***always*** will be a session found
                //$session_found = vtprd_maybe_get_product_session_info($product_id);
                vtprd_maybe_get_product_session_info($product_id);
                //************************************************************************
                /*
                              v1.0.9.0 begin     this part of the routine reworked.
                               WITH V1.0.9.0 WE IGNORE THE UNIT PRICE IN THE CART,
                                as that could reflect both a CATALOG discount AND an **in-line** CART discount 
                                not a problem with coupone-based discount)
                                rather, we either go back to the ORIGINAL unit price for processing
                                OR we use the CATALOG discounted unit price.
                                (1) Original price, as taken from the DB
                                (2) Catalog pricing, taken from session variable
                                (3) Cart pricing, from running cart discount
                */
                //************************************************************************
                //By this time, there may  be a 'display' session variable for this product, if a discount was displayed in the catalog
                //  so 2nd - nth iteration picks up the discounted current price AND the original price for comparison
                if (isset($vtprd_info['product_session_info']['product_yousave_total_amt']) && $vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) {
                    //v1.0.9.0 changed to pick up FREE items...
                    //  $vtprd_cart_item->unit_price             =  vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart);     //v1.0.8.0
                    $vtprd_cart_item->unit_price = $vtprd_info['product_session_info']['product_discount_price'];
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    //v1.0.7.4  save for later comparison
                    $vtprd_cart_item->db_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    $vtprd_cart_item->db_unit_price_special = $vtprd_info['product_session_info']['product_special_price'];
                    $vtprd_cart_item->db_unit_price_list = $vtprd_info['product_session_info']['product_list_price'];
                    //error_log( print_r(  'Pricing in Cart, from session_info, product = ' .$product_id. ' unit price= ' .$vtprd_cart_item->db_unit_price_list .' qty= ' .$vtprd_cart_item->quantity, true ) );
                } else {
                    //error_log( print_r(  'no session_info', true ) );
                    //echo '<pre> CALL to vtprd_get_current_active_price 001 - product= '.print_r($product_id), true).'</pre>' ;
                    //echo '<pre> before call 001 $product_id = '.print_r($product_id, true).'</pre>' ;
                    $price = vtprd_get_current_active_price($product_id);
                    //error_log( print_r(  'price 001= ' .$price, true ) );
                    $vtprd_previous_cart = '';
                    $price = vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart, $price);
                    //error_log( print_r(  'price 002= ' .$price, true ) );
                    $vtprd_cart_item->unit_price = $price;
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_cart_item->db_unit_price_list;
                    /*  now loaded in vtprd_get_current_active_price
                        $vtprd_cart_item->db_unit_price         = $price;
                        $vtprd_cart_item->db_unit_price_list    = $regular_price;
                        $vtprd_cart_item->db_unit_price_special = $sale_price;                  
                        */
                }
                //v1.0.9.0 end
                // db_unit_price_special CAN be zero if item is FREE!!
                //if ($vtprd_cart_item->unit_price < $vtprd_cart_item->db_unit_price_list )  {
                //v1.1.0.4 begin  added >= 0 and != null test
                if ($vtprd_cart_item->db_unit_price_special != null && $vtprd_cart_item->db_unit_price_special >= 0 && $vtprd_cart_item->db_unit_price_special < $vtprd_cart_item->db_unit_price_list) {
                    //v1.1.0.4 end
                    $vtprd_cart_item->product_is_on_special = 'yes';
                }
                /*
                if  ($vtprd_cart_item->db_unit_price_special == null) {
                $vtprd_cart_item->product_is_on_special = 'It"s null, dummy!!!';
                } else 
                if  ($vtprd_cart_item->db_unit_price_special <= 0 ) {
                $vtprd_cart_item->product_is_on_special = 'It"s not numeric, dummy!!!';
                } 
                */
                $vtprd_cart_item->total_price = $vtprd_cart_item->quantity * $vtprd_cart_item->unit_price;
                /*  *********************************
                 ***  JUST the cat *ids* please...
                 ************************************ */
                $vtprd_cart_item->prod_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['parent_plugin_taxonomy'], $args = array('fields' => 'ids'));
                $vtprd_cart_item->rule_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['rulecat_taxonomy'], $args = array('fields' => 'ids'));
                //initialize the arrays
                $vtprd_cart_item->prod_rule_include_only_list = array();
                $vtprd_cart_item->prod_rule_exclusion_list = array();
                /*  *********************************
                 ***  fill in include/exclude arrays if selected on the PRODUCT Screen (parent plugin)
                 ************************************ */
                $vtprd_includeOrExclude_meta = get_post_meta($cart_item['product_id'], $vtprd_info['product_meta_key_includeOrExclude'], true);
                //v1.0.7.8  use the parent ID at all times!
                if ($vtprd_includeOrExclude_meta) {
                    switch ($vtprd_includeOrExclude_meta['includeOrExclude_option']) {
                        case 'includeAll':
                            break;
                        case 'includeList':
                            $vtprd_cart_item->prod_rule_include_only_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeList':
                            $vtprd_cart_item->prod_rule_exclusion_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeAll':
                            $vtprd_cart_item->prod_rule_exclusion_list[0] = 'all';
                            //set the exclusion list to exclude all
                            break;
                    }
                }
                //v1.0.9.3 added if isset
                if (isset($cart_item['line_subtotal'])) {
                    $vtprd_cart_item->lifetime_line_subtotal = $cart_item['line_subtotal'];
                    //v1.0.8.0  for future lifetime processing only...
                }
                //add cart_item to cart array
                $vtprd_cart->cart_items[] = $vtprd_cart_item;
            }
        }
        //	endforeach;
    }
    //end  if (sizeof($woocommerce->cart->get_cart())>0)
    if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
        vtprd_get_purchaser_info_from_screen();
    }
    $vtprd_cart->purchaser_ip_address = $vtprd_info['purchaser_ip_address'];
    $vtprd_cart->cart_contents_count = $woocommerce->cart->cart_contents_count;
    //v1.0.9.3  used to check if cart contents have changed...
    //error_log( print_r(  'product_session_info', true ) );
    //$product_session_info = $vtprd_info['product_session_info'];
    //error_log( var_export($product_session_info, true ) );
    // error_log( print_r(  'END LOAD CART CONTENTS ', true ) );
    // error_log( var_export($vtprd_cart, true ) );
}