Version Description
Release Date - 2018-09-03 * FIX: Email restrictions compatibility with WooCommerce versions prior to 3.4 * FIX: Individual use conflict * FIX: (FREE) Missing debug template
Download this release
Release Info
Developer | josk79 |
Plugin | WooCommerce Extended Coupon Features |
Version | 3.0.2 |
Comparing to | |
See all releases |
Code changes from version 3.0.1 to 3.0.2
- includes/class-wjecf-controller.php +15 -44
- includes/plugins/WJECF_Autocoupon.php +11 -52
- includes/plugins/WJECF_Debug.php +31 -2
- readme.txt +10 -11
- woocommerce-jos-autocoupon.php +3 -3
includes/class-wjecf-controller.php
CHANGED
@@ -803,30 +803,34 @@ class WJECF_Controller {
|
|
803 |
/**
|
804 |
* Return an array of WC_Coupons with coupons that shouldn't cause individual use conflicts.
|
805 |
*
|
806 |
-
* @param WC_Coupon[] $
|
807 |
* @return WC_Coupon[]
|
808 |
*/
|
809 |
-
public function coupon_combination_filter( $
|
810 |
|
811 |
-
$
|
812 |
|
813 |
//Contains coupon codes that are already in cart or pending in the filtered-array
|
814 |
$applied_coupon_codes = WC()->cart->get_applied_coupons();
|
815 |
|
816 |
-
foreach ( $
|
817 |
-
if ( $the_coupon->get_individual_use() ) {
|
818 |
//Only allow a new automatic individual use coupon if it doesn't remove coupons from the cart.
|
819 |
$coupons_to_keep = apply_filters( 'woocommerce_apply_individual_use_coupon', array(), $the_coupon, $applied_coupon_codes );
|
820 |
if ( count( $applied_coupon_codes ) != count( array_intersect( $applied_coupon_codes, $coupons_to_keep ) ) ) {
|
821 |
-
continue;
|
822 |
}
|
823 |
}
|
824 |
|
825 |
//Check to see if an individual use coupon is already in the cart.
|
826 |
foreach ( $applied_coupon_codes as $code ) {
|
|
|
|
|
|
|
|
|
827 |
$coupon = new WC_Coupon( $code );
|
828 |
if ( $coupon->get_individual_use() && false === apply_filters( 'woocommerce_apply_with_individual_use_coupon', false, $the_coupon, $coupon, $applied_coupon_codes ) ) {
|
829 |
-
continue 2;
|
830 |
}
|
831 |
}
|
832 |
|
@@ -839,14 +843,14 @@ class WJECF_Controller {
|
|
839 |
* @param string[] $applied_coupon_codes Codes of the coupons already in the cart
|
840 |
*/
|
841 |
if ( ! apply_filters( 'wjecf_apply_with_other_coupons', true, $the_coupon, $applied_coupon_codes ) ) {
|
842 |
-
continue;
|
843 |
}
|
844 |
|
845 |
-
$applied_coupon_codes[]
|
846 |
-
$
|
847 |
}
|
848 |
|
849 |
-
return $
|
850 |
}
|
851 |
|
852 |
/**
|
@@ -953,39 +957,6 @@ class WJECF_Controller {
|
|
953 |
}
|
954 |
}
|
955 |
|
956 |
-
/**
|
957 |
-
* Get overwritable template filename
|
958 |
-
*
|
959 |
-
* Template can be overwritten in wp-content/themes/YOUR_THEME/woocommerce-auto-added-coupons/
|
960 |
-
* @param string $template_name
|
961 |
-
* @return string Template filename
|
962 |
-
*/
|
963 |
-
public function get_template_filename( $template_name ) {
|
964 |
-
$template_path = 'woocommerce-auto-added-coupons';
|
965 |
-
|
966 |
-
//Get template overwritten file
|
967 |
-
$template = locate_template( trailingslashit( $template_path ) . $template_name );
|
968 |
-
|
969 |
-
// Get default template
|
970 |
-
if ( ! $template ) {
|
971 |
-
$plugin_template_path = plugin_dir_path( dirname( __FILE__ ) ) . 'templates/';
|
972 |
-
$template = $plugin_template_path . $template_name;
|
973 |
-
}
|
974 |
-
|
975 |
-
return $template;
|
976 |
-
}
|
977 |
-
|
978 |
-
/**
|
979 |
-
* Include a template file, either from this plugins directory or overwritten in the themes directory
|
980 |
-
* @param type $template_name
|
981 |
-
* @return type
|
982 |
-
*/
|
983 |
-
public function include_template( $template_name, $variables = array() ) {
|
984 |
-
/* phpcs:ignore */
|
985 |
-
extract( $variables );
|
986 |
-
include( $this->get_template_filename( $template_name ) );
|
987 |
-
}
|
988 |
-
|
989 |
// ========================
|
990 |
// INFO ABOUT WJECF PLUGIN
|
991 |
// ========================
|
803 |
/**
|
804 |
* Return an array of WC_Coupons with coupons that shouldn't cause individual use conflicts.
|
805 |
*
|
806 |
+
* @param WC_Coupon[] $coupons
|
807 |
* @return WC_Coupon[]
|
808 |
*/
|
809 |
+
public function coupon_combination_filter( $coupons ) {
|
810 |
|
811 |
+
$filtered_coupons = array();
|
812 |
|
813 |
//Contains coupon codes that are already in cart or pending in the filtered-array
|
814 |
$applied_coupon_codes = WC()->cart->get_applied_coupons();
|
815 |
|
816 |
+
foreach ( $coupons as $the_coupon ) {
|
817 |
+
if ( $the_coupon->get_individual_use() && ! in_array( $the_coupon->get_code(), $applied_coupon_codes ) ) {
|
818 |
//Only allow a new automatic individual use coupon if it doesn't remove coupons from the cart.
|
819 |
$coupons_to_keep = apply_filters( 'woocommerce_apply_individual_use_coupon', array(), $the_coupon, $applied_coupon_codes );
|
820 |
if ( count( $applied_coupon_codes ) != count( array_intersect( $applied_coupon_codes, $coupons_to_keep ) ) ) {
|
821 |
+
continue; //skip coupon.
|
822 |
}
|
823 |
}
|
824 |
|
825 |
//Check to see if an individual use coupon is already in the cart.
|
826 |
foreach ( $applied_coupon_codes as $code ) {
|
827 |
+
if ( $code === $the_coupon->get_code() ) {
|
828 |
+
//Dont compare the coupon with itself
|
829 |
+
continue;
|
830 |
+
}
|
831 |
$coupon = new WC_Coupon( $code );
|
832 |
if ( $coupon->get_individual_use() && false === apply_filters( 'woocommerce_apply_with_individual_use_coupon', false, $the_coupon, $coupon, $applied_coupon_codes ) ) {
|
833 |
+
continue 2; //skip coupon.
|
834 |
}
|
835 |
}
|
836 |
|
843 |
* @param string[] $applied_coupon_codes Codes of the coupons already in the cart
|
844 |
*/
|
845 |
if ( ! apply_filters( 'wjecf_apply_with_other_coupons', true, $the_coupon, $applied_coupon_codes ) ) {
|
846 |
+
continue; //skip coupon.
|
847 |
}
|
848 |
|
849 |
+
$applied_coupon_codes[] = $the_coupon->get_code();
|
850 |
+
$filtered_coupons[] = $the_coupon;
|
851 |
}
|
852 |
|
853 |
+
return $filtered_coupons;
|
854 |
}
|
855 |
|
856 |
/**
|
957 |
}
|
958 |
}
|
959 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
960 |
// ========================
|
961 |
// INFO ABOUT WJECF PLUGIN
|
962 |
// ========================
|
includes/plugins/WJECF_Autocoupon.php
CHANGED
@@ -856,57 +856,7 @@ if ( defined( 'ABSPATH' ) && ! class_exists( 'WJECF_Autocoupon' ) ) {
|
|
856 |
$valid_auto_coupons[] = $coupon;
|
857 |
}
|
858 |
|
859 |
-
return
|
860 |
-
}
|
861 |
-
|
862 |
-
/**
|
863 |
-
* Return an array of WC_Coupons with coupons that shouldn't cause individual use conflicts.
|
864 |
-
*
|
865 |
-
* @param WC_Coupon[] $coupons_to_apply
|
866 |
-
* @return WC_Coupon[]
|
867 |
-
*/
|
868 |
-
public function coupon_combination_filter( $coupons_to_apply ) {
|
869 |
-
|
870 |
-
$filtered_coupons_to_apply = array();
|
871 |
-
|
872 |
-
//Contains coupon codes that are already in cart or pending in the filtered-array
|
873 |
-
$applied_coupon_codes = WC()->cart->get_applied_coupons();
|
874 |
-
|
875 |
-
foreach ( $coupons_to_apply as $the_coupon ) {
|
876 |
-
if ( $the_coupon->get_individual_use() ) {
|
877 |
-
//Only allow a new automatic individual use coupon if it doesn't remove coupons from the cart.
|
878 |
-
$coupons_to_keep = apply_filters( 'woocommerce_apply_individual_use_coupon', array(), $the_coupon, $applied_coupon_codes );
|
879 |
-
if ( count( $applied_coupon_codes ) != count( array_intersect( $applied_coupon_codes, $coupons_to_keep ) ) ) {
|
880 |
-
continue;
|
881 |
-
}
|
882 |
-
}
|
883 |
-
|
884 |
-
//Check to see if an individual use coupon is already in the cart.
|
885 |
-
foreach ( $applied_coupon_codes as $code ) {
|
886 |
-
$coupon = new WC_Coupon( $code );
|
887 |
-
if ( $coupon->get_individual_use() && false === apply_filters( 'woocommerce_apply_with_individual_use_coupon', false, $the_coupon, $coupon, $applied_coupon_codes ) ) {
|
888 |
-
continue 2;
|
889 |
-
}
|
890 |
-
}
|
891 |
-
|
892 |
-
/**
|
893 |
-
* Filter to disallow certain coupon combinations to be auto-applied together.
|
894 |
-
*
|
895 |
-
* @since 3.0.0
|
896 |
-
*
|
897 |
-
* @param bool $apply Apply the coupon?
|
898 |
-
* @param WC_Coupon $the_coupon Coupon to apply
|
899 |
-
* @param string[] $applied_coupon_codes Codes of the coupons already in the cart
|
900 |
-
*/
|
901 |
-
if ( ! apply_filters( 'wjecf_apply_with_other_coupons', true, $the_coupon, $applied_coupon_codes ) ) {
|
902 |
-
continue;
|
903 |
-
}
|
904 |
-
|
905 |
-
$applied_coupon_codes[] = $the_coupon->get_code();
|
906 |
-
$filtered_coupons_to_apply[] = $the_coupon;
|
907 |
-
}
|
908 |
-
|
909 |
-
return $filtered_coupons_to_apply;
|
910 |
}
|
911 |
|
912 |
/**
|
@@ -935,7 +885,7 @@ if ( defined( 'ABSPATH' ) && ! class_exists( 'WJECF_Autocoupon' ) ) {
|
|
935 |
if ( $can_be_applied ) {
|
936 |
// Limit to defined email addresses.
|
937 |
$restrictions = $coupon->get_email_restrictions();
|
938 |
-
if ( is_array( $restrictions ) && 0 < count( $restrictions ) && ! $
|
939 |
$can_be_applied = false;
|
940 |
}
|
941 |
$this->log(
|
@@ -1002,6 +952,15 @@ if ( defined( 'ABSPATH' ) && ! class_exists( 'WJECF_Autocoupon' ) ) {
|
|
1002 |
return apply_filters( 'wjecf_coupon_can_be_applied', $can_be_applied, $coupon );
|
1003 |
}
|
1004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1005 |
/**
|
1006 |
* Does the coupon have a value? (autocoupon should not be applied if it has no value)
|
1007 |
* @param WC_Coupon $coupon The coupon data
|
856 |
$valid_auto_coupons[] = $coupon;
|
857 |
}
|
858 |
|
859 |
+
return WJECF()->coupon_combination_filter( $valid_auto_coupons );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
860 |
}
|
861 |
|
862 |
/**
|
885 |
if ( $can_be_applied ) {
|
886 |
// Limit to defined email addresses.
|
887 |
$restrictions = $coupon->get_email_restrictions();
|
888 |
+
if ( is_array( $restrictions ) && 0 < count( $restrictions ) && ! $this->is_coupon_emails_allowed( $check_emails, $restrictions, $cart ) ) {
|
889 |
$can_be_applied = false;
|
890 |
}
|
891 |
$this->log(
|
952 |
return apply_filters( 'wjecf_coupon_can_be_applied', $can_be_applied, $coupon );
|
953 |
}
|
954 |
|
955 |
+
private function is_coupon_emails_allowed( $check_emails, $restrictions, $cart ) {
|
956 |
+
if ( is_callable( array( $cart, 'is_coupon_emails_allowed' ) ) ) {
|
957 |
+
//Requires WC 3.4+
|
958 |
+
return $cart->is_coupon_emails_allowed( $check_emails, $restrictions );
|
959 |
+
}
|
960 |
+
|
961 |
+
return sizeof( array_intersect( $check_emails, $restrictions ) ) > 0;
|
962 |
+
}
|
963 |
+
|
964 |
/**
|
965 |
* Does the coupon have a value? (autocoupon should not be applied if it has no value)
|
966 |
* @param WC_Coupon $coupon The coupon data
|
includes/plugins/WJECF_Debug.php
CHANGED
@@ -77,7 +77,37 @@ if ( defined( 'ABSPATH' ) && ! class_exists( 'WJECF_Debug' ) ) {
|
|
77 |
$this->log( 'debug', 'Current coupons in cart: ' . implode( ', ', WC()->cart->applied_coupons ) );
|
78 |
|
79 |
if ( $this->log_output ) {
|
80 |
-
WJECF()->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
}
|
83 |
|
@@ -139,7 +169,6 @@ if ( defined( 'ABSPATH' ) && ! class_exists( 'WJECF_Debug' ) ) {
|
|
139 |
return WJECF()->get_option( 'debug_mode' );
|
140 |
}
|
141 |
|
142 |
-
|
143 |
// ========================
|
144 |
// LOGGING
|
145 |
// ========================
|
77 |
$this->log( 'debug', 'Current coupons in cart: ' . implode( ', ', WC()->cart->applied_coupons ) );
|
78 |
|
79 |
if ( $this->log_output ) {
|
80 |
+
if ( WJECF()->is_pro() ) {
|
81 |
+
WJECF()->include_template( 'debug/log.php', array( 'log' => $this->log_output ) );
|
82 |
+
} else {
|
83 |
+
//FREE version has no templating.
|
84 |
+
$log = $this->log_output;
|
85 |
+
?>
|
86 |
+
<style>
|
87 |
+
.soft79_wjecf_log { font-size:11px; }
|
88 |
+
</style>
|
89 |
+
<table class='soft79_wjecf_log'>
|
90 |
+
<tr>
|
91 |
+
<th>Time</th>
|
92 |
+
<th>Level</th>
|
93 |
+
<th>Filter / Action</th>
|
94 |
+
<th>Function</th>
|
95 |
+
<th>Message</th>
|
96 |
+
</tr>
|
97 |
+
<?php
|
98 |
+
foreach ( $log as $log_item ) {
|
99 |
+
echo '<tr>';
|
100 |
+
echo '<td>' . date( 'H:i:s', $log_item['time'] ) . '</td>';
|
101 |
+
echo '<td>' . esc_html( $log_item['level'] ) . '</td>';
|
102 |
+
echo '<td>' . esc_html( $log_item['filter'] ) . '</td>';
|
103 |
+
echo '<td>' . esc_html( $log_item['class'] . '::' . $log_item['function'] ) . '</td>';
|
104 |
+
echo '<td>' . esc_html( $log_item['message'] ) . '</td>';
|
105 |
+
echo "</tr>\n";
|
106 |
+
}
|
107 |
+
?>
|
108 |
+
</table>
|
109 |
+
<?php
|
110 |
+
}
|
111 |
}
|
112 |
}
|
113 |
|
169 |
return WJECF()->get_option( 'debug_mode' );
|
170 |
}
|
171 |
|
|
|
172 |
// ========================
|
173 |
// LOGGING
|
174 |
// ========================
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: woocommerce, coupons, discount
|
|
4 |
Requires at least: 4.8
|
5 |
Requires PHP: 5.4
|
6 |
Tested up to: 4.9.8
|
7 |
-
Stable tag: 3.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -85,19 +85,12 @@ An empty cart can not have any coupons. The PRO version of this plugin has a wor
|
|
85 |
|
86 |
= The cart is not updated after changing the payment method =
|
87 |
|
88 |
-
|
89 |
-
You can do this by overriding woocommerce/templates/checkout/payment.php (place it in your_template/woocommerce/checkout/).
|
90 |
|
91 |
= The cart is not updated after changing the billing email address =
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
//Update the cart preview when the billing email is changed by the customer
|
96 |
-
add_filter( 'woocommerce_checkout_fields', function( $checkout_fields ) {
|
97 |
-
$checkout_fields['billing']['billing_email']['class'][] = 'update_totals_on_change';
|
98 |
-
return $checkout_fields;
|
99 |
-
} );
|
100 |
-
`
|
101 |
|
102 |
== Screenshots ==
|
103 |
|
@@ -108,6 +101,12 @@ add_filter( 'woocommerce_checkout_fields', function( $checkout_fields ) {
|
|
108 |
|
109 |
== Changelog ==
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
= 3.0.1 =
|
112 |
*Release Date - 2018-09-02*
|
113 |
* FIX: Fatal error in FREE version of the plugin
|
4 |
Requires at least: 4.8
|
5 |
Requires PHP: 5.4
|
6 |
Tested up to: 4.9.8
|
7 |
+
Stable tag: 3.0.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
85 |
|
86 |
= The cart is not updated after changing the payment method =
|
87 |
|
88 |
+
On the settings page (Settings > WooCommerce Extended Coupon Features) check the box *Update order review on payment method change*.
|
|
|
89 |
|
90 |
= The cart is not updated after changing the billing email address =
|
91 |
|
92 |
+
On the settings page (Settings > WooCommerce Extended Coupon Features) check the box *Update order review on billing email change*.
|
93 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
== Screenshots ==
|
96 |
|
101 |
|
102 |
== Changelog ==
|
103 |
|
104 |
+
= 3.0.2 =
|
105 |
+
*Release Date - 2018-09-03*
|
106 |
+
* FIX: Email restrictions compatibility with WooCommerce versions prior to 3.4
|
107 |
+
* FIX: Individual use conflict
|
108 |
+
* FIX: (FREE) Missing debug template
|
109 |
+
|
110 |
= 3.0.1 =
|
111 |
*Release Date - 2018-09-02*
|
112 |
* FIX: Fatal error in FREE version of the plugin
|
woocommerce-jos-autocoupon.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WooCommerce Extended Coupon Features FREE
|
4 |
* Plugin URI: http://www.soft79.nl
|
5 |
* Description: Additional functionality for WooCommerce Coupons.
|
6 |
-
* Version: 3.0.
|
7 |
* Author: Soft79
|
8 |
* License: GPL2
|
9 |
* WC requires at least: 3.0.0
|
@@ -15,10 +15,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
15 |
}
|
16 |
|
17 |
if ( ! defined( 'WJECF_VERSION' ) ) {
|
18 |
-
define( 'WJECF_VERSION', '3.0.
|
19 |
}
|
20 |
|
21 |
-
// NOTE: This file must be compatible with old PHP versions. All other files can be PHP 5.
|
22 |
if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
23 |
// We must define wjecf_load_plugin_textdomain() so that versions prior to 3.0 detect this plugin instance.
|
24 |
function wjecf_load_plugin_textdomain() {
|
3 |
* Plugin Name: WooCommerce Extended Coupon Features FREE
|
4 |
* Plugin URI: http://www.soft79.nl
|
5 |
* Description: Additional functionality for WooCommerce Coupons.
|
6 |
+
* Version: 3.0.2
|
7 |
* Author: Soft79
|
8 |
* License: GPL2
|
9 |
* WC requires at least: 3.0.0
|
15 |
}
|
16 |
|
17 |
if ( ! defined( 'WJECF_VERSION' ) ) {
|
18 |
+
define( 'WJECF_VERSION', '3.0.2' );
|
19 |
}
|
20 |
|
21 |
+
// NOTE: This file must be compatible with old PHP versions. All other files can be PHP 5.4+ .
|
22 |
if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
23 |
// We must define wjecf_load_plugin_textdomain() so that versions prior to 3.0 detect this plugin instance.
|
24 |
function wjecf_load_plugin_textdomain() {
|