% coupons and allowed each to be removed via a link
This commit is contained in:
parent
cf248ff114
commit
943c119d3b
|
@ -500,7 +500,7 @@ class woocommerce_cart {
|
|||
|
||||
case "percent" :
|
||||
|
||||
$percent_discount = round( ( ($this->cart_contents_total + $this->tax_total) / 100) * $coupon->amount , 2);
|
||||
$percent_discount = (round( $this->cart_contents_total + $this->tax_total , 2) / 100 ) * $coupon->amount;
|
||||
|
||||
$this->discount_total = $this->discount_total + $percent_discount;
|
||||
|
||||
|
@ -1080,9 +1080,24 @@ class woocommerce_cart {
|
|||
/**
|
||||
* gets the array of applied coupon codes
|
||||
*/
|
||||
function remove_coupons() {
|
||||
unset($_SESSION['coupons']);
|
||||
$this->applied_coupons = array();
|
||||
function remove_coupons( $type = 0 ) {
|
||||
|
||||
if ($type == 1) :
|
||||
if ($this->applied_coupons) foreach ($this->applied_coupons as $index => $code) :
|
||||
$coupon = &new woocommerce_coupon( $code );
|
||||
if ( $coupon->apply_before_tax() ) unset($this->applied_coupons[$index]);
|
||||
endforeach;
|
||||
$_SESSION['coupons'] = $this->applied_coupons;
|
||||
elseif ($type == 2) :
|
||||
if ($this->applied_coupons) foreach ($this->applied_coupons as $index => $code) :
|
||||
$coupon = &new woocommerce_coupon( $code );
|
||||
if ( !$coupon->apply_before_tax() ) unset($this->applied_coupons[$index]);
|
||||
endforeach;
|
||||
$_SESSION['coupons'] = $this->applied_coupons;
|
||||
else :
|
||||
unset($_SESSION['coupons']);
|
||||
$this->applied_coupons = array();
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ function woocommerce_cart( $atts ) {
|
|||
// Remvoe Discount Codes
|
||||
elseif (isset($_GET['remove_discounts'])) :
|
||||
|
||||
$woocommerce->cart->remove_coupons();
|
||||
$woocommerce->cart->remove_coupons( $_GET['remove_discounts'] );
|
||||
|
||||
// Re-calc price
|
||||
$woocommerce->cart->calculate_totals();
|
||||
|
|
|
@ -786,7 +786,7 @@ if (!function_exists('woocommerce_cart_totals')) {
|
|||
</tr><?php endif; ?>
|
||||
|
||||
<?php if ($woocommerce->cart->get_discounts_after_tax()) : ?><tr class="discount">
|
||||
<th><?php _e('Discount', 'woothemes'); ?> <?php _e('[Remove]', 'woothemes'); ?></th>
|
||||
<th><?php _e('Discount', 'woothemes'); ?> <a href="<?php echo add_query_arg('remove_discounts', '2') ?>"><?php _e('[Remove]', 'woothemes'); ?></a></th>
|
||||
<td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
|
||||
</tr><?php endif; ?>
|
||||
|
||||
|
|
Loading…
Reference in New Issue