WooCommerce Extended Coupon Features - Version 3.2.7

Version Description

Release Date - 2021-02-13 * FIX: User restrictions on backend orders

Download this release

Release Info

Developer josk79
Plugin Icon 128x128 WooCommerce Extended Coupon Features
Version 3.2.7
Comparing to
See all releases

Code changes from version 3.2.6 to 3.2.7

assets/js/wjecf-admin.js CHANGED
@@ -28,7 +28,9 @@ jQuery( function( $ ) {
28
  update_wjecf_products_and();
29
  update_wjecf_categories_and();
30
 
31
- $( 'select#discount_type' ).on( 'change', update_discount_type ).change();
 
 
32
  };
33
 
34
  var update_wjecf_products_and = function() {
28
  update_wjecf_products_and();
29
  update_wjecf_categories_and();
30
 
31
+ $( 'select#discount_type' )
32
+ .on( 'change', update_discount_type )
33
+ .trigger( 'change' );
34
  };
35
 
36
  var update_wjecf_products_and = function() {
includes/class-wjecf-controller.php CHANGED
@@ -253,7 +253,7 @@ class WJECF_Controller {
253
  $this->validate_shipping_method( $coupon );
254
  $this->validate_excluded_shipping_method( $coupon );
255
  $this->validate_payment_method( $coupon );
256
- $this->validate_customer( $coupon );
257
 
258
  if ( $this->is_pro() ) {
259
  $this->validate_pro( $coupon, $wc_discounts );
@@ -629,21 +629,14 @@ class WJECF_Controller {
629
  * @param WC_Coupon $coupon
630
  * @return void
631
  */
632
- private function validate_customer( $coupon ) {
633
- //Since 2.6.3: only verify customer if on frontend
634
- if ( ! $this->is_request( 'frontend' ) ) {
635
- return;
636
- }
637
-
638
- //============================
639
- //Test restricted user ids and roles
640
  //NOTE: If both customer id and role restrictions are provided, the coupon matches if either the id or the role matches
641
  $coupon_customer_ids = $this->get_coupon_customer_ids( $coupon );
642
  $coupon_customer_roles = $this->get_coupon_customer_roles( $coupon );
643
  if ( ! empty( $coupon_customer_ids ) || ! empty( $coupon_customer_roles ) ) {
644
- $user = wp_get_current_user();
645
  //If both fail we invalidate. Otherwise it's ok
646
- if ( ! in_array( $user->ID, $coupon_customer_ids ) && ! array_intersect( $user->roles, $coupon_customer_roles ) ) {
647
  throw new Exception(
648
  /* translators: 1: coupon code */
649
  sprintf( __( 'Sorry, it seems the coupon "%s" is not yours.', 'woocommerce-jos-autocoupon' ), $coupon->get_code() ),
@@ -656,8 +649,8 @@ class WJECF_Controller {
656
  //Test excluded user roles
657
  $coupon_excluded_customer_roles = $this->get_coupon_excluded_customer_roles( $coupon );
658
  if ( ! empty( $coupon_excluded_customer_roles ) ) {
659
- $user = wp_get_current_user();
660
- if ( array_intersect( $user->roles, $coupon_excluded_customer_roles ) ) {
661
  throw new Exception(
662
  /* translators: 1: coupon code */
663
  sprintf( __( 'Sorry, it seems the coupon "%s" is not yours.', 'woocommerce-jos-autocoupon' ), $coupon->get_code() ),
253
  $this->validate_shipping_method( $coupon );
254
  $this->validate_excluded_shipping_method( $coupon );
255
  $this->validate_payment_method( $coupon );
256
+ $this->validate_customer( $coupon, $wc_discounts );
257
 
258
  if ( $this->is_pro() ) {
259
  $this->validate_pro( $coupon, $wc_discounts );
629
  * @param WC_Coupon $coupon
630
  * @return void
631
  */
632
+ private function validate_customer( $coupon, $wc_discounts ) {
 
 
 
 
 
 
 
633
  //NOTE: If both customer id and role restrictions are provided, the coupon matches if either the id or the role matches
634
  $coupon_customer_ids = $this->get_coupon_customer_ids( $coupon );
635
  $coupon_customer_roles = $this->get_coupon_customer_roles( $coupon );
636
  if ( ! empty( $coupon_customer_ids ) || ! empty( $coupon_customer_roles ) ) {
637
+ $user = WJECF_WC()->get_user( $wc_discounts );
638
  //If both fail we invalidate. Otherwise it's ok
639
+ if ( ! $user || ( ! in_array( $user->ID, $coupon_customer_ids ) && ! array_intersect( $user->roles, $coupon_customer_roles ) ) ) {
640
  throw new Exception(
641
  /* translators: 1: coupon code */
642
  sprintf( __( 'Sorry, it seems the coupon "%s" is not yours.', 'woocommerce-jos-autocoupon' ), $coupon->get_code() ),
649
  //Test excluded user roles
650
  $coupon_excluded_customer_roles = $this->get_coupon_excluded_customer_roles( $coupon );
651
  if ( ! empty( $coupon_excluded_customer_roles ) ) {
652
+ $user = WJECF_WC()->get_user( $wc_discounts );
653
+ if ( $user && array_intersect( $user->roles, $coupon_excluded_customer_roles ) ) {
654
  throw new Exception(
655
  /* translators: 1: coupon code */
656
  sprintf( __( 'Sorry, it seems the coupon "%s" is not yours.', 'woocommerce-jos-autocoupon' ), $coupon->get_code() ),
includes/class-wjecf-wc.php CHANGED
@@ -197,6 +197,21 @@ class WJECF_WC {
197
  return $coupon;
198
  }
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  //INSTANCE
201
 
202
  /**
197
  return $coupon;
198
  }
199
 
200
+ /**
201
+ * Returns the user of the order (in case of wp-admin) or the current user (in case of a frontend cart)
202
+ *
203
+ * @since 3.2.7
204
+ * @param WC_Discounts $wc_discounts
205
+ * @return WP_User|false
206
+ */
207
+ public function get_user( $wc_discounts = null ) {
208
+ if ( $wc_discounts->get_object() instanceof WC_Order ) {
209
+ return $wc_discounts->get_object()->get_user();
210
+ } else {
211
+ return wp_get_current_user();
212
+ }
213
+ }
214
+
215
  //INSTANCE
216
 
217
  /**
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: josk79
3
  Tags: woocommerce, coupons, discount
4
  Requires at least: 4.9
5
  Requires PHP: 5.6
6
- Tested up to: 5.6.0
7
- Stable tag: 3.2.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -103,8 +103,12 @@ On the settings page (Settings > WooCommerce Extended Coupon Features) check the
103
 
104
  == Changelog ==
105
 
 
 
 
 
106
  = 3.2.6 =
107
- *Release Data - 2021-01-16*
108
  * (PRO) FIX: Don't display free product selection when there are no items to choose from
109
  * FEATURE: 'Table Rate Shipping' by WooCommerce compatibility
110
 
3
  Tags: woocommerce, coupons, discount
4
  Requires at least: 4.9
5
  Requires PHP: 5.6
6
+ Tested up to: 5.6.2
7
+ Stable tag: 3.2.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
103
 
104
  == Changelog ==
105
 
106
+ = 3.2.7 =
107
+ *Release Date - 2021-02-13*
108
+ * FIX: User restrictions on backend orders
109
+
110
  = 3.2.6 =
111
+ *Release Date - 2021-01-16*
112
  * (PRO) FIX: Don't display free product selection when there are no items to choose from
113
  * FEATURE: 'Table Rate Shipping' by WooCommerce compatibility
114
 
woocommerce-jos-autocoupon.php CHANGED
@@ -3,12 +3,12 @@
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.2.6
7
  * Text Domain: woocommerce-jos-autocoupon
8
  * Author: Soft79
9
  * License: GPL2
10
  * WC requires at least: 3.0.0
11
- * WC tested up to: 4.9.0
12
  */
13
 
14
  if ( ! defined( 'ABSPATH' ) ) {
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  }
17
 
18
  if ( ! defined( 'WJECF_VERSION' ) ) {
19
- define( 'WJECF_VERSION', '3.2.6' );
20
  }
21
 
22
  // NOTE: This file must be compatible with old PHP versions. All other files can be PHP 5.6+ .
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.2.7
7
  * Text Domain: woocommerce-jos-autocoupon
8
  * Author: Soft79
9
  * License: GPL2
10
  * WC requires at least: 3.0.0
11
+ * WC tested up to: 5.0.0
12
  */
13
 
14
  if ( ! defined( 'ABSPATH' ) ) {
16
  }
17
 
18
  if ( ! defined( 'WJECF_VERSION' ) ) {
19
+ define( 'WJECF_VERSION', '3.2.7' );
20
  }
21
 
22
  // NOTE: This file must be compatible with old PHP versions. All other files can be PHP 5.6+ .