';
}
foreach ($quantity_rules as $quantity_rule) {
$discount_val = $quantity_rule['dis_value'];
$discount_typ = $quantity_rule['dis_type'];
// Currency conversion rate
if( $this->converted_rate == '' && $item->get_ID() != '' ) {
$this->converted_rate = $this->get_con_unit($item, $price, true);
}
// $converted_rate = $this->converted_rate;
$converted_rate = 1; // Removing coupon amount - get price changed to $price - calculate total
// Pricing Table
if ($discount_typ == 'percentage') {
$discount_pt = $pricing_table_price * ((float)$discount_val / 100);
$discount_pt = min($pricing_table_price, $discount_pt);
// Updated Price
$discounted_new_price = (($pricing_table_price - $discount_pt) > 0) ? wc_price ( wc_remove_number_precision ( $pricing_table_price - $discount_pt ) * $converted_rate ) : 0;
} else if ($discount_typ == 'fixed') {
$discount_pt = wc_add_number_precision($discount_val * $converted_rate);
// Discount
$discounted_new_price = wc_price($discount_val) . ' will be deducted from cart';
}
// $discounted_new_price = (($pricing_table_price - $discount_pt) > 0) ? wc_price ( wc_remove_number_precision ( $pricing_table_price - $discount_pt ) * $converted_rate ) : 0;
if ( $value_display == 'discount_value' ) {
if ($discount_typ == 'percentage') {
$discounted_new_price = (float)$discount_val . '% OFF';
} else if ($discount_typ == 'fixed') {
$discounted_new_price = wc_price($discount_val) . ' OFF on cart value';
}
}
// Pricing Table Calculations
if ($item->is_type('variable')) {
// Variation Pricing Table
$price_to_discount_max = max($variation_prices);
$price_to_discount_min = min($variation_prices);
if ($discount_typ == 'percentage') {
$discount_max_value = max($variation_prices) * ((float)$discount_val / 100);
$discount_min_value = min($variation_prices) * ((float)$discount_val / 100);
// $discount_max_value = min($price_to_discount, $discount_pt);
} else if ($discount_typ == 'fixed') {
$discount_max_value = wc_add_number_precision($discount_val);
$discount_min_value = wc_add_number_precision($discount_val);
}
$discounted_new_max_price = (($price_to_discount_max - $discount_max_value) > 0) ? wc_price ( wc_remove_number_precision ( $price_to_discount_max - $discount_max_value ) ) : 0;
$discounted_new_min_price = (($price_to_discount_min - $discount_min_value) > 0) ? wc_price ( wc_remove_number_precision ( $price_to_discount_min - $discount_min_value ) ) : 0;
if ($table_layout == 'horizontal') {
if ($quantity_rule['start_range'] == $quantity_rule['end_range']) {
$tr_qn .= '| ' . $quantity_rule['start_range'] . ' | ';
} else if ($quantity_rule['end_range']) {
$tr_qn .= '' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | ';
} else {
$tr_qn .= '' . $quantity_rule['start_range'] . ' + | ';
}
if ( $value_display == 'discount_value' ) {
if ($discount_typ == 'percentage') {
$tr_pr .= '' .(float)$discount_val . '% OFF | ';
} else if ($discount_typ == 'fixed') {
$tr_pr .= '' .(float)$discount_val . ' OFF | ';
}
} else {
if ($discounted_new_min_price == $discounted_new_max_price) {
$tr_pr .= '' . $discounted_new_min_price . ' | ';
} else {
$tr_pr .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | ';
}
}
} else {
if ($quantity_rule['start_range'] == $quantity_rule['end_range']) {
$table .= '';
$table .= '| ' . $quantity_rule['start_range'] . ' | ';
if ( $value_display == 'discount_value' ) {
if ($discount_typ == 'percentage') {
$table .= '' .(float)$discount_val . '% OFF | ';
} else if ($discount_typ == 'fixed') {
$table .= '' .(float)$discount_val . ' OFF | ';
}
} else {
if ($discounted_new_min_price == $discounted_new_max_price) {
$table .= '' . $discounted_new_min_price . ' | ';
} else {
$table .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | ';
}
}
$table .= '
';
} else if ($quantity_rule['end_range']) {
$table .= '';
$table .= '| ' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | ';
if ( $value_display == 'discount_value' ) {
if ($discount_typ == 'percentage') {
$table .= '' .(float)$discount_val . '% OFF | ';
} else if ($discount_typ == 'fixed') {
$table .= '' .(float)$discount_val . ' OFF | ';
}
} else {
if ($discounted_new_min_price == $discounted_new_max_price) {
$table .= '' . $discounted_new_min_price . ' | ';
} else {
$table .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | ';
}
}
$table .= '
';
} else {
$table .= '';
$table .= '| ' . $quantity_rule['start_range'] . ' + | ';
if ( $value_display == 'discount_value' ) {
if ($discount_typ == 'percentage') {
$table .= '' .(float)$discount_val . '% OFF | ';
} else if ($discount_typ == 'fixed') {
$table .= '' .(float)$discount_val . ' OFF | ';
}
} else {
if ($discounted_new_min_price == $discounted_new_max_price) {
$table .= '' . $discounted_new_min_price . ' | ';
} else {
$table .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | ';
}
}
$table .= '
';
}
}
} else {
if ($table_layout == 'horizontal') {
if ($quantity_rule['start_range'] == $quantity_rule['end_range']) {
$tr_qn .= '' . $quantity_rule['start_range'] . ' | ';
} else if ($quantity_rule['end_range']) {
$tr_qn .= '' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | ';
} else {
$tr_qn .= '' . $quantity_rule['start_range'] . ' + | ';
}
$tr_pr .= '' . $discounted_new_price . ' | ';
} else {
if ($quantity_rule['start_range'] == $quantity_rule['end_range']) {
$table .= '| ' . $quantity_rule['start_range'] . ' | ' . $discounted_new_price . ' |
';
} else if ($quantity_rule['end_range']) {
$table .= '| ' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | ' . $discounted_new_price . ' |
';
} else {
$table .= '| ' . $quantity_rule['start_range'] . ' + | ' . $discounted_new_price . ' |
';
}
}
}
// End PT
// Cart Calculations
if ( isset ( WC()->cart ) && WC()->cart->get_cart_contents_count() > 0 ) {
if ( $wdp_cart_quantity >= (int)$quantity_rule['start_range'] && $wdp_cart_quantity <= (int)$quantity_rule['end_range'] ) {
$discount_amt = 0;
if ($discount_typ == 'percentage') {
$discount_amt = $wdp_cart_totals * ($discount_val / 100);
$this->discounts[$rule['id']]['discounts']['type'] = 'percentage';
$this->discounts[$rule['id']]['discounts']['value'] = $discount_val;
} else if ($discount_typ == 'fixed') {
$discount_amt = $discount_val;
$this->discounts[$rule['id']]['discounts']['type'] = 'fixed';
$this->discounts[$rule['id']]['discounts']['value'] = $discount_val;
} else {
$discount_amt = 0;
$this->discounts[$rule['id']]['discounts']['type'] = '';
$this->discounts[$rule['id']]['discounts']['value'] = 0;
}
$this->discounts[$rule['id']]['taxable'] = $rule['inc_tax'];
$disc_act_val = (float)$discount_val;
$disc_act_type = $discount_typ;
$cart_total = $wdp_cart_totals - $discount_amt;
$cart_fee = $discount_amt;
} else if ($wdp_cart_quantity >= $max_range) {
$discount_amt = 0;
if ($discount_typ == 'percentage') {
$discount_amt = $wdp_cart_totals * ($discount_val / 100);
$this->discounts[$rule['id']]['discounts']['type'] = 'percentage';
$this->discounts[$rule['id']]['discounts']['value'] = $discount_val;
} else if ($discount_typ == 'fixed') {
$discount_amt = $discount_val;
$this->discounts[$rule['id']]['discounts']['type'] = 'fixed';
$this->discounts[$rule['id']]['discounts']['value'] = $discount_val;
} else {
$discount_amt = 0;
$this->discounts[$rule['id']]['discounts']['type'] = '';
$this->discounts[$rule['id']]['discounts']['value'] = 0;
}
$this->discounts[$rule['id']]['taxable'] = $rule['inc_tax'];
$disc_act_val = (float)$discount_val;
$disc_act_type = $discount_typ;
$cart_total = $wdp_cart_totals - $discount_amt;
$cart_fee = $discount_amt;
}
} // End Cart Calculations
} // End Foreach
if ($table_layout == 'horizontal') {
$tr_qn .= '';
$tr_pr .= '';
$table .= $tr_qn . $tr_pr . '