Version Description
- Don't apply coupon if the discount is 0.00
- Allow applying multiple coupons via an url using *?apply_coupon=coupon_code1,coupon_code2
Download this release
Release Info
Developer | josk79 |
Plugin | WooCommerce Extended Coupon Features |
Version | 1.1.3 |
Comparing to | |
See all releases |
Code changes from version 1.1.2 to 1.1.3
- readme.txt +4 -1
- woocommerce-jos-autocoupon.php +35 -4
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQ
|
|
4 |
Tags: woocommerce, coupons, discount
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 4.0
|
7 |
-
Stable tag: 1.1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -69,6 +69,9 @@ Sure! [This](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQ
|
|
69 |
1. Simply use the WooCommerce Coupons menu to make a coupon an "auto coupon".
|
70 |
|
71 |
== Changelog ==
|
|
|
|
|
|
|
72 |
|
73 |
= 1.1.2 =
|
74 |
* Minor change to make the plugin compatible with WooCommerce 2.3.1
|
4 |
Tags: woocommerce, coupons, discount
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 4.0
|
7 |
+
Stable tag: 1.1.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
69 |
1. Simply use the WooCommerce Coupons menu to make a coupon an "auto coupon".
|
70 |
|
71 |
== Changelog ==
|
72 |
+
= 1.1.3 =
|
73 |
+
* Don't apply coupon if the discount is 0.00
|
74 |
+
* Allow applying multiple coupons via an url using *?apply_coupon=coupon_code1,coupon_code2
|
75 |
|
76 |
= 1.1.2 =
|
77 |
* Minor change to make the plugin compatible with WooCommerce 2.3.1
|
woocommerce-jos-autocoupon.php
CHANGED
@@ -3,13 +3,16 @@
|
|
3 |
* Plugin Name: WooCommerce auto added coupons
|
4 |
* Plugin URI: http://wordpress.org/plugins/woocommerce-auto-added-coupons
|
5 |
* Description: Allow discounts to be automatically added to the cart when it's restrictions are met. Allow applying coupons via an url.
|
6 |
-
* Version: 1.1.
|
7 |
* Author: Jos Koenis
|
8 |
* License: GPL2
|
9 |
*/
|
10 |
|
11 |
/*
|
12 |
Change history:
|
|
|
|
|
|
|
13 |
1.1.2:
|
14 |
- Minor change to make the plugin compatible with WooCommerce 2.3.1
|
15 |
- Loop through coupons in ascending order
|
@@ -75,8 +78,12 @@ class WC_Jos_AutoCoupon_Controller{
|
|
75 |
*/
|
76 |
public function coupon_by_url() {
|
77 |
if (isset($_GET['apply_coupon'])) {
|
|
|
|
|
78 |
global $woocommerce;
|
79 |
-
|
|
|
|
|
80 |
}
|
81 |
}
|
82 |
|
@@ -131,7 +138,7 @@ class WC_Jos_AutoCoupon_Controller{
|
|
131 |
foreach ( $this->get_all_auto_coupons() as $coupon_code ) {
|
132 |
if ( ! $woocommerce->cart->has_discount( $coupon_code ) ) {
|
133 |
$coupon = new WC_Coupon($coupon_code);
|
134 |
-
if ( $
|
135 |
$woocommerce->cart->add_discount( $coupon_code );
|
136 |
$this->overwrite_success_message( $coupon );
|
137 |
}
|
@@ -139,6 +146,30 @@ class WC_Jos_AutoCoupon_Controller{
|
|
139 |
}
|
140 |
}
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
/**
|
143 |
* Remove unmatched autocoupons. No message will be shown.
|
144 |
* NOTE: This function must be called before WooCommerce removes the coupon, to inhibit WooCommerces "coupon not valid"-message!
|
@@ -150,7 +181,7 @@ class WC_Jos_AutoCoupon_Controller{
|
|
150 |
foreach ( $this->get_all_auto_coupons() as $coupon_code ) {
|
151 |
if ( $woocommerce->cart->has_discount( $coupon_code ) ) {
|
152 |
$coupon = new WC_Coupon($coupon_code);
|
153 |
-
if ( ! $
|
154 |
WC()->cart->remove_coupon( $coupon_code );
|
155 |
}
|
156 |
}
|
3 |
* Plugin Name: WooCommerce auto added coupons
|
4 |
* Plugin URI: http://wordpress.org/plugins/woocommerce-auto-added-coupons
|
5 |
* Description: Allow discounts to be automatically added to the cart when it's restrictions are met. Allow applying coupons via an url.
|
6 |
+
* Version: 1.1.3
|
7 |
* Author: Jos Koenis
|
8 |
* License: GPL2
|
9 |
*/
|
10 |
|
11 |
/*
|
12 |
Change history:
|
13 |
+
1.1.3:
|
14 |
+
- Don't apply an auto coupon if the discount is 0.00
|
15 |
+
- Allow applying multiple coupons via an url using *?apply_coupon=coupon_code1,coupon_code2
|
16 |
1.1.2:
|
17 |
- Minor change to make the plugin compatible with WooCommerce 2.3.1
|
18 |
- Loop through coupons in ascending order
|
78 |
*/
|
79 |
public function coupon_by_url() {
|
80 |
if (isset($_GET['apply_coupon'])) {
|
81 |
+
$split = explode( ",", $_GET['apply_coupon'] );
|
82 |
+
|
83 |
global $woocommerce;
|
84 |
+
foreach ( $split as $coupon_code ) {
|
85 |
+
$woocommerce->cart->add_discount( $coupon_code );
|
86 |
+
}
|
87 |
}
|
88 |
}
|
89 |
|
138 |
foreach ( $this->get_all_auto_coupons() as $coupon_code ) {
|
139 |
if ( ! $woocommerce->cart->has_discount( $coupon_code ) ) {
|
140 |
$coupon = new WC_Coupon($coupon_code);
|
141 |
+
if ( $this->coupon_can_be_applied($coupon) ) {
|
142 |
$woocommerce->cart->add_discount( $coupon_code );
|
143 |
$this->overwrite_success_message( $coupon );
|
144 |
}
|
146 |
}
|
147 |
}
|
148 |
|
149 |
+
/**
|
150 |
+
* Test whether the coupon is valid and has a discount > 0
|
151 |
+
* @return bool
|
152 |
+
*/
|
153 |
+
function coupon_can_be_applied($coupon) {
|
154 |
+
global $woocommerce;
|
155 |
+
|
156 |
+
if ( ! $coupon->is_valid() ) {
|
157 |
+
return false;
|
158 |
+
} else if ( $coupon->individual_use == 'yes' && count( $woocommerce->cart->applied_coupons ) != 0 ) {
|
159 |
+
return false;
|
160 |
+
} else {
|
161 |
+
//Test whether discount > 0
|
162 |
+
foreach ( $woocommerce->cart->get_cart() as $cart_item) {
|
163 |
+
if ( $coupon->is_valid_for_cart() || $coupon->is_valid_for_product( $cart_item['data'], $cart_item ) ) {
|
164 |
+
if ( $coupon->get_discount_amount( $cart_item['data']->price, $cart_item ) > 0 ) {
|
165 |
+
return true;
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
}
|
170 |
+
return false;
|
171 |
+
}
|
172 |
+
|
173 |
/**
|
174 |
* Remove unmatched autocoupons. No message will be shown.
|
175 |
* NOTE: This function must be called before WooCommerce removes the coupon, to inhibit WooCommerces "coupon not valid"-message!
|
181 |
foreach ( $this->get_all_auto_coupons() as $coupon_code ) {
|
182 |
if ( $woocommerce->cart->has_discount( $coupon_code ) ) {
|
183 |
$coupon = new WC_Coupon($coupon_code);
|
184 |
+
if ( ! $this->coupon_can_be_applied($coupon) ) {
|
185 |
WC()->cart->remove_coupon( $coupon_code );
|
186 |
}
|
187 |
}
|