public function get_RP_WCDPD($product, $field_price = null, $cart_item_key = null)
 {
     $price = null;
     if (class_exists('RP_WCDPD') && class_exists('RP_WCDPD_Pricing') && !empty($GLOBALS['RP_WCDPD'])) {
         $tm_RP_WCDPD = $GLOBALS['RP_WCDPD'];
         $selected_rule = null;
         if ($field_price !== null && $cart_item_key !== null) {
             return $this->get_RP_WCDPD_single($field_price, $cart_item_key, $tm_RP_WCDPD->pricing);
         }
         $dpd_version_compare = version_compare(RP_WCDPD_VERSION, '1.0.13', '<');
         // Iterate over pricing rules and use the first one that has this product in conditions (or does not have if condition "not in list")
         if (isset($tm_RP_WCDPD->opt['pricing']['sets']) && count($tm_RP_WCDPD->opt['pricing']['sets'])) {
             foreach ($tm_RP_WCDPD->opt['pricing']['sets'] as $rule_key => $rule) {
                 if ($rule['method'] == 'quantity' && ($validated_rule = RP_WCDPD_Pricing::validate_rule($rule))) {
                     if ($dpd_version_compare) {
                         if ($validated_rule['selection_method'] == 'all' && $tm_RP_WCDPD->user_matches_rule($validated_rule['user_method'], $validated_rule['roles'])) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'categories_include' && count(array_intersect($tm_RP_WCDPD->get_product_categories($product->id), $validated_rule['categories'])) > 0 && $tm_RP_WCDPD->user_matches_rule($validated_rule['user_method'], $validated_rule['roles'])) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'categories_exclude' && count(array_intersect($tm_RP_WCDPD->get_product_categories($product->id), $validated_rule['categories'])) == 0 && $tm_RP_WCDPD->user_matches_rule($validated_rule['user_method'], $validated_rule['roles'])) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'products_include' && in_array($product->id, $validated_rule['products']) && $tm_RP_WCDPD->user_matches_rule($validated_rule['user_method'], $validated_rule['roles'])) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'products_exclude' && !in_array($product->id, $validated_rule['products']) && $tm_RP_WCDPD->user_matches_rule($validated_rule['user_method'], $validated_rule['roles'])) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                     } else {
                         if ($validated_rule['selection_method'] == 'all' && $tm_RP_WCDPD->user_matches_rule($validated_rule)) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'categories_include' && count(array_intersect($tm_RP_WCDPD->get_product_categories($product->id), $validated_rule['categories'])) > 0 && $tm_RP_WCDPD->user_matches_rule($validated_rule)) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'categories_exclude' && count(array_intersect($tm_RP_WCDPD->get_product_categories($product->id), $validated_rule['categories'])) == 0 && $tm_RP_WCDPD->user_matches_rule($validated_rule)) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'products_include' && in_array($product->id, $validated_rule['products']) && $tm_RP_WCDPD->user_matches_rule($validated_rule)) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                         if ($validated_rule['selection_method'] == 'products_exclude' && !in_array($product->id, $validated_rule['products']) && $tm_RP_WCDPD->user_matches_rule($validated_rule)) {
                             $selected_rule = $validated_rule;
                             break;
                         }
                     }
                 }
             }
         }
         if (is_array($selected_rule)) {
             // Quantity
             if ($selected_rule['method'] == 'quantity' && isset($selected_rule['pricing']) && in_array($selected_rule['quantities_based_on'], array('exclusive_product', 'exclusive_variation', 'exclusive_configuration'))) {
                 if ($product->product_type == 'variable' || $product->product_type == 'variable-subscription') {
                     $product_variations = $product->get_available_variations();
                 }
                 // For variable products only - check if prices differ for different variations
                 $multiprice_variable_product = false;
                 if (($product->product_type == 'variable' || $product->product_type == 'variable') && !empty($product_variations)) {
                     $last_product_variation = array_slice($product_variations, -1);
                     $last_product_variation_object = new WC_Product_Variable($last_product_variation[0]['variation_id']);
                     $last_product_variation_price = $last_product_variation_object->get_price();
                     foreach ($product_variations as $variation) {
                         $variation_object = new WC_Product_Variable($variation['variation_id']);
                         if ($variation_object->get_price() != $last_product_variation_price) {
                             $multiprice_variable_product = true;
                         }
                     }
                 }
                 if ($multiprice_variable_product) {
                     $variation_table_data = array();
                     foreach ($product_variations as $variation) {
                         $variation_product = new WC_Product_Variation($variation['variation_id']);
                         $variation_table_data[$variation['variation_id']] = $tm_RP_WCDPD->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
                     }
                     $price = array();
                     $price['is_multiprice'] = true;
                     $price['rules'] = $variation_table_data;
                 } else {
                     if ($product->product_type == 'variable' && !empty($product_variations)) {
                         $variation_product = new WC_Product_Variation($last_product_variation[0]['variation_id']);
                         $table_data = $tm_RP_WCDPD->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
                     } else {
                         $table_data = $tm_RP_WCDPD->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $product->get_price());
                     }
                     $price = array();
                     $price['is_multiprice'] = false;
                     $price['rules'] = $table_data;
                 }
             }
         }
     }
     if ($field_price !== null) {
         $price = $field_price;
     }
     return $price;
 }
 /**
  * Calculate prices to display for pricing tables
  * 
  * @access public
  * @param array $table_data
  * @param float $original_price
  * @return void
  */
 public function pricing_table_calculate_adjusted_prices($table_data, $original_price)
 {
     foreach ($table_data as $row_key => $row) {
         $current_adjusted_price = $original_price - RP_WCDPD_Pricing::apply_adjustment($original_price, array('type' => $row['type'], 'value' => $row['value']));
         $current_adjusted_price = $current_adjusted_price < 0 ? 0 : $current_adjusted_price;
         $table_data[$row_key]['display_price'] = $this->format_price($current_adjusted_price);
     }
     return $table_data;
 }
