public function check_install()
 {
     if (!defined('IFRAME_REQUEST') && get_option('wc_dynamic_pricing_db_version') !== WC_Dynamic_Pricing::instance()->db_version) {
         $this->do_update();
         update_option('wc_dynamic_pricing_db_version', WC_Dynamic_Pricing::instance()->db_version);
     }
 }
function woocommerce_gravityforms_get_updated_price()
{
    global $woocommerce;
    header('Cache-Control: no-cache, must-revalidate');
    header('Content-type: application/json');
    $variation_id = isset($_POST['variation_id']) ? $_POST['variation_id'] : '';
    $product_id = isset($_POST['product_id']) ? $_POST['product_id'] : 0;
    $gform_total = isset($_POST['gform_total']) ? $_POST['gform_total'] : 0;
    $product_data = null;
    if (function_exists('get_product')) {
        $product_data = get_product($variation_id > 0 ? $variation_id : $product_id);
    } else {
        if ($variation_id > 0) {
            $product_data = new WC_Product_Variation($variation_id);
        } else {
            $product_data = new WC_Product($product_id);
        }
    }
    $discount_price = false;
    $gforms_discount_price = false;
    $base_price = $product_data->get_price();
    if (class_exists('WC_Dynamic_Pricing')) {
        $working_price = $base_price;
        $dynamic_pricing = WC_Dynamic_Pricing::instance();
        foreach ($dynamic_pricing->modules as $module) {
            if ($module->module_type == 'simple') {
                //Make sure we are using the price that was just discounted.
                $working_price = $discount_price ? $discount_price : $base_price;
                $working_price = $module->get_product_working_price($working_price, $product_data);
                if (floatval($working_price)) {
                    $discount_price = $module->get_discounted_price_for_shop($product_data, $working_price);
                }
            }
        }
        $gforms_base_price = $base_price + $gform_total;
        $gforms_working_price = $base_price + $gform_total;
        foreach ($dynamic_pricing->modules as $module) {
            if ($module->module_type == 'simple') {
                //Make sure we are using the price that was just discounted.
                $gforms_working_price = $gforms_discount_price ? $gforms_discount_price : $gforms_base_price;
                $gforms_working_price = $module->get_product_working_price($gforms_working_price, $product_data);
                if (floatval($gforms_working_price)) {
                    $gforms_discount_price = $module->get_discounted_price_for_shop($product_data, $gforms_working_price);
                }
            }
        }
    }
    $price = $discount_price ? $discount_price : $base_price;
    $gform_final_total = $gforms_discount_price ? $gforms_discount_price : $price + $gform_total;
    $result = array('formattedBasePrice' => apply_filters('woocommerce_gform_base_price', woocommerce_price($price), $product_data), 'formattedTotalPrice' => apply_filters('woocommerce_gform_total_price', woocommerce_price($gform_final_total), $product_data), 'formattedVariationTotal' => apply_filters('woocommerce_gform_variation_total_price', woocommerce_price($gform_total), $product_data));
    echo json_encode($result);
    die;
}
 private function print_price_fields($product_id = 0, $form_prefix = "")
 {
     if (!$product_id) {
         global $product;
         if ($product) {
             $product_id = $product->id;
         }
     } else {
         $product = wc_get_product($product_id);
     }
     if (!$product_id || empty($product)) {
         if (!empty($this->current_product_id_to_be_displayed)) {
             $product_id = $this->current_product_id_to_be_displayed;
             $product = wc_get_product($product_id);
         } else {
             $this->tm_epo_totals_batch($form_prefix);
             return;
         }
     }
     if (!$product_id || empty($product)) {
         return;
     }
     $cpf_price_array = $this->get_product_tm_epos($product_id);
     if (!$cpf_price_array) {
         return;
     }
     if ($cpf_price_array && $this->tm_epo_enable_final_total_box_all == "no") {
         $global_price_array = $cpf_price_array['global'];
         $local_price_array = $cpf_price_array['local'];
         if (empty($global_price_array) && empty($local_price_array)) {
             return;
         }
     }
     if (!$cpf_price_array && $this->tm_epo_enable_final_total_box_all == "no") {
         return;
     }
     if ($form_prefix) {
         $form_prefix = "_" . $form_prefix;
     }
     // WooCommerce Dynamic Pricing & Discounts
     if (class_exists('RP_WCDPD') && !empty($GLOBALS['RP_WCDPD'])) {
         $price = $this->get_RP_WCDPD($product);
         if ($price) {
             $price['product'] = array();
             if ($price['is_multiprice']) {
                 foreach ($price['rules'] as $variation_id => $variation_rule) {
                     foreach ($variation_rule as $rulekey => $pricerule) {
                         $price['product'][$variation_id][] = array("min" => $pricerule["min"], "max" => $pricerule["max"], "value" => $pricerule["type"] != "percentage" ? apply_filters('woocommerce_tm_epo_price', $pricerule["value"], "", false) : $pricerule["value"], "type" => $pricerule["type"]);
                     }
                 }
             } else {
                 foreach ($price['rules'] as $rulekey => $pricerule) {
                     $price['product'][0][] = array("min" => $pricerule["min"], "max" => $pricerule["max"], "value" => $pricerule["type"] != "percentage" ? apply_filters('woocommerce_tm_epo_price', $pricerule["value"], "", false) : $pricerule["value"], "type" => $pricerule["type"]);
                 }
             }
         } else {
             $price = array();
             $price['product'] = array();
         }
         $price['price'] = apply_filters('woocommerce_tm_epo_price', $product->get_price(), "", false);
     } else {
         if (class_exists('WC_Dynamic_Pricing')) {
             $id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $dp = WC_Dynamic_Pricing::instance();
             if ($dp && is_object($dp) && property_exists($dp, "discounted_products") && isset($dp->discounted_products[$id])) {
                 $_price = $dp->discounted_products[$id];
             } else {
                 $_price = $product->get_price();
             }
         } else {
             $_price = apply_filters('woocommerce_tm_epo_price_compatibility', $product->get_price(), $product);
         }
         $price = array();
         $price['product'] = array();
         $price['price'] = apply_filters('woocommerce_tm_epo_price', $_price, "", false);
     }
     $variations = array();
     $variations_subscription_period = array();
     $variations_subscription_sign_up_fee = array();
     foreach ($product->get_children() as $child_id) {
         $variation = $product->get_child($child_id);
         if (!$variation->exists()) {
             continue;
         }
         if (class_exists('WC_Subscriptions_Product')) {
             $variations_subscription_period[$child_id] = WC_Subscriptions_Product::get_price_string($variation, array('subscription_price' => false, 'sign_up_fee' => false, 'trial_length' => false));
             $variations_subscription_sign_up_fee[$child_id] = $variation->subscription_sign_up_fee;
         } else {
             $variations_subscription_period[$child_id] = '';
             $variations_subscription_sign_up_fee[$child_id] = '';
         }
         $variations[$child_id] = apply_filters('woocommerce_tm_epo_price_compatibility', apply_filters('woocommerce_tm_epo_price', $variation->get_price(), "", false), $variation, $child_id);
     }
     $is_subscription = false;
     $subscription_period = '';
     $subscription_sign_up_fee = 0;
     if (class_exists('WC_Subscriptions_Product')) {
         if (WC_Subscriptions_Product::is_subscription($product)) {
             $is_subscription = true;
             $subscription_period = WC_Subscriptions_Product::get_price_string($product, array('subscription_price' => false, 'sign_up_fee' => false, 'trial_length' => false));
             $subscription_sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product);
         }
     }
     global $woocommerce;
     $cart = $woocommerce->cart;
     $_tax = new WC_Tax();
     $taxrates = $_tax->get_rates($product->get_tax_class());
     unset($_tax);
     $tax_rate = 0;
     foreach ($taxrates as $key => $value) {
         $tax_rate = $tax_rate + floatval($value['rate']);
     }
     $taxable = $product->is_taxable();
     $tax_display_mode = get_option('woocommerce_tax_display_shop');
     $tax_string = "";
     if ($taxable && $this->tm_epo_global_tax_string_suffix == "yes") {
         if ($tax_display_mode == 'excl') {
             //if ( $cart->tax_total > 0 && $cart->prices_include_tax ) {
             $tax_string = ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
             //}
         } else {
             //if ( $cart->tax_total > 0 && !$cart->prices_include_tax ) {
             $tax_string = ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>';
             //}
         }
     }
     $force_quantity = 0;
     if ($this->cart_edit_key) {
         $cart_item_key = $this->cart_edit_key;
         $cart_item = WC()->cart->get_cart_item($cart_item_key);
         if (isset($cart_item["quantity"])) {
             $force_quantity = $cart_item["quantity"];
         }
     }
     if (!$this->is_bto) {
         if (empty($this->epo_internal_counter) || !isset($this->epo_internal_counter_check["tc" . $this->epo_internal_counter])) {
             // First time displaying totals and fields haven't been displayed
             $this->epo_internal_counter++;
             $this->epo_internal_counter_check["tc" . $this->epo_internal_counter] = $this->epo_internal_counter;
         } else {
             // Fields have already been displayed
             unset($this->epo_internal_counter_check["tc" . $this->epo_internal_counter]);
             $this->current_product_id_to_be_displayed = 0;
         }
         $_epo_internal_counter = $this->epo_internal_counter;
     } else {
         $_epo_internal_counter = 0;
     }
     wc_get_template('tm-totals.php', array('theme_name' => $this->get_theme('Name'), 'variations' => esc_html(json_encode((array) $variations)), 'variations_subscription_period' => esc_html(json_encode((array) $variations_subscription_period)), 'variations_subscription_sign_up_fee' => esc_html(json_encode((array) $variations_subscription_sign_up_fee)), 'subscription_period' => $subscription_period, 'subscription_sign_up_fee' => $subscription_sign_up_fee, 'is_subscription' => $is_subscription, 'is_sold_individually' => $product->is_sold_individually(), 'hidden' => $this->tm_meta_cpf['override_final_total_box'] ? $this->tm_epo_final_total_box == 'hide' ? ' hidden' : '' : ($this->tm_meta_cpf['override_final_total_box'] == 'hide' ? ' hidden' : ''), 'form_prefix' => $form_prefix, 'type' => esc_html($product->product_type), 'price' => esc_html(is_object($product) ? apply_filters('woocommerce_tm_final_price', $price['price'], $product) : ''), 'taxable' => $taxable, 'tax_display_mode' => $tax_display_mode, 'prices_include_tax' => $cart->prices_include_tax, 'tax_rate' => $tax_rate, 'tax_string' => $tax_string, 'product_price_rules' => esc_html(json_encode((array) $price['product'])), 'fields_price_rules' => $this->tm_epo_dpd_enable == "no" ? 0 : 1, 'tm_epo_dpd_suffix' => $this->tm_epo_dpd_suffix, 'tm_epo_dpd_prefix' => $this->tm_epo_dpd_prefix, 'force_quantity' => $force_quantity, 'product_id' => $product_id, 'epo_internal_counter' => $_epo_internal_counter), $this->_namespace, $this->template_path);
 }
 public static function init()
 {
     if (self::$instance == null) {
         self::$instance = new WC_Dynamic_Pricing();
     }
 }