Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/aco-woo-dynamic-pricing/includes/class-awdp-api.php
+++ b/aco-woo-dynamic-pricing/includes/class-awdp-api.php
@@ -201,6 +201,23 @@
}
}
+ // Assign next latest priority to the duplicated rule
+ $existing_rules = get_posts(array(
+ 'fields' => 'ids',
+ 'posts_per_page' => -1,
+ 'post_type' => AWDP_POST_TYPE,
+ 'post__not_in' => array($newRuleID)
+ ));
+ $max_priority = 0;
+ foreach ($existing_rules as $listID) {
+ $priority = intval(get_post_meta($listID, 'discount_priority', true));
+ if ($priority > $max_priority) {
+ $max_priority = $priority;
+ }
+ }
+ $next_priority = $max_priority + 1;
+ update_post_meta($newRuleID, 'discount_priority', $next_priority);
+
}
// Get all badges
@@ -734,6 +751,7 @@
$pricing_new_label = $data['pricing_new_label'] ? $data['pricing_new_label'] : '';
$default_fee_label = $data['default_fee_label'] ? $data['default_fee_label'] : '';
$dismessagestatus = $data['discount_message_status'] ? $data['discount_message_status'] : 0;
+ $dismessageonce = isset($data['discount_message_once']) ? ($data['discount_message_once'] ? 1 : 0) : 1;
$message = $data['discount_message'] ? $data['discount_message'] : '';
$tableposition = $data['tableposition'] ? $data['tableposition'] : '';
$tablesort = $data['tablesort'] ? $data['tablesort'] : '';
@@ -753,17 +771,17 @@
$dismessage = $data['dismessage'] ? $data['dismessage'] : '';
$dismessage_rule = $data['dismessage_rule'] ? $data['dismessage_rule'] : '';
$dismessage_position = $data['dismessage_position'] ? $data['dismessage_position'] : '';
- $dismessage_fontsize = $data['dismessage_fontsize'] ? $data['dismessage_fontsize'] : '';
- $dismessage_paddding_lm = $data['dismessage_paddding_lm'] ? $data['dismessage_paddding_lm'] : '';
- $dismessage_paddding_tp = $data['dismessage_paddding_tp'] ? $data['dismessage_paddding_tp'] : '';
- $dismessage_radius = $data['dismessage_radius'] ? $data['dismessage_radius'] : '';
+ $dismessage_fontsize = isset($data['dismessage_fontsize']) && $data['dismessage_fontsize'] !== '' ? $data['dismessage_fontsize'] : '';
+ $dismessage_paddding_lm = isset($data['dismessage_paddding_lm']) && $data['dismessage_paddding_lm'] !== '' ? $data['dismessage_paddding_lm'] : '';
+ $dismessage_paddding_tp = isset($data['dismessage_paddding_tp']) && $data['dismessage_paddding_tp'] !== '' ? $data['dismessage_paddding_tp'] : '';
+ $dismessage_radius = isset($data['dismessage_radius']) && $data['dismessage_radius'] !== '' ? $data['dismessage_radius'] : '';
$dismessage_background = $data['dismessage_background'] ? $data['dismessage_background'] : '';
$dismessage_color = $data['dismessage_color'] ? $data['dismessage_color'] : '';
- $border_top_width = $data['border_top_width'] ? $data['border_top_width'] : '';
- $border_right_width = $data['border_right_width'] ? $data['border_right_width'] : '';
- $border_bottom_width = $data['border_bottom_width'] ? $data['border_bottom_width'] : '';
- $border_left_width = $data['border_left_width'] ? $data['border_left_width'] : '';
+ $border_top_width = isset($data['border_top_width']) && $data['border_top_width'] !== '' ? $data['border_top_width'] : '';
+ $border_right_width = isset($data['border_right_width']) && $data['border_right_width'] !== '' ? $data['border_right_width'] : '';
+ $border_bottom_width = isset($data['border_bottom_width']) && $data['border_bottom_width'] !== '' ? $data['border_bottom_width'] : '';
+ $border_left_width = isset($data['border_left_width']) && $data['border_left_width'] !== '' ? $data['border_left_width'] : '';
$offer_border_color = $data['offer_border_color'] ? $data['offer_border_color'] : '';
//TimeZone
@@ -908,6 +926,11 @@
else
update_option('awdp_message_status', $dismessagestatus);
+ if ( false === get_option('awdp_message_once') )
+ add_option('awdp_message_once', $dismessageonce, '', 'yes');
+ else
+ update_option('awdp_message_once', $dismessageonce);
+
if ( false === get_option('awdp_discount_message') )
add_option('awdp_discount_message', $message, '', 'yes');
else
@@ -1045,6 +1068,7 @@
$result['discount_item_description'] = $discount_item_description;
$result['default_fee_label'] = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : '';
$result['discount_message_status'] = get_option('awdp_message_status') ? get_option('awdp_message_status') : '';
+ $result['discount_message_once'] = ( get_option('awdp_message_once') !== false ) ? get_option('awdp_message_once') : 1;
$result['discount_message'] = get_option('awdp_discount_message') ? get_option('awdp_discount_message') : '';
$result['tableposition'] = get_option('awdp_table_position') ? get_option('awdp_table_position') : ( get_option('tableposition') ? get_option('tableposition') : '' );
$result['tablesort'] = get_option('awdp_table_sort') ? get_option('awdp_table_sort') : '';
@@ -1115,6 +1139,35 @@
{
$this->delete_transient();
$data = $data->get_params();
+
+ $rule_name = isset($data['name']) ? trim($data['name']) : '';
+ $discount_type = isset($data['discount_type']) ? trim($data['discount_type']) : '';
+
+ if ( empty($rule_name) || empty($discount_type) ) {
+ return new WP_Error(
+ 'rest_rule_invalid',
+ __( 'Rule Name and Discount Type are required.', 'aco-woo-dynamic-pricing' ),
+ array( 'status' => 400 )
+ );
+ }
+
+ if ( $discount_type === 'cart_quantity' && isset($data['quantityranges']) && is_array($data['quantityranges']) ) {
+ foreach ( $data['quantityranges'] as $range ) {
+ $start = isset($range['start_range']) ? trim($range['start_range']) : '';
+ $end = isset($range['end_range']) ? trim($range['end_range']) : '';
+
+ if ( $start !== '' && $end !== '' && is_numeric($start) && is_numeric($end) ) {
+ if ( floatval($start) > floatval($end) ) {
+ return new WP_Error(
+ 'rest_rule_invalid_range',
+ __( 'From value cannot be greater than To value.', 'aco-woo-dynamic-pricing' ),
+ array( 'status' => 400 )
+ );
+ }
+ }
+ }
+ }
+
if ($data['id']) {
$my_post = array(
'ID' => $data['id'],
@@ -1167,12 +1220,18 @@
$wdp_show_in_loop = isset($data['show_in_loop']) ? $data['show_in_loop'] : '';
$wdp_rules = isset($data['rules']) ? $data['rules'] : '';
$wdp_quantity_type = isset($data['quantity_type']) ? $data['quantity_type'] : '';
+ if ( $wdp_discount_type === 'cart_quantity' && empty( $wdp_quantity_type ) ) {
+ $wdp_quantity_type = 'type_product';
+ }
$wdp_weekday = isset($data['discount_schedule_weekday']) ? $data['discount_schedule_weekday'] : '';
$start_time = isset($data['startTime']) ? date('H:i', strtotime($data['startTime'] )) : '';
$end_time = isset($data['endTime']) ? date('H:i', strtotime($data['endTime'] )) : '';
$table_layout = isset($data['table_layout']) ? $data['table_layout'] : '';
+ if ( $wdp_discount_type === 'cart_quantity' && empty( $table_layout ) ) {
+ $table_layout = 'vertical';
+ }
$disc_calc_type = isset($data['disc_calc_type']) ? $data['disc_calc_type'] : '';
@@ -1270,6 +1329,9 @@
if (isset($data['id'])) {
$result = array();
$discount_rule = get_post($data['id']);
+ if ( !$discount_rule || is_wp_error($discount_rule) || get_post_type($discount_rule) !== AWDP_POST_TYPE ) {
+ return new WP_Error( 'rest_rule_not_found', __( 'Rule not found or is invalid.', 'aco-woo-dynamic-pricing' ), array( 'status' => 404 ) );
+ }
$discount_config = get_post_meta($discount_rule->ID, 'discount_config', true) ? get_post_meta($discount_rule->ID, 'discount_config', true) : [];
// Scheduling dates
@@ -1319,13 +1381,15 @@
}
}
if( $taxvalues != '' ) {
- $defaultTax = $wpdb->get_results ( "SELECT DISTINCT cat.term_id as value, cat.name as label FROM {$wpdb->prefix}terms cat LEFT JOIN {$wpdb->prefix}term_taxonomy cattax ON cat.term_id = cattax.term_id WHERE cattax.term_id IN (" . $taxvalues . ")" );
+ $safe_taxvalues = implode( ',', array_map( 'intval', explode( ',', $taxvalues ) ) );
+ $defaultTax = $wpdb->get_results( "SELECT DISTINCT cat.term_id as value, cat.name as label FROM {$wpdb->prefix}terms cat LEFT JOIN {$wpdb->prefix}term_taxonomy cattax ON cat.term_id = cattax.term_id WHERE cattax.term_id IN (" . $safe_taxvalues . ")" );
foreach ( $defaultTax as $dtax ) {
$dtax->label = html_entity_decode ( $dtax->label );
}
}
if( $prodvalues != '' ) {
- $defaultProducts = $wpdb->get_results ( "SELECT DISTINCT ID as value, post_title as label FROM {$wpdb->prefix}posts WHERE ID IN (" . $prodvalues . ")" );
+ $safe_prodvalues = implode( ',', array_map( 'intval', explode( ',', $prodvalues ) ) );
+ $defaultProducts = $wpdb->get_results( "SELECT DISTINCT ID as value, post_title as label FROM {$wpdb->prefix}posts WHERE ID IN (" . $safe_prodvalues . ")" );
foreach ( $defaultProducts as $dprod ) {
$status = get_post_status ( $dprod->value );
if ( $status === 'draft' ) {
@@ -1515,7 +1579,8 @@
$ar_cnt++;
}
if( $values != '' ) {
- $tax = $wpdb->get_results ( "SELECT DISTINCT cat.term_id as value, cat.name as label FROM {$wpdb->prefix}terms cat LEFT JOIN {$wpdb->prefix}term_taxonomy cattax ON cat.term_id = cattax.term_id WHERE cattax.term_id IN (" . $values . ")" );
+ $safe_values = implode( ',', array_map( 'intval', explode( ',', $values ) ) );
+ $tax = $wpdb->get_results( "SELECT DISTINCT cat.term_id as value, cat.name as label FROM {$wpdb->prefix}terms cat LEFT JOIN {$wpdb->prefix}term_taxonomy cattax ON cat.term_id = cattax.term_id WHERE cattax.term_id IN (" . $safe_values . ")" );
}
}
--- a/aco-woo-dynamic-pricing/includes/class-awdp-backend.php
+++ b/aco-woo-dynamic-pricing/includes/class-awdp-backend.php
@@ -109,6 +109,10 @@
add_action('admin_footer', array($this, 'wdp_deactivation_form'));
+ // Major update notice on the Plugins screen.
+ add_filter('in_plugin_update_message_' . plugin_basename($this->file), array($this, 'major_update_notice'), 10, 2);
+ add_action('admin_head-plugins.php', array($this, 'major_update_notice_styles'));
+
//Body Class
add_filter( 'admin_body_class', array($this, 'wdp_admin_class' ));
@@ -118,12 +122,57 @@
* ver @ 4.3.1
* Body Class
*/
+ public function major_update_notice($plugin_data, $response)
+ {
+ if (empty($plugin_data['new_version'])) {
+ return;
+ }
+
+ $installed = get_option($this->_token . '_version', AWDP_VERSION);
+
+ if (
+ version_compare($plugin_data['new_version'], '5.0.0', '>=') &&
+ version_compare($installed, '5.0.0', '<')
+ ) {
+ printf(
+ '<br><span class="awdp-major-update-notice">%s</span>',
+ esc_html__(
+ 'Major update: this release includes a redesigned admin UI and refactored discount engine. Back up your site before updating.',
+ 'aco-woo-dynamic-pricing'
+ )
+ );
+ }
+ }
+
+ public function major_update_notice_styles()
+ {
+ echo '<style>
+ .awdp-major-update-notice {
+ display: inline-block;
+ margin-top: 4px;
+ padding: 4px 8px;
+ font-size: 12px;
+ line-height: 1.4;
+ color: #646970;
+ background: #f6f7f7;
+ border-left: 3px solid #dba617;
+ border-radius: 2px;
+ }
+ </style>';
+ }
+
public function wdp_admin_class($classes) {
$currentScreen = get_current_screen();
$screenID = $currentScreen->id; //
if ( strpos ( $screenID, 'awdp_' ) !== false ) {
- $classes .= ( strpos ( $screenID, 'product_lists' ) !== false && strpos ( $classes, 'pricing-rules' ) === false ) ? ' pricing-rules_page_awdp_admin_product_lists' : ( ( strpos ( $screenID, 'settings' ) !== false && strpos ( $classes, 'pricing-rules' ) === false ) ? ' pricing-rules_page_awdp_ui_settings' : '' );
+ if ( strpos ( $screenID, 'product_lists' ) !== false && strpos ( $classes, 'pricing-rules' ) === false ) {
+ $classes .= ' pricing-rules_page_awdp_admin_product_lists';
+ } elseif ( strpos ( $screenID, 'settings' ) !== false && strpos ( $classes, 'pricing-rules' ) === false ) {
+ $classes .= ' pricing-rules_page_awdp_ui_settings';
+ } elseif ( strpos ( $screenID, 'help' ) !== false && strpos ( $classes, 'pricing-rules' ) === false ) {
+ $classes .= ' pricing-rules_page_awdp_ui_help';
+ }
}
return $classes;
}
@@ -278,6 +327,7 @@
wp_localize_script($this->_token . '-backend-script', 'awdp_object', array(
'api_nonce' => wp_create_nonce('wp_rest'),
'root' => rest_url('awdp/v1/'),
+ 'adminUrl' => admin_url(),
'cats' => (array)$categories,
'tags' => (array)$taglist,
'productlist' => (array)$awdpList,
--- a/aco-woo-dynamic-pricing/includes/class-awdp-discount-old.php
+++ b/aco-woo-dynamic-pricing/includes/class-awdp-discount-old.php
@@ -0,0 +1,3130 @@
+<?php
+
+if (!defined('ABSPATH'))
+ exit;
+
+class AWDP_Discount
+{
+
+ /**
+ * @var object
+ * @access private
+ * @since 1.0.0
+ */
+ private static $_instance = null;
+
+ /**
+ * The version number.
+ * @var string
+ * @access public
+ * @since 1.0.0
+ */
+ public $_version;
+ public $product_lists = false;
+ public $awdp_cart_rules = false;
+ public $apply_wdp_coupon = false;
+ public $pricing_table = [];
+ public $productvariations = [];
+ public $couponLabel = '';
+ public $wdp_discounted_price = [];
+ public $wdpCartDicount = [];
+ public $wdpCartDiscountValues = [];
+ public $awdp_cart_rule_ids = [];
+ public $variations = [];
+ public $variation_prods = [];
+ public $wdpQNitems = [];
+ public $actual_price = [];
+ public $wdp_order_meta = [];
+ public $awdp_discount_applied = [];
+ private $_active = false;
+ private $types = array();
+ private $discount_rules = false;
+ private $conversion_unit = false;
+ private $converted_rate = '';
+
+ private $discounts = array();
+ private $discounted_products = array();
+ public $discountProductPrice = '';
+ public $discountProductMaxPrice = '';
+ public $discountProductMinPrice = '';
+ public $products_on_sale = [];
+
+ public function __construct()
+ {
+
+ $this->types = Array(
+ 'percent_total_amount' => __('Percentage of cart total amount', 'aco-woo-dynamic-pricing'),
+ 'percent_product_price' => __('Percentage of product price', 'aco-woo-dynamic-pricing'),
+ 'fixed_product_price' => __('Fixed price of product price', 'aco-woo-dynamic-pricing'),
+ 'fixed_cart_amount' => __('Fixed price of cart total amount', 'aco-woo-dynamic-pricing'),
+ 'cart_quantity' => __('Quantity based discount', 'aco-woo-dynamic-pricing')
+ );
+
+ }
+
+ /**
+ * Ensures only one instance of AWDP is loaded or can be loaded.
+ * @since 1.0.0
+ * @static
+ * @see WordPress_Plugin_Template()
+ * @return Main AWDP instance
+ */
+ public static function instance($file = '', $version = '1.0.0')
+ {
+ if (is_null(self::$_instance)) {
+ self::$_instance = new self($file, $version);
+ }
+ return self::$_instance;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isActive()
+ {
+
+ return $this->_active;
+
+ }
+
+ /*
+ * @change get_price to woocommerce_before_calculate_totals
+ * @since 4.0
+ * @fix compatibility and quantity discount issues
+ */
+ public function wdpCalculateDiscount ( $cartObject ) {
+
+ if ( $cartObject ) {
+
+ $cartContents = $cartObject->cart_contents;
+ $result = [];
+ // $couponStatus = get_option('awdp_apply_coupon_discount') ? get_option('awdp_apply_coupon_discount') : false;
+ $couponStatus = false;
+
+ // Disable Discount if any other gets added to the cart
+ $disable_discount = get_option('awdp_disable_discount') ? get_option('awdp_disable_discount') : '';
+ $coupon = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : 'Discount';
+ $coupon_code = apply_filters('woocommerce_coupon_code', $coupon);
+ if ( $disable_discount && !empty ( WC()->cart->get_applied_coupons() ) && !in_array ( $coupon_code, WC()->cart->get_applied_coupons() ) ) {
+ return $cartObject;
+ }
+
+ // Load discount rules
+ $this->load_rules();
+ $this->apply_wdp_coupon = true;
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return $cartObject; // Exit if no rules
+
+ // CartContents Loop
+ foreach ( $cartContents as $cartContent ) {
+
+ $prod_ID = $cartContent['product_id'];
+ $product = wc_get_product ( $prod_ID );
+ // $product_slug = $product->get_data()['slug'];
+ $product_slug = $cartContent['data']->get_slug();
+ $quantity = $cartContent['quantity'];
+ $variationID = $cartContent['variation_id'];
+ $variations = $cartContent['variation'];
+ $disc_prod_ID = $variationID == 0 ? $prod_ID : $variationID;
+
+ // Changing Product Slug to cart key - addons compatibility
+ $cartKey = $cartContent['key'];
+
+ // Get Cart Price
+ $cartItemPrice = $cartContent['data']->get_price();
+
+ // Checking for addons price
+ $addonPrice = apply_filters('wcpa_cart_addon_data', false, $cartContent);
+ $dispPrice = $addonPrice ? ( $addonPrice['totalPrice'] - $addonPrice['excludeFromDiscount'] ) : $cartItemPrice;
+
+ // $product_price1 = apply_filters('advanced_woo_discount_rules_product_price_on_before_calculate_discount', $product_price, $product, $quantity, $cart_item, $calculate_discount_from);
+
+ /*
+ * ver @ 4.3.3
+ * Get conversion rate
+ * Remove conversion from the coupon total
+ */
+ $this->converted_rate = $this->get_con_unit($product, $cartContent['data']->get_price());
+
+ foreach ( $this->discount_rules as $k => $rule ) {
+
+ // Disable Discount for Deposit Items
+ $depositCheck = get_post_meta($rule['id'], 'deposit_check', true) ? get_post_meta($rule['id'], 'deposit_check', true) : 0;
+ if ( array_key_exists ( 'awcdp_deposit', $cartContent ) && $cartContent['awcdp_deposit'] && $depositCheck ) {
+ continue;
+ }
+
+ // Get Product List
+ if ( !$this->get_items_to_apply_discount ( $product, $rule, $disc_prod_ID, false, $product_slug ) ) {
+ continue;
+ }
+
+ // Check if User if Logged-In
+ if ( ( intval ( $rule['discount_reg_customers'] ) === 1 && !is_user_logged_in() ) || ( intval ( $rule['discount_reg_customers'] ) === 1 && is_user_logged_in() && ( !empty ( array_filter ( $rule['discount_reg_user_roles'] ) ) && empty ( array_intersect ( $rule['discount_cur_user_roles'], $rule['discount_reg_user_roles'] ) ) ) ) ) {
+ continue;
+ }
+
+ // Validate Rules
+ if( 'cart_quantity' != $rule['type'] ) { // Skipping cart_quantity rule //
+ if ( !$this->validate_discount_rules( $product, $rule, ['product_price','cart_total_amount', 'cart_total_amount_all_prods', 'cart_items', 'cart_items_all_prods', 'cart_products', 'cart_products_list'], $cartContent ) ) {
+ continue;
+ }
+ }
+
+ // Discounts Default Values
+ if ( !isset ( $this->discounts[$rule['id']] ) ) {
+ $this->discounts[$rule['id']] = [ 'label' => $rule['label'], 'discount_type' => $rule['type'], 'discount_remainder' => -1, 'taxable' => false ];
+ }
+
+ // Saving Actual Price (Cart View - Coupon Disabled)
+ // if ( $couponStatus && array_key_exists ( $product_slug, $this->actual_price ) == false ) {
+ // $this->actual_price[$product_slug] = $cartItemPrice;
+ // }
+
+ // Get Price
+ // $price = !empty ($this->wdp_discounted_price) ? ( ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) && $this->wdp_discounted_price[$cartKey] != '' ) ? wc_remove_number_precision ( $this->wdp_discounted_price[$cartKey] ) : $cartContent['data']->get_price() ) : $cartContent['data']->get_price();
+ $price = !empty ($this->wdp_discounted_price) ? ( ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) && $this->wdp_discounted_price[$cartKey] != '' ) ? wc_remove_number_precision ( $this->wdp_discounted_price[$cartKey] ) : $cartItemPrice ) : $cartItemPrice;
+
+ $discVariable = $this->discounts[$rule['id']];
+ $prodLists = $this->product_lists;
+
+ // Disable Double Discount
+ if ( array_key_exists ( 'discounts', $this->discounts[$rule['id']] ) && array_key_exists ( $cartKey, $this->discounts[$rule['id']]['discounts'] ) ) {
+ continue;
+ }
+
+ // Discount Types
+ if ( 'percent_product_price' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeProductPrice(), 'apply_discount_percent_product_price' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cartContent, $disc_prod_ID, $prodLists, $dispPrice, $couponStatus )
+ );
+ else if ( 'fixed_product_price' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeProductPrice(), 'apply_discount_fixed_product_price' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cartContent, $disc_prod_ID, $prodLists, $dispPrice, $couponStatus )
+ );
+ else if ( 'percent_total_amount' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeTotalAmount(), 'apply_discount_percent_total_amount' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cartContent, $disc_prod_ID, $dispPrice, $couponStatus )
+ );
+ else if ( 'fixed_cart_amount' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeTotalAmount(), 'apply_discount_fixed_price_total_amount' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cartContent, $disc_prod_ID, $dispPrice, $couponStatus )
+ );
+ else if ( 'cart_quantity' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeCartQuantity(), 'apply_discount_cart_quantity' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $prodLists, $cartContents, $cartContent, $disc_prod_ID, $dispPrice, $couponStatus )
+ );
+
+
+ if ( !empty($result) ) {
+
+ $this->discounts[$rule['id']] = $result['productDiscount'];
+ $this->discounted_products[] = $cartKey;
+ $this->wdp_discounted_price[$cartKey] = array_key_exists ( 'discountedprice', $result ) ? $result['discountedprice'] : ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) ? $this->wdp_discounted_price[$cartKey] : '' );
+
+ // Set Cart Item Price
+ // if ( $couponStatus ) {
+ // $cartContent['data']->set_price(wc_remove_number_precision($this->wdp_discounted_price[$product_slug]));
+ // }
+
+ // Order Meta
+ $coupon = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : 'Discount';
+ $coupon_code = apply_filters('woocommerce_coupon_code', $coupon);
+ $orderMetaData = [];
+ $orderMetaData['type'] = $rule['type'];
+ $orderMetaData['discount'] = $result['productDiscount'];
+ $orderMetaData['coupon'] = $coupon_code;
+ $orderMetaData['discountedPrice'] = array_key_exists ( 'discountedprice', $result ) ? $result['discountedprice'] : ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) ? $this->wdp_discounted_price[$cartKey] : '' );
+
+ $this->wdp_order_meta[$cartKey][] = $orderMetaData;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ // Show Pricing Table
+ public function show_pricing_table(){
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return ''; // Exit if no rules
+
+ // Load Product List
+ $this->set_product_list();
+
+ global $product;
+ $post_id = $product->get_id();
+ $product = wc_get_product( $post_id );
+
+ // Divi Theme Page Builder Loading issue - Fix
+ if(!$product){
+ return;
+ }
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+ $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price();
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) );
+
+ $rules = $this->discount_rules;
+ $price = $priceIncTax ? $priceIncTax : $cartPrice;
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $discountedPrice = $this->discountProductPrice;
+ $discountProductMaxPrice = $this->discountProductMaxPrice;
+ $discountProductMinPrice = $this->discountProductMinPrice;
+
+ // if( $this->converted_rate == '' && $item->get_ID() != '' ) {
+ // $this->converted_rate = $this->get_con_unit($item, $price, true);
+ // }
+
+ if ( $price == '' || $price == 0 ) return '';
+
+ $pricing_table = call_user_func_array (
+ array ( new AWDP_viewPricingTable(), 'pricin_table' ),
+ array ( $rules, $product, $price, $post_id, $prodLists, $variations, $discountedPrice, $discountProductMaxPrice, $discountProductMinPrice )
+ );
+
+ echo $pricing_table;
+
+ }
+
+ // Price View HTML
+ public function get_product_price_html ( $item_price, $product )
+ {
+
+ if ( !$product ) return $item_price;
+
+ $updatedPrice = '';
+ $post_id = $product->get_id();
+
+ /*
+ * Set / Reset Attribute Value
+ * Support for Feed Plugin - Set sale price attribute key as 'acowdp_sale_price'
+ * ver @ 4.4.4
+ */
+ if ( metadata_exists ( 'post', $post_id, AWDP_Feed_Attribute ) ) {
+ update_post_meta ( $post_id, AWDP_Feed_Attribute, '' );
+ } else {
+ add_post_meta ( $post_id, AWDP_Feed_Attribute, '' );
+ }
+ // End
+
+ if ( is_admin() && !wp_doing_ajax() )
+ return $item_price;
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return $item_price; // Exit if no rules
+
+ // Load Product List
+ $this->set_product_list();
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+ $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price();
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) );
+
+ $rules = $this->discount_rules;
+ $price = $priceIncTax ? $priceIncTax : $cartPrice;
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $cartRules = $this->awdp_cart_rules;
+
+ // Display regular price instead of sale price @ ver 4.3.3
+ $displayPrcIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array('price' => $product->get_regular_price() ) ) : wc_get_price_excluding_tax( $product, array('price' => $product->get_regular_price() ) );
+ $addition_settings = get_option('awdp_addition_settings') ? get_option('awdp_addition_settings') : [];
+ // $use_regular = array_key_exists ( 'use_regular', $addition_settings ) ? $addition_settings['use_regular'] : false;
+ // $display_price = $use_regular ? ( $displayPrcIncTax ? $displayPrcIncTax : $product->get_regular_price() ) : '';
+ // $display_price = $displayPrcIncTax ? $displayPrcIncTax : $product->get_regular_price();
+ $display_price = '';
+
+ // if( $this->converted_rate == '' && $item->get_ID() != '' ) {
+ // $this->converted_rate = $this->get_con_unit($item, $price, true);
+ // }
+
+ if ( $price == '' || $price == 0 ) return $item_price;
+
+ $viewPrice = call_user_func_array (
+ array ( new AWDP_viewProductPrice(), 'product_price' ),
+ array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price, $display_price )
+ );
+
+ if ( is_array ( $viewPrice ) ) {
+ $updatedPrice = $viewPrice['itemPrice'];
+ $this->discountProductPrice = $viewPrice['discountedPrice'];
+ $this->discountProductMaxPrice = $viewPrice['discountedMaxPrice'];
+ $this->discountProductMinPrice = $viewPrice['discountedMinPrice'];
+ }
+
+ return $updatedPrice ? $updatedPrice : $item_price;
+
+ }
+
+ // WCPA Get Variation Price
+ public function wdpWCPAVariationPrice ( )
+ {
+
+ // global $product;
+ // $product->get_id();
+
+ // Reset Query
+ wp_reset_query();
+
+ $post_id = get_the_ID();
+ $product = wc_get_product( $post_id );
+
+ if ( !$product ) return '';
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+ $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price();
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) );
+
+ $price = $priceIncTax ? $priceIncTax : $cartPrice;
+
+ if ( is_admin() )
+ return $price;
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return $price; // Exit if no rules
+
+ // Load Product List
+ $this->set_product_list();
+
+ $updatedPrice = '';
+ $product_slug = $product->get_data()['slug'];
+
+ $rules = $this->discount_rules;
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $cartRules = $this->awdp_cart_rules;
+ $item_price = $price;
+
+ // if( $this->converted_rate == '' && $item->get_ID() != '' ) {
+ // $this->converted_rate = $this->get_con_unit($item, $price, true);
+ // }
+ $priceGroup = call_user_func_array (
+ array ( new AWDP_productGroup(), 'product_group' ),
+ array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price )
+ );
+
+ if ( is_array ( $priceGroup ) ) {
+
+ return new WP_REST_Response($priceGroup, 200);
+
+ }
+
+ return $price;
+
+ }
+
+ // Adding WCPA Filed Value For Quantity Discount
+ public function wcpaQunantity_Discount() {
+
+ // Verify nonce to prevent CSRF on unauthenticated AJAX endpoint.
+ check_ajax_referer( 'awdpnonce', 'nonce' );
+
+ $itemCount = isset( $_GET['proCount'] ) ? absint( $_GET['proCount'] ) : 1;
+ $this->load_rules();
+ $rules = $this->discount_rules;
+ $result = ['fixed' => 0, 'percentage' => 0];
+ foreach ( $rules as $rule ) {
+ if ( $rule['type'] == 'cart_quantity') {
+ foreach ($rule['quantity_rules'] as $quantity_rule) {
+ if($itemCount >= $quantity_rule['start_range'] && $itemCount <= $quantity_rule['end_range']) {
+ if($quantity_rule['dis_type'] == 'percentage') {
+ $value = $quantity_rule['dis_value'] ? $quantity_rule['dis_value'] / 100 : 0;
+ $result['fixed'] = 0;
+ $result['percentage'] = round($value, 2);
+ } elseif ( $quantity_rule['dis_type'] == 'fixed' ) {
+ $value = $quantity_rule['dis_value'] ? $quantity_rule['dis_value'] : 0;
+ $result['percentage'] = 0;
+ $result['fixed'] = round($value, 2);
+ }
+ }
+
+ }
+ }
+ }
+ if ( is_array ( $result ) ) {
+ return json_encode($result);
+ }
+ return $result;
+ }
+
+ // WCPA Discount Price For Frontend
+ public function wdpDynamicDiscount ()
+ {
+
+ // Verify nonce to prevent CSRF on unauthenticated AJAX endpoint.
+ check_ajax_referer( 'awdpnonce', 'nonce' );
+
+ $post_id = isset( $_GET['prodID'] ) ? absint( $_GET['prodID'] ) : get_the_ID();
+ $variation_id = isset( $_GET['varID'] ) ? absint( $_GET['varID'] ) : 0;
+ $itemCount = isset( $_GET['proCount'] ) ? absint( $_GET['proCount'] ) : 1;
+ $product = $variation_id ? wc_get_product ( $variation_id ) : wc_get_product ( $post_id );
+ if ( !$product ) return '';
+
+ update_option('itemCount', $itemCount);
+
+ /*
+ * ver @ 5.0.5
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+ $pirce_include_tax = get_option( 'woocommerce_prices_include_tax' );
+ $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price();
+
+ /*
+ * ver @ 5.0.9
+ * If more than 2 decimal points, round to 2 decimal points
+ */
+ $decimal_points = get_option( 'woocommerce_price_num_decimals' ) ? get_option( 'woocommerce_price_num_decimals' ) : 2;
+ $priceIncTax = ( ( strlen ( strrchr ( wc_get_price_including_tax ( $product, array ( 'price' => $cartPrice ) ), '.' ) ) -1 ) > 2 ) ? round ( wc_get_price_including_tax ( $product, array ( 'price' => $cartPrice ) ), 2 ) : wc_get_price_including_tax ( $product, array ( 'price' => $cartPrice ) );
+ $priceExcTax = ( ( strlen ( strrchr ( wc_get_price_excluding_tax ( $product, array ( 'price' => $cartPrice ) ), '.' ) ) -1 ) > 2 ) ? round ( wc_get_price_excluding_tax ( $product, array ( 'price' => $cartPrice ) ), 2 ) : wc_get_price_excluding_tax ( $product, array ( 'price' => $cartPrice ) );
+
+ // $priceAfterTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax ( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax ( $product, array ( 'price' => $cartPrice ) );
+ $priceAfterTax = ( 'incl' === $tax_display_mode ) ? $priceIncTax : ( ( 'yes' === $pirce_include_tax && 'excl' === $tax_display_mode ) ? $priceExcTax : '' );
+
+ $price = $priceAfterTax ? $priceAfterTax : $cartPrice;
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return $price; // Exit if no rules
+
+
+ // Load Product List
+ $this->set_product_list();
+
+ $updatedPrice = '';
+ $product_slug = $product->get_data()['slug'];
+ $rules = $this->discount_rules;
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $cartRules = $this->awdp_cart_rules;
+ $item_price = $price;
+
+ // if ( $discountedPrice ) {
+ // $product_id = $_REQUEST['product_id'];
+ // }
+ $priceGroup = call_user_func_array (
+ array ( new AWDP_productGroup(), 'product_price' ),
+ array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price,$itemCount)
+ );
+
+ // if ( is_array ( $priceGroup ) ) {
+ // return new WP_REST_Response($priceGroup, 200);
+ // }
+
+ if ( is_array ( $priceGroup ) ) {
+ return json_encode($priceGroup);
+ }
+ return $price;
+
+ }
+
+ public function wcpaDiscount($response, $product)
+ {
+
+ $result = [];
+
+ if ( !$product ) return $response;
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null ) return $response;
+
+ // Load Product List
+ $this->set_product_list();
+
+ $rules = $this->discount_rules;
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $cartRules = $this->awdp_cart_rules;
+ // $item_price = $price;
+
+ $wcpaDisc = call_user_func_array (
+ array ( new AWDP_productGroup(), 'wcpa_discount' ),
+ array ( $rules, $product )
+ );
+
+ if ( !empty ($wcpaDisc) ) {
+ // Considering only single discount value as multiple values / group currently not supported with WCPA
+ foreach ( $wcpaDisc as $disc ) {
+ if ( $disc['type'] == 'percentage' ) {
+ $value = $disc['value'] ? $disc['value'] / 100 : 0;
+ $result['fixed'] = 0;
+ $result['percentage'] = $value;
+ } elseif ( $disc['type'] == 'fixed' ) {
+ $value = $disc['value'] ? $disc['value'] : 0;
+ $result['percentage'] = 0;
+ $result['fixed'] = $value;
+ }
+ }
+ }
+
+ return !empty($result) ? $result : $response;
+
+ }
+
+ // WCPA Price
+ public function wdpWCPAPrice($default, $product) {
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return $default; // Exit if no rules
+
+ // Load Product List
+ $this->set_product_list();
+
+ if ( !$product ) return $default;
+
+ $updatedPrice = '';
+ $result = [];
+ $product_slug = $product->get_data()['slug'];
+ $post_id = $product->get_id();
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+ $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price();
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) );
+
+ $rules = $this->discount_rules;
+ $price = $priceIncTax ? $priceIncTax : $cartPrice;
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $cartRules = $this->awdp_cart_rules;
+ $item_price = $price;
+
+ // Display regular price instead of sale price @ ver 4.3.3
+ $displayPrcIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array('price' => $product->get_regular_price() ) ) : wc_get_price_excluding_tax( $product, array('price' => $product->get_regular_price() ) );
+ $addition_settings = get_option('awdp_addition_settings') ? get_option('awdp_addition_settings') : [];
+ // $use_regular = array_key_exists ( 'use_regular', $addition_settings ) ? $addition_settings['use_regular'] : false;
+ // $display_price = $use_regular ? ( $displayPrcIncTax ? $displayPrcIncTax : $product->get_regular_price() ) : '';
+ // $display_price = $displayPrcIncTax ? $displayPrcIncTax : $product->get_regular_price();
+ $display_price = '';
+
+ $viewPrice = call_user_func_array (
+ array ( new AWDP_viewProductPrice(), 'product_price' ),
+ array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price, $display_price )
+ );
+
+ $wcpaPrice = call_user_func_array (
+ array ( new AWDP_productGroup(), 'product_price' ),
+ array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price)
+ );
+
+ if ( is_array ( $viewPrice ) || is_array ( $wcpaPrice ) ) {
+
+ // $updatedPrice = $viewPrice['discountedPrice'];
+
+ $result['price'] = $viewPrice['discountedPrice'] ? $viewPrice['discountedPrice'] : $wcpaPrice['price'];
+ $result['originalPrice'] = $price;
+
+ return $result;
+
+ }
+
+ return $default;
+
+ }
+
+ // Cart Price View
+ public function cart_discount_items ( $item_price, $cart_item )
+ {
+
+ // Disable Discount if any other gets added to the cart
+ $disable_discount = get_option('awdp_disable_discount') ? get_option('awdp_disable_discount') : '';
+ $coupon = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : 'Discount';
+ $coupon_code = apply_filters('woocommerce_coupon_code', $coupon);
+ if ( $disable_discount && !empty ( WC()->cart->get_applied_coupons() ) && !in_array ( $coupon_code, WC()->cart->get_applied_coupons() ) ) {
+ return $item_price;
+ }
+
+ // Load discount rules
+ $this->load_rules();
+
+ // Check if discount is active
+ if ( $this->discount_rules == null )
+ return $item_price; // Exit if no rules
+
+ // Load Product List
+ $this->set_product_list();
+
+ $post_id = $cart_item['product_id'];
+ $quantity = $cart_item['quantity'];
+ $product = wc_get_product( $post_id );
+
+ $rules = $this->discount_rules;
+ // $price = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price(); // get cart price
+ // $price = $cart_item['data']->get_price(); // get cart price
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+
+ $cartPrice = $cart_item['data']->get_price();
+ // Checking for addons price
+ $addonPrice = apply_filters('wcpa_cart_addon_data', false, $cart_item);
+ $dispPrice = $addonPrice ? ( $addonPrice['totalPrice'] - $addonPrice['excludeFromDiscount'] ) : $cartPrice;
+
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) );
+
+ $price = $priceIncTax ? $priceIncTax : $cartPrice; // commenting $discPrices - fix - cart price mismatch when multiples rules are applied
+
+ // $price = '';
+ // $product_slug = $product->get_data()['slug'];
+ $product_slug = $cart_item['data']->get_slug();
+ $prodLists = $this->product_lists;
+ $variations = $this->variations;
+ $cartContents = WC()->cart->get_cart();
+ // $couponStatus = get_option('awdp_apply_coupon_discount') ? get_option('awdp_apply_coupon_discount') : false;
+ $couponStatus = false;
+ // $disc_prod_ID = $post_id;
+ $variationID = $cart_item['variation_id'];
+ // $variations = $cart_item['variation'];
+ $disc_prod_ID = $variationID == 0 ? $post_id : $variationID;
+
+ // Changing Product Slug to cart key - addons compatibility
+ $cartKey = $cart_item['key'];
+
+ // if( $this->converted_rate == '' && $item->get_ID() != '' ) {
+ // $this->converted_rate = $this->get_con_unit($item, $price, true);
+ // }
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product ) : wc_get_price_excluding_tax( $product );
+
+ // Display regular price instead of sale price @ ver 4.3.3
+ $displayPrcIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array('price' => $product->get_regular_price() ) ) : wc_get_price_excluding_tax( $product, array('price' => $product->get_regular_price() ) );
+ $addition_settings = get_option('awdp_addition_settings') ? get_option('awdp_addition_settings') : [];
+ // $use_regular = array_key_exists ( 'use_regular', $addition_settings ) ? $addition_settings['use_regular'] : false;
+ // $display_price = $use_regular ? ( $displayPrcIncTax ? $displayPrcIncTax : $product->get_regular_price() ) : '';
+ // $display_price = $displayPrcIncTax ? $displayPrcIncTax : $product->get_regular_price();
+ $display_price = '';
+
+ foreach ( $this->discount_rules as $k => $rule ) {
+
+
+ // Disable Discount for Deposit Items
+ $depositCheck = get_post_meta($rule['id'], 'deposit_check', true) ? get_post_meta($rule['id'], 'deposit_check', true) : 0;
+ if ( array_key_exists ( 'awcdp_deposit', $cart_item ) && $cart_item['awcdp_deposit'] && $depositCheck ) {
+ continue;
+ }
+
+ // Get Product List
+ if ( !$this->get_items_to_apply_discount ( $product, $rule, $disc_prod_ID, false, $product_slug ) ) {
+ continue;
+ }
+
+ // Check if User if Logged-In
+ if ( ( intval ( $rule['discount_reg_customers'] ) === 1 && !is_user_logged_in() ) || ( intval ( $rule['discount_reg_customers'] ) === 1 && is_user_logged_in() && ( !empty ( array_filter ( $rule['discount_reg_user_roles'] ) ) && empty ( array_intersect ( $rule['discount_cur_user_roles'], $rule['discount_reg_user_roles'] ) ) ) ) ) {
+ continue;
+ }
+
+ // Validate Rules
+ if( 'cart_quantity' != $rule['type'] ) { // Skipping cart_quantity rule //
+ if ( !$this->validate_discount_rules( $product, $rule, ['product_price','cart_total_amount', 'cart_total_amount_all_prods', 'cart_items', 'cart_items_all_prods', 'cart_products', 'cart_products_list'], $cart_item ) ) {
+ continue;
+ }
+ }
+
+ // Discounts Default Values
+ if ( !isset ( $this->discounts[$rule['id']] ) ) {
+ $this->discounts[$rule['id']] = [ 'label' => $rule['label'], 'discount_type' => $rule['type'], 'discount_remainder' => -1, 'taxable' => false ];
+ }
+
+ /*
+ * Disable Double Discount
+ * @ver 4.1.6
+ * $product_slug added to awdp_discount_applied list is discount already applied
+ */
+ if ( array_key_exists ( 'discounts', $this->discounts[$rule['id']] ) && array_key_exists ( $cartKey, $this->discounts[$rule['id']]['discounts'] ) ) {
+ $this->awdp_discount_applied[] = $product_slug;
+ continue;
+ }
+
+ // Get Price
+ // if ( $couponStatus && array_key_exists ( $product_slug, $this->actual_price ) ) {
+ // $price = $this->actual_price[$product_slug];
+ // } else {
+ // $price = !empty ($this->wdp_discounted_price) ? ( ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) && $this->wdp_discounted_price[$cartKey] != '' ) ? wc_remove_number_precision ( $this->wdp_discounted_price[$cartKey] ) : $cart_item['data']->get_price() ) : $cart_item['data']->get_price();
+ $price = !empty ($this->wdp_discounted_price) ? ( ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) && $this->wdp_discounted_price[$cartKey] != '' ) ? wc_remove_number_precision ( $this->wdp_discounted_price[$cartKey] ) : $cart_item['data']->get_price() ) : $cart_item['data']->get_price();
+ // }
+
+ $discVariable = $this->discounts[$rule['id']];
+ $prodLists = $this->product_lists;
+
+ // Discount Types
+ if ( 'percent_product_price' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeProductPrice(), 'apply_discount_percent_product_price' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cart_item, $disc_prod_ID, $prodLists, $dispPrice, $couponStatus )
+ );
+ else if ( 'fixed_product_price' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeProductPrice(), 'apply_discount_fixed_product_price' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cart_item, $disc_prod_ID, $prodLists, $dispPrice, $couponStatus )
+ );
+ else if ( 'percent_total_amount' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeTotalAmount(), 'apply_discount_percent_total_amount' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cart_item, $disc_prod_ID, $dispPrice, $couponStatus )
+ );
+ else if ( 'fixed_cart_amount' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeTotalAmount(), 'apply_discount_fixed_price_total_amount' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $cart_item, $disc_prod_ID, $dispPrice, $couponStatus )
+ );
+ else if ( 'cart_quantity' == $rule['type'] )
+ $result = call_user_func_array (
+ array ( new AWDP_typeCartQuantity(), 'apply_discount_cart_quantity' ),
+ array ( $rule, $product, $price, $quantity, $discVariable, $prodLists, $cartContents, $cart_item, $disc_prod_ID, $dispPrice, $couponStatus )
+ );
+
+
+ if ( !empty($result) ) {
+ $this->discounts[$rule['id']] = $result['productDiscount'];
+ $this->discounted_products[] = $cartKey;
+ $this->wdp_discounted_price[$cartKey] = array_key_exists ( 'discountedprice', $result ) ? $result['discountedprice'] : ( array_key_exists ( $cartKey, $this->wdp_discounted_price ) ? $this->wdp_discounted_price[$cartKey] : '' );
+ }
+
+ }
+
+ $activeDiscounts = $this->discounts;
+
+ $viewPrice = call_user_func_array (
+ array ( new AWDP_viewCartPrice(), 'cart_price' ),
+ array ( $rules, $price, $cart_item, $prodLists, $item_price, $activeDiscounts, $product, $quantity, $display_price )
+ );
+
+ return $viewPrice;
+
+ }
+
+ // Sub Total Calculations
+ public function wdpCartLoop ( $wc, $cart_item, $cart_item_key )
+ {
+
+ // $couponStatus = get_option('awdp_apply_coupon_discount') ? get_option('awdp_apply_coupon_discount') : false;
+
+ // if ( $couponStatus ) {
+ // return $wc;
+ // }
+
+ // $wcpa_price = preg_match('/<span class="wcpa_price">(.*?)</span>/s', $wc, $match);
+
+ $activeDiscounts = $this->discounts;
+ // $variationDiscounts = $this->variationDiscounts;
+ $decimalPoints = wc_get_price_decimals();
+ $product_id = $cart_item['product_id'];
+ $product = wc_get_product( $product_id );
+
+ /*
+ * ver @ 4.3.3
+ * Tax Settings
+ */
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+
+ $cartPrice = $cart_item['data']->get_price();
+ // Checking for addons price
+ $addonPrice = apply_filters('wcpa_cart_addon_data', false, $cart_item);
+ $dispPrice = $addonPrice ? ( $addonPrice['totalPrice'] - $addonPrice['excludeFromDiscount'] ) : $cartPrice;
+
+ $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) );
+
+ $price = $priceIncTax ? $priceIncTax : $cartPrice;
+ $quantity = $cart_item['quantity'];
+ $discount = 0;
+ $prod_ID = $cart_item['data']->get_slug();
+ $cartKey = $cart_item['key'];
+
+ // if ( $price > 0 ) {
+ // if (WC()->cart->display_prices_including_tax()) {
+ // $price = $this->wdp_price_including_tax ( $product, $price, array(
+ // 'qty' => $quantity,
+ // 'price' => $price,
+ // ) );
+ // } else {
+ // $price = $this->wdp_price_excluding_tax ( $product, $price, array(
+ // 'qty' => $quantity,
+ // 'price' => $price
+ // ) );
+ // }
+ // }
+
+ if ( $activeDiscounts ) {
+
+ foreach ( $activeDiscounts as $discounts ) {
+ if ( array_key_exists ( 'discounts', $discounts ) ) {
+ if ( array_key_exists ( $cartKey, $discounts['discounts'] ) && $discounts['discounts'][$cartKey]['discount'] != '' && ( $discounts['discounts'][$cartKey]["displayoncart"] != false ) ) {
+ $discount += wc_remove_number_precision ( $discounts['discounts'][$cartKey]['discount'] );
+ }
+ }
+ }
+
+ $discount = ( 'incl' === $tax_display_mode ) ? round( wc_get_price_including_tax( $product, array ( 'price' => $discount ) ),$decimalPoints ) : round( wc_get_price_excluding_tax( $product, array ( 'price' => $discount ) ), $decimalPoints );
+ $discounted_price = ( $price - $discount ) * $quantity;
+
+ $price = round ( $discounted_price, $decimalPoints );
+
+ $product_subtotal = wc_price ( $price );
+
+ if ( $product->is_taxable() && get_option('woocommerce_tax_display_cart') == 'incl' ) {
+ if( !wc_prices_include_tax() && WC()->cart->get_subtotal_tax() > 0 ) {
+ $product_subtotal .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
+ }
+ }
+
+ return $product_subtotal;
+
+ } else {
+
+ return $wc;
+
+ }
+
+ }
+
+ /