function product_page_pricing_table_data()
{
    $RP_WCDPD = RP_WCDPD::get_instance();
    $this_option = $RP_WCDPD->get_options();
    if ($this_option['settings']['display_table'] == 'hide' && (!isset($this_option['settings']['display_offers']) || $this_option['settings']['display_offers'] == 'hide')) {
        return;
    }
    global $product;
    if (!$product) {
        return;
    }
    // Load required classes
    require_once RP_WCDPD_PLUGIN_PATH . 'includes/classes/Pricing.php';
    $selected_rule = null;
    // Iterate over pricing rules and use the first one that has this product in conditions (or does not have if condition "not in list")
    if (isset($this_option['pricing']['sets']) && count($this_option['pricing']['sets'])) {
        foreach ($this_option['pricing']['sets'] as $rule_key => $rule) {
            if ($rule['method'] == 'quantity' && ($validated_rule = RP_WCDPD_Pricing::validate_rule($rule))) {
                if ($validated_rule['selection_method'] == 'all' && $RP_WCDPD->user_matches_rule($validated_rule)) {
                    $selected_rule = $validated_rule;
                    break;
                }
                if ($validated_rule['selection_method'] == 'categories_include' && count(array_intersect($RP_WCDPD->get_product_categories($product->id), $validated_rule['categories'])) > 0 && $RP_WCDPD->user_matches_rule($validated_rule)) {
                    $selected_rule = $validated_rule;
                    break;
                }
                if ($validated_rule['selection_method'] == 'categories_exclude' && count(array_intersect($RP_WCDPD->get_product_categories($product->id), $validated_rule['categories'])) == 0 && $RP_WCDPD->user_matches_rule($validated_rule)) {
                    $selected_rule = $validated_rule;
                    break;
                }
                if ($validated_rule['selection_method'] == 'products_include' && in_array($product->id, $validated_rule['products']) && $RP_WCDPD->user_matches_rule($validated_rule)) {
                    $selected_rule = $validated_rule;
                    break;
                }
                if ($validated_rule['selection_method'] == 'products_exclude' && !in_array($product->id, $validated_rule['products']) && $RP_WCDPD->user_matches_rule($validated_rule)) {
                    $selected_rule = $validated_rule;
                    break;
                }
            }
        }
    }
    if (is_array($selected_rule)) {
        // Quantity
        if ($selected_rule['method'] == 'quantity' && in_array($this_option['settings']['display_table'], array('modal', 'inline')) && isset($selected_rule['pricing'])) {
            if ($product->product_type == 'variable') {
                $product_variations = $product->get_available_variations();
            }
            // For variable products only - check if prices differ for different variations
            $multiprice_variable_product = false;
            if ($product->product_type == 'variable' && !empty($product_variations)) {
                $last_product_variation = array_slice($product_variations, -1);
                $last_product_variation_object = new WC_Product_Variable($last_product_variation[0]['variation_id']);
                $last_product_variation_price = $last_product_variation_object->get_price();
                foreach ($product_variations as $variation) {
                    $variation_object = new WC_Product_Variable($variation['variation_id']);
                    if ($variation_object->get_price() != $last_product_variation_price) {
                        $multiprice_variable_product = true;
                    }
                }
            }
            if ($multiprice_variable_product) {
                $variation_table_data = array();
                foreach ($product_variations as $variation) {
                    $variation_product = new WC_Product_Variation($variation['variation_id']);
                    $variation_table_data[$variation['variation_id']] = $RP_WCDPD->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
                }
            } else {
                if ($product->product_type == 'variable' && !empty($product_variations)) {
                    $variation_product = new WC_Product_Variation($last_product_variation[0]['variation_id']);
                    $table_data = $RP_WCDPD->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
                } else {
                    $table_data = $RP_WCDPD->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $product->get_price());
                }
            }
        }
        return $table_data;
    }
    return false;
}