From 943c119d3b522847f624685c4be31e09047e3554 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 21 Nov 2011 17:11:44 +0000 Subject: [PATCH] % coupons and allowed each to be removed via a link --- classes/cart.class.php | 23 +++++++++++++++++++---- shortcodes/shortcode-cart.php | 2 +- woocommerce_template_functions.php | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/classes/cart.class.php b/classes/cart.class.php index 77e6a9ee352..6cfe82ddd4d 100644 --- a/classes/cart.class.php +++ b/classes/cart.class.php @@ -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; } } \ No newline at end of file diff --git a/shortcodes/shortcode-cart.php b/shortcodes/shortcode-cart.php index 6db4cc4f975..3d4cf431828 100644 --- a/shortcodes/shortcode-cart.php +++ b/shortcodes/shortcode-cart.php @@ -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(); diff --git a/woocommerce_template_functions.php b/woocommerce_template_functions.php index 89a6d3cc9df..07a0a83b2f2 100644 --- a/woocommerce_template_functions.php +++ b/woocommerce_template_functions.php @@ -786,7 +786,7 @@ if (!function_exists('woocommerce_cart_totals')) { cart->get_discounts_after_tax()) : ?> - + -cart->get_discounts_after_tax(); ?>