Ejemplo n.º 1
0
 public function vtprd_maybe_get_price($price, $product_info)
 {
     //error_log( print_r(  'Function begin - vtprd_maybe_get_price', 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 set to execute ONLY out of the get_current_price function in parent-functions,
     //   JUST to pick up product price from OTHER plugins ($currency conversion, etc)
     //  this will ALWAYS be true for that call
     if (isset($_SESSION['do_no_actions']) && $_SESSION['do_no_actions']) {
         return $price;
     }
     //****************************************************************
     //  IF vtprd_do_compatability_pricing set ON ITS OWN,
     //      Get_price is ON.  But it's only used to get the current price ONCE,
     //      and further Pricing Deals processing is NOT NEEDED
     //    DO NO further processing
     $do_get_price = apply_filters('vtprd_do_compatability_pricing', false);
     //if ONLY vtprd_do_compatability_pricing, Exit
     //  only these additional plugins (tested by class) may continue!
     if ($do_get_price && !class_exists('WC_Measurement_Price_Calculator') && !class_exists('WC_Product_Addons')) {
         return $price;
     }
     //****************************************************************
     //v1.1.1 end
     global $post, $vtprd_info, $vtprd_cart, $vtprd_cart_item, $vtprd_setup_options;
     vtprd_debug_options();
     //v1.0.5
     //********************
     //v1.0.8.9 begin
     //  rarely at checkout screen the "return $price" was happening!!
     //  added in the 'doing_ajax' logic
     //    needed because 'is_admin' doesn't work in ajax...
     //********************
     if (defined('DOING_AJAX') && DOING_AJAX) {
         $carry_on = true;
     } else {
         if (function_exists('get_current_screen') || is_admin()) {
             //v1.0.7.4
             //v1.1.1 remove other tests ==>> DO NOT RUN in ADMIN
             //  if ( (isset($post->post_type)) &&    //v1.0.7.4
             //       ($post->post_type == 'product'  ) ) {    //in admin, don't run this on the PRODUCT screen!!
             return $price;
         }
     }
     //v1.0.8.9 end
     //********************
     if (isset($product_info->variation_id) && $product_info->variation_id > ' ') {
         $product_id = $product_info->variation_id;
     } else {
         if ($product_info->id > ' ') {
             $product_id = $product_info->id;
         } else {
             $product_id = $product_info->product_id;
         }
     }
     if ($product_id <= ' ') {
         return $price;
     }
     $vtprd_hold_cart = $vtprd_cart;
     //v1.1.1
     vtprd_maybe_get_price_single_product($product_id, $price);
     //-------------
     //v1.1.1 BEGIN
     //*****************************************************
     // ONLY FOR PLUGIN:: woocommerce-measurement-price-calculator
     // ONLY FOR PLUGIN:: woocommerce-product-addons
     //*****************************************************
     //
     //if this isn't a calculator product, exit!  This array is **only** there for calculator products
     //if this isn't an addons product, exit!
     // weird thing happening with the calculator data even when deactivated, so checking plugin active on each as gateway.
     if (class_exists('WC_Measurement_Price_Calculator') && $vtprd_info['product_session_info']['product_has_calculator'] || class_exists('WC_Product_Addons') && $vtprd_info['product_session_info']['product_has_addons']) {
         $carry_on = true;
     } else {
         return $price;
     }
     if ($vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) {
         //v1.0.7.2  replaced 'product_discount_price' with 'product_yousave_total_amt' to pick up a FREE discount
         //v1.1.1 begin
         $discount_price = $vtprd_info['product_session_info']['product_discount_price'];
     } else {
         $discount_price = false;
     }
     //*****************************************************
     // PLUGIN:: woocommerce-product-addons
     //*****************************************************
     // if product has addons AND
     // if incoming price is greater than list, ADDONS have been added to the
     //    Price and **WE SHOULDN'T TOUCH IT**!!!
     //    Addons have their own variation ID, so we can uniquely identify it out of the box!
     if (class_exists('WC_Product_Addons') && $vtprd_info['product_session_info']['product_has_addons']) {
         //CURRENTLY INACTIVE (for now Bolt-ons only allow Coupon Discounting) ==>> discountUnitPrice path
         if ($vtprd_setup_options['discount_taken_where'] == 'discountUnitPrice') {
             if (isset($_SESSION['vtprd_addons_added_' . $product_id]) && $_SESSION['vtprd_addons_added_' . $product_id] > 0) {
                 //addons have increased the list value of the product!
                 switch (true) {
                     case $price > $vtprd_info['product_session_info']['product_list_price']:
                         return $price;
                         break;
                     case $discount_price && $discount_price < $price && $price == $vtprd_info['product_session_info']['product_list_price']:
                         return $discount_price;
                         break;
                     default:
                         return $price;
                         break;
                 }
             } else {
                 if ($discount_price && $discount_price < $price) {
                     return $discount_price;
                 } else {
                     return $price;
                 }
             }
         } else {
             if ($price == $vtprd_info['product_session_info']['product_list_price']) {
                 if ($discount_price) {
                     return $discount_price;
                 } else {
                     return $price;
                 }
             } else {
                 return $price;
             }
         }
     }
     //v1.1.1 end
     //-------------
     //v1.1.1 BEGIN
     //*****************************************************
     // PLUGIN:: woocommerce-measurement-price-calculator
     //*****************************************************
     // the discount price may already be correct from previous calls, in this odd situation - so don't do anything if there is no actual discount.
     if ($vtprd_info['product_session_info']['product_has_calculator']) {
         if ($discount_price && $discount_price < $price) {
             $price = $discount_price;
         }
     } else {
         //all OTHER pricing that comes through here
         if ($discount_price) {
             $price = $discount_price;
         }
     }
     return $price;
 }
 public function vtprd_maybe_get_price($price, $product_info)
 {
     global $post, $vtprd_info;
     vtprd_debug_options();
     //v1.0.5
     //echo '<br>GET PRICE BEGIN<br>';
     //          session_start();    //mwntest
     //echo 'SESSION data <pre>'.print_r($_SESSION, true).'</pre>' ;
     // IF THIS IS USED, THE SESSION ROW MUST ALWAYS BE CREATED!!!
     /*   
         //this can be activated in admin.  DISALLOW! BUT BUSTS MAIN FUNCTION...
         if (is_admin()){
           return $price; 
         }
     */
     //********************
     //v1.0.8.9 begin
     //  rarely at checkout screen the "return $price" was happening!!
     //  added in the 'doing_ajax' logic
     //    needed because 'is_admin' doesn't work in ajax...
     //********************
     if (defined('DOING_AJAX') && DOING_AJAX) {
         $do_nothing;
     } else {
         if (function_exists('get_current_screen') || is_admin()) {
             //v1.0.7.4
             if (isset($post->post_type) && $post->post_type == 'product') {
                 //in admin, don't run this on the PRODUCT screen!!
                 return $price;
             }
         }
     }
     //v1.0.8.9 end
     //********************
     if ($product_info->variation_id > ' ') {
         $product_id = $product_info->variation_id;
     } else {
         if ($product_info->id > ' ') {
             $product_id = $product_info->id;
         } else {
             $product_id = $product_info->product_id;
         }
     }
     if ($product_id <= ' ') {
         //error_log( print_r(  '022 $price_html= ' .$price, true ) );
         return $price;
     }
     //error_log( print_r(  'FROM vtprd_maybe_get_price', true ) );
     //vtprd_maybe_get_discount_catalog_session_price($product_id);
     vtprd_maybe_get_price_single_product($product_id, $price);
     if ($vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) {
         //v1.0.7.2  replaced 'product_discount_price' with 'product_yousave_total_amt' to pick up a FREE discount
         $price = $vtprd_info['product_session_info']['product_discount_price'];
         //v1.0.7.4 ==>> this remains unchanged!!
         // $price = $this->vtprd_show_shop_price(); //v1.0.7.4
     }
     //error_log( print_r(  '023 $price_html= ' .$price, true ) );
     return $price;
 }