Version Description
- FIX: Combining add-to-cart and apply_coupon in a single querystring
Download this release
Release Info
Developer | josk79 |
Plugin | WooCommerce Extended Coupon Features |
Version | 2.3.7.4 |
Comparing to | |
See all releases |
Code changes from version 2.3.7 to 2.3.7.4
- includes/admin/wjecf-admin.php +14 -54
- includes/wjecf-autocoupon.php +5 -10
- includes/wjecf-controller.php +9 -74
- includes/wjecf-wc.php +178 -0
- readme.txt +16 -3
- woocommerce-jos-autocoupon.php +9 -2
includes/admin/wjecf-admin.php
CHANGED
@@ -19,7 +19,7 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
19 |
public function init_admin_hook() {
|
20 |
add_action( 'admin_notices', array( $this, 'admin_notices'));
|
21 |
|
22 |
-
if ( !
|
23 |
$this->enqueue_notice( '<p>' .
|
24 |
__( '<strong>WooCommerce Extended Coupon Features:</strong> You are using an old version of WooCommerce. Updating of WooCommerce is recommended as using an outdated version might cause unexpected behaviour in combination with modern plugins.' )
|
25 |
. '</p>', 'notice-warning' );
|
@@ -293,7 +293,8 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
293 |
echo '<option value="' . esc_attr( $shipping_method->id ) . '"' . selected( in_array( $shipping_method->id, $coupon_shipping_method_ids ), true, false ) . '>' . esc_html( $shipping_method->method_title ) . '</option>';
|
294 |
}
|
295 |
?>
|
296 |
-
</select
|
|
|
297 |
<?php
|
298 |
|
299 |
//=============================
|
@@ -311,7 +312,8 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
311 |
}
|
312 |
}
|
313 |
?>
|
314 |
-
</select
|
|
|
315 |
<?php
|
316 |
}
|
317 |
|
@@ -338,9 +340,9 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
338 |
}
|
339 |
|
340 |
echo esc_attr( json_encode( $json_ids ) );
|
341 |
-
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" />
|
342 |
-
|
343 |
-
|
344 |
<?php
|
345 |
|
346 |
//=============================
|
@@ -360,9 +362,9 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
360 |
. esc_html( $role_name ) . '</option>';
|
361 |
}
|
362 |
?>
|
363 |
-
</select>
|
364 |
-
|
365 |
-
|
366 |
<?php
|
367 |
|
368 |
//=============================
|
@@ -381,9 +383,9 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
381 |
. esc_html( $role_name ) . '</option>';
|
382 |
}
|
383 |
?>
|
384 |
-
</select>
|
385 |
-
|
386 |
-
|
387 |
<?php
|
388 |
}
|
389 |
|
@@ -514,48 +516,6 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
514 |
<?php
|
515 |
}
|
516 |
|
517 |
-
public function render_admin_product_selector( $dom_id, $field_name, $selected_ids, $placeholder = null ) {
|
518 |
-
$product_key_values = array();
|
519 |
-
foreach ( $selected_ids as $product_id ) {
|
520 |
-
$product = wc_get_product( $product_id );
|
521 |
-
if ( is_object( $product ) ) {
|
522 |
-
$product_key_values[ esc_attr( $product_id ) ] = wp_kses_post( $product->get_formatted_name() );
|
523 |
-
}
|
524 |
-
}
|
525 |
-
|
526 |
-
if ( $placeholder === null ) $placeholder = __( 'Search for a product…', 'woocommerce' );
|
527 |
-
|
528 |
-
//In WooCommerce version 2.3.0 chosen was replaced by select2
|
529 |
-
$use_select2 = WJECF()->check_woocommerce_version('2.3.0');
|
530 |
-
if ($use_select2) {
|
531 |
-
$this->render_admin_select2_product_selector( $dom_id, $field_name, $product_key_values, $placeholder );
|
532 |
-
} else {
|
533 |
-
$this->render_admin_chosen_product_selector( $dom_id, $field_name, $product_key_values, $placeholder );
|
534 |
-
}
|
535 |
-
|
536 |
-
}
|
537 |
-
|
538 |
-
private function render_admin_chosen_product_selector( $dom_id, $field_name, $selected_keys_and_values, $placeholder ) {
|
539 |
-
// $selected_keys_and_values must be an array of [ id => name ]
|
540 |
-
|
541 |
-
echo '<select id="' . esc_attr( $dom_id ) . '" name="' . esc_attr( $field_name ) . '[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="' . esc_attr( $placeholder ) . '">';
|
542 |
-
foreach ( $selected_keys_and_values as $product_id => $product_name ) {
|
543 |
-
echo '<option value="' . $product_id . '" selected="selected">' . $product_name . '</option>';
|
544 |
-
}
|
545 |
-
echo '</select>';
|
546 |
-
}
|
547 |
-
|
548 |
-
private function render_admin_select2_product_selector( $dom_id, $field_name, $selected_keys_and_values, $placeholder ) {
|
549 |
-
// $selected_keys_and_values must be an array of [ id => name ]
|
550 |
-
|
551 |
-
$json_encoded = esc_attr( json_encode( $selected_keys_and_values ) );
|
552 |
-
echo '<input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="'
|
553 |
-
. esc_attr( $field_name ) . '" data-placeholder="'
|
554 |
-
. esc_attr( $placeholder ) . '" data-action="woocommerce_json_search_products_and_variations" data-selected="'
|
555 |
-
. $json_encoded . '" value="' . implode( ',', array_keys( $selected_keys_and_values ) ) . '" />';
|
556 |
-
|
557 |
-
}
|
558 |
-
|
559 |
/**
|
560 |
* Add donate-link to plugin page
|
561 |
*/
|
19 |
public function init_admin_hook() {
|
20 |
add_action( 'admin_notices', array( $this, 'admin_notices'));
|
21 |
|
22 |
+
if ( ! WJECF_WC()->check_woocommerce_version('2.3.0') ) {
|
23 |
$this->enqueue_notice( '<p>' .
|
24 |
__( '<strong>WooCommerce Extended Coupon Features:</strong> You are using an old version of WooCommerce. Updating of WooCommerce is recommended as using an outdated version might cause unexpected behaviour in combination with modern plugins.' )
|
25 |
. '</p>', 'notice-warning' );
|
293 |
echo '<option value="' . esc_attr( $shipping_method->id ) . '"' . selected( in_array( $shipping_method->id, $coupon_shipping_method_ids ), true, false ) . '>' . esc_html( $shipping_method->method_title ) . '</option>';
|
294 |
}
|
295 |
?>
|
296 |
+
</select><?php echo WJECF_WC()->wc_help_tip( __( 'One of these shipping methods must be selected in order for this coupon to be valid.', 'woocommerce-jos-autocoupon' ) ); ?>
|
297 |
+
</p>
|
298 |
<?php
|
299 |
|
300 |
//=============================
|
312 |
}
|
313 |
}
|
314 |
?>
|
315 |
+
</select><?php echo WJECF_WC()->wc_help_tip( __( 'One of these payment methods must be selected in order for this coupon to be valid.', 'woocommerce-jos-autocoupon' ) ); ?>
|
316 |
+
</p>
|
317 |
<?php
|
318 |
}
|
319 |
|
340 |
}
|
341 |
|
342 |
echo esc_attr( json_encode( $json_ids ) );
|
343 |
+
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" />
|
344 |
+
<?php echo WJECF_WC()->wc_help_tip( __( 'Only these customers may use this coupon.', 'woocommerce-jos-autocoupon' ) ); ?>
|
345 |
+
</p>
|
346 |
<?php
|
347 |
|
348 |
//=============================
|
362 |
. esc_html( $role_name ) . '</option>';
|
363 |
}
|
364 |
?>
|
365 |
+
</select>
|
366 |
+
<?php echo WJECF_WC()->wc_help_tip( __( 'Only these User Roles may use this coupon.', 'woocommerce-jos-autocoupon' ) ); ?>
|
367 |
+
</p>
|
368 |
<?php
|
369 |
|
370 |
//=============================
|
383 |
. esc_html( $role_name ) . '</option>';
|
384 |
}
|
385 |
?>
|
386 |
+
</select>
|
387 |
+
<?php echo WJECF_WC()->wc_help_tip( __( 'These User Roles will be specifically excluded from using this coupon.', 'woocommerce-jos-autocoupon' ) ); ?>
|
388 |
+
</p>
|
389 |
<?php
|
390 |
}
|
391 |
|
516 |
<?php
|
517 |
}
|
518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
/**
|
520 |
* Add donate-link to plugin page
|
521 |
*/
|
includes/wjecf-autocoupon.php
CHANGED
@@ -24,7 +24,7 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
24 |
}
|
25 |
|
26 |
//Frontend hooks - logic
|
27 |
-
if (
|
28 |
add_action( 'woocommerce_after_calculate_totals', array( &$this, 'update_matched_autocoupons' ) );
|
29 |
} else {
|
30 |
//WC Versions prior to 2.3.0 don't have after_calculate_totals hook, this is a fallback
|
@@ -42,8 +42,8 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
42 |
add_filter('option_woocommerce_cart_redirect_after_add', array ( &$this, 'option_woocommerce_cart_redirect_after_add') );
|
43 |
|
44 |
if ( ! is_ajax() ) {
|
45 |
-
//Get cart should not be called before the wp_loaded action
|
46 |
-
add_action( 'wp_loaded', array( &$this, 'coupon_by_url' ) ); //Coupon through url
|
47 |
}
|
48 |
}
|
49 |
|
@@ -223,7 +223,7 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
223 |
$cart = WC()->cart;
|
224 |
foreach ( $split as $coupon_code ) {
|
225 |
$coupon = WJECF()->get_coupon( $coupon_code );
|
226 |
-
if (
|
227 |
wc_add_notice( $coupon->get_coupon_error( WC_Coupon::E_WC_COUPON_NOT_EXIST ), 'error' );
|
228 |
} else {
|
229 |
$valid = $coupon->is_valid();
|
@@ -240,12 +240,7 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
240 |
$requested_url .= $_SERVER['HTTP_HOST'];
|
241 |
$requested_url .= $_SERVER['REQUEST_URI'];
|
242 |
|
243 |
-
|
244 |
-
if ( WJECF()->check_woocommerce_version('2.3.0')) {
|
245 |
-
wp_safe_redirect( remove_query_arg( array( 'apply_coupon' ), ( $requested_url ) ) );
|
246 |
-
} else {
|
247 |
-
wp_safe_redirect( remove_query_arg( array( 'apply_coupon', 'add-to-cart' ), ( $requested_url ) ) );
|
248 |
-
}
|
249 |
exit;
|
250 |
}
|
251 |
}
|
24 |
}
|
25 |
|
26 |
//Frontend hooks - logic
|
27 |
+
if ( WJECF_WC()->check_woocommerce_version('2.3.0')) {
|
28 |
add_action( 'woocommerce_after_calculate_totals', array( &$this, 'update_matched_autocoupons' ) );
|
29 |
} else {
|
30 |
//WC Versions prior to 2.3.0 don't have after_calculate_totals hook, this is a fallback
|
42 |
add_filter('option_woocommerce_cart_redirect_after_add', array ( &$this, 'option_woocommerce_cart_redirect_after_add') );
|
43 |
|
44 |
if ( ! is_ajax() ) {
|
45 |
+
//Get cart should not be called before the wp_loaded action nor the add_to_cart_action (class-wc-form-handler)
|
46 |
+
add_action( 'wp_loaded', array( &$this, 'coupon_by_url' ), 90 ); //Coupon through url
|
47 |
}
|
48 |
}
|
49 |
|
223 |
$cart = WC()->cart;
|
224 |
foreach ( $split as $coupon_code ) {
|
225 |
$coupon = WJECF()->get_coupon( $coupon_code );
|
226 |
+
if ( WJECF_WC()->check_woocommerce_version('2.3.0') && ! $coupon->exists ) {
|
227 |
wc_add_notice( $coupon->get_coupon_error( WC_Coupon::E_WC_COUPON_NOT_EXIST ), 'error' );
|
228 |
} else {
|
229 |
$valid = $coupon->is_valid();
|
240 |
$requested_url .= $_SERVER['HTTP_HOST'];
|
241 |
$requested_url .= $_SERVER['REQUEST_URI'];
|
242 |
|
243 |
+
wp_safe_redirect( remove_query_arg( array( 'apply_coupon', 'add-to-cart' ), ( $requested_url ) ) );
|
|
|
|
|
|
|
|
|
|
|
244 |
exit;
|
245 |
}
|
246 |
}
|
includes/wjecf-controller.php
CHANGED
@@ -46,9 +46,14 @@ class WJECF_Controller {
|
|
46 |
//Paths
|
47 |
$this->plugin_path = plugin_dir_path( dirname(__FILE__) );
|
48 |
$this->plugin_url = plugins_url( '/', dirname( __FILE__ ) );
|
49 |
-
|
50 |
$filename = $this->is_pro() ? "woocommerce-jos-autocoupon-pro.php" : "woocommerce-jos-autocoupon.php" ;
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
$this->version = $plugin_data['Version'];
|
53 |
}
|
54 |
|
@@ -102,7 +107,7 @@ class WJECF_Controller {
|
|
102 |
//Frontend hooks
|
103 |
|
104 |
//assert_coupon_is_valid (which raises exception on invalid coupon) can only be used on WC 2.3.0 and up
|
105 |
-
if (
|
106 |
add_filter('woocommerce_coupon_is_valid', array( $this, 'assert_coupon_is_valid' ), 10, 2 );
|
107 |
} else {
|
108 |
add_filter('woocommerce_coupon_is_valid', array( $this, 'coupon_is_valid' ), 10, 2 );
|
@@ -169,42 +174,6 @@ class WJECF_Controller {
|
|
169 |
}
|
170 |
}
|
171 |
|
172 |
-
/**
|
173 |
-
* Check whether WooCommerce version is greater or equal than $req_version
|
174 |
-
* @param string @req_version The version to compare to
|
175 |
-
* @return bool true if WooCommerce is at least the given version
|
176 |
-
*/
|
177 |
-
public static function check_woocommerce_version( $req_version ) {
|
178 |
-
return version_compare( self::get_woocommerce_version(), $req_version, '>=' );
|
179 |
-
}
|
180 |
-
|
181 |
-
private static $wc_version = null;
|
182 |
-
/**
|
183 |
-
* Get the WooCommerce version number
|
184 |
-
* @return string|bool WC Version number or false if WC not detected
|
185 |
-
*/
|
186 |
-
public static function get_woocommerce_version() {
|
187 |
-
if (self::$wc_version === null) {
|
188 |
-
// If get_plugins() isn't available, require it
|
189 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
190 |
-
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
191 |
-
}
|
192 |
-
|
193 |
-
// Create the plugins folder and file variables
|
194 |
-
$plugin_folder = get_plugins( '/woocommerce' );
|
195 |
-
$plugin_file = 'woocommerce.php';
|
196 |
-
|
197 |
-
// If the plugin version number is set, return it
|
198 |
-
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
|
199 |
-
self::$wc_version = $plugin_folder[$plugin_file]['Version'];
|
200 |
-
} else {
|
201 |
-
self::$wc_version = false; // Not found
|
202 |
-
}
|
203 |
-
|
204 |
-
}
|
205 |
-
return self::$wc_version;
|
206 |
-
}
|
207 |
-
|
208 |
/* FRONTEND HOOKS */
|
209 |
|
210 |
/**
|
@@ -537,7 +506,7 @@ class WJECF_Controller {
|
|
537 |
$overwritten_values['discount_type'] = $coupon->discount_type;
|
538 |
|
539 |
//$coupon->is_valid_for_product only works for these types
|
540 |
-
if ( !
|
541 |
$overwritten_values['discount_type'] = $overwritten_values['type'] = $coupon->discount_type;
|
542 |
$coupon->discount_type = $coupon->type = 'fixed_product';
|
543 |
}
|
@@ -586,40 +555,6 @@ class WJECF_Controller {
|
|
586 |
return $coupon;
|
587 |
}
|
588 |
|
589 |
-
/**
|
590 |
-
* Check the type of the coupon
|
591 |
-
* @param WC_Coupon $coupon The coupon to check
|
592 |
-
* @param string|array $type The type(s) we want to check for
|
593 |
-
* @return bool True if the coupon is of the type
|
594 |
-
*/
|
595 |
-
public function coupon_is_type( $coupon, $type ) {
|
596 |
-
//Backwards compatibility 2.2.11
|
597 |
-
if ( method_exists( $coupon, 'is_type' ) ) {
|
598 |
-
return $coupon->is_type( $type );
|
599 |
-
} else {
|
600 |
-
return ( $coupon->discount_type == $type || ( is_array( $type ) && in_array( $coupon->discount_type, $type ) ) ) ? true : false;
|
601 |
-
}
|
602 |
-
}
|
603 |
-
|
604 |
-
/**
|
605 |
-
* Get categories of a product (and anchestors)
|
606 |
-
* @param int $product_id
|
607 |
-
* @return array product_cat_ids
|
608 |
-
*/
|
609 |
-
function get_product_cat_ids( $product_id ) {
|
610 |
-
//Backwards compatibility WC versions older than 2.5
|
611 |
-
if ( function_exists( 'wc_get_product_cat_ids' ) ) {
|
612 |
-
return wc_get_product_cat_ids( $product_id );
|
613 |
-
} else {
|
614 |
-
$product_cats = wp_get_post_terms( $product_id, 'product_cat', array( "fields" => "ids" ) );
|
615 |
-
|
616 |
-
foreach ( $product_cats as $product_cat ) {
|
617 |
-
$product_cats = array_merge( $product_cats, get_ancestors( $product_cat, 'product_cat' ) );
|
618 |
-
}
|
619 |
-
return $product_cats;
|
620 |
-
}
|
621 |
-
}
|
622 |
-
|
623 |
/**
|
624 |
* Get array of the selected shipping methods ids.
|
625 |
* @param int $coupon_id The coupon id
|
46 |
//Paths
|
47 |
$this->plugin_path = plugin_dir_path( dirname(__FILE__) );
|
48 |
$this->plugin_url = plugins_url( '/', dirname( __FILE__ ) );
|
49 |
+
|
50 |
$filename = $this->is_pro() ? "woocommerce-jos-autocoupon-pro.php" : "woocommerce-jos-autocoupon.php" ;
|
51 |
+
|
52 |
+
//Version
|
53 |
+
$default_headers = array(
|
54 |
+
'Version' => 'Version',
|
55 |
+
);
|
56 |
+
$plugin_data = get_file_data( $this->plugin_path . $filename, $default_headers, 'plugin' );
|
57 |
$this->version = $plugin_data['Version'];
|
58 |
}
|
59 |
|
107 |
//Frontend hooks
|
108 |
|
109 |
//assert_coupon_is_valid (which raises exception on invalid coupon) can only be used on WC 2.3.0 and up
|
110 |
+
if ( WJECF_WC()->check_woocommerce_version('2.3.0') ) {
|
111 |
add_filter('woocommerce_coupon_is_valid', array( $this, 'assert_coupon_is_valid' ), 10, 2 );
|
112 |
} else {
|
113 |
add_filter('woocommerce_coupon_is_valid', array( $this, 'coupon_is_valid' ), 10, 2 );
|
174 |
}
|
175 |
}
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
/* FRONTEND HOOKS */
|
178 |
|
179 |
/**
|
506 |
$overwritten_values['discount_type'] = $coupon->discount_type;
|
507 |
|
508 |
//$coupon->is_valid_for_product only works for these types
|
509 |
+
if ( ! WJECF_WC()->coupon_is_type( $coupon, array( 'fixed_product', 'percent_product' ) ) ) {
|
510 |
$overwritten_values['discount_type'] = $overwritten_values['type'] = $coupon->discount_type;
|
511 |
$coupon->discount_type = $coupon->type = 'fixed_product';
|
512 |
}
|
555 |
return $coupon;
|
556 |
}
|
557 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
558 |
/**
|
559 |
* Get array of the selected shipping methods ids.
|
560 |
* @param int $coupon_id The coupon id
|
includes/wjecf-wc.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
defined('ABSPATH') or die();
|
4 |
+
|
5 |
+
/**
|
6 |
+
*
|
7 |
+
* Interface to WooCommerce. Handles version differences / backwards compatibility.
|
8 |
+
*
|
9 |
+
* @since 2.3.7.2
|
10 |
+
*/
|
11 |
+
class WJECF_WC {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Returns a specific item in the cart.
|
15 |
+
*
|
16 |
+
* @param string $cart_item_key Cart item key.
|
17 |
+
* @return array Item data
|
18 |
+
*/
|
19 |
+
public function get_cart_item( $cart_item_key ) {
|
20 |
+
if ( $this->check_woocommerce_version('2.2.9') ) {
|
21 |
+
return WC()->cart->get_cart_item( $cart_item_key );
|
22 |
+
}
|
23 |
+
|
24 |
+
return isset( WC()->cart->cart_contents[ $cart_item_key ] ) ? WC()->cart->cart_contents[ $cart_item_key ] : array();
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Get categories of a product (and anchestors)
|
29 |
+
* @param int $product_id
|
30 |
+
* @return array product_cat_ids
|
31 |
+
*/
|
32 |
+
public function wc_get_product_cat_ids( $product_id ) {
|
33 |
+
//Since WC 2.5.0
|
34 |
+
if ( function_exists( 'wc_get_product_cat_ids' ) ) {
|
35 |
+
return wc_get_product_cat_ids( $product_id );
|
36 |
+
}
|
37 |
+
|
38 |
+
$product_cats = wp_get_post_terms( $product_id, 'product_cat', array( "fields" => "ids" ) );
|
39 |
+
|
40 |
+
foreach ( $product_cats as $product_cat ) {
|
41 |
+
$product_cats = array_merge( $product_cats, get_ancestors( $product_cat, 'product_cat' ) );
|
42 |
+
}
|
43 |
+
return $product_cats;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Check the type of the coupon
|
48 |
+
* @param WC_Coupon $coupon The coupon to check
|
49 |
+
* @param string|array $type The type(s) we want to check for
|
50 |
+
* @return bool True if the coupon is of the type
|
51 |
+
*/
|
52 |
+
public function coupon_is_type( $coupon, $type ) {
|
53 |
+
//Backwards compatibility 2.2.11
|
54 |
+
if ( method_exists( $coupon, 'is_type' ) ) {
|
55 |
+
return $coupon->is_type( $type );
|
56 |
+
}
|
57 |
+
|
58 |
+
return ( $coupon->discount_type == $type || ( is_array( $type ) && in_array( $coupon->discount_type, $type ) ) ) ? true : false;
|
59 |
+
}
|
60 |
+
|
61 |
+
//ADMIN
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Display a WooCommerce help tip
|
65 |
+
* @param string $tip The tip to display
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
public function wc_help_tip( $tip ) {
|
69 |
+
//Since WC 2.5.0
|
70 |
+
if ( function_exists( 'wc_help_tip' ) ) {
|
71 |
+
return wc_help_tip( $tip );
|
72 |
+
}
|
73 |
+
|
74 |
+
return '<img class="help_tip" style="margin-top: 21px;" data-tip="' . esc_attr( $tip ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Renders a product selection <input>. Will use either select2 (WC2.3+) or chosen (< WC2.3)
|
79 |
+
* @param string $dom_id
|
80 |
+
* @param string $field_name
|
81 |
+
* @param array $selected_ids Array of integers
|
82 |
+
* @param string|null $placeholder
|
83 |
+
* @return void
|
84 |
+
*/
|
85 |
+
public function render_admin_product_selector( $dom_id, $field_name, $selected_ids, $placeholder = null ) {
|
86 |
+
$product_key_values = array();
|
87 |
+
foreach ( $selected_ids as $product_id ) {
|
88 |
+
$product = wc_get_product( $product_id );
|
89 |
+
if ( is_object( $product ) ) {
|
90 |
+
$product_key_values[ esc_attr( $product_id ) ] = wp_kses_post( $product->get_formatted_name() );
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
if ( $placeholder === null ) $placeholder = __( 'Search for a product…', 'woocommerce' );
|
95 |
+
|
96 |
+
//In WooCommerce version 2.3.0 chosen was replaced by select2
|
97 |
+
if ( $this->check_woocommerce_version('2.3.0') ) {
|
98 |
+
$this->render_admin_select2_product_selector( $dom_id, $field_name, $product_key_values, $placeholder );
|
99 |
+
} else {
|
100 |
+
$this->render_admin_chosen_product_selector( $dom_id, $field_name, $product_key_values, $placeholder );
|
101 |
+
}
|
102 |
+
}
|
103 |
+
private function render_admin_chosen_product_selector( $dom_id, $field_name, $selected_keys_and_values, $placeholder ) {
|
104 |
+
// $selected_keys_and_values must be an array of [ id => name ]
|
105 |
+
|
106 |
+
echo '<select id="' . esc_attr( $dom_id ) . '" name="' . esc_attr( $field_name ) . '[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="' . esc_attr( $placeholder ) . '">';
|
107 |
+
foreach ( $selected_keys_and_values as $product_id => $product_name ) {
|
108 |
+
echo '<option value="' . $product_id . '" selected="selected">' . $product_name . '</option>';
|
109 |
+
}
|
110 |
+
echo '</select>';
|
111 |
+
}
|
112 |
+
private function render_admin_select2_product_selector( $dom_id, $field_name, $selected_keys_and_values, $placeholder ) {
|
113 |
+
// $selected_keys_and_values must be an array of [ id => name ]
|
114 |
+
|
115 |
+
$json_encoded = esc_attr( json_encode( $selected_keys_and_values ) );
|
116 |
+
echo '<input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="'
|
117 |
+
. esc_attr( $field_name ) . '" data-placeholder="'
|
118 |
+
. esc_attr( $placeholder ) . '" data-action="woocommerce_json_search_products_and_variations" data-selected="'
|
119 |
+
. $json_encoded . '" value="' . implode( ',', array_keys( $selected_keys_and_values ) ) . '" />';
|
120 |
+
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
//VERSION
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Check whether WooCommerce version is greater or equal than $req_version
|
128 |
+
* @param string @req_version The version to compare to
|
129 |
+
* @return bool true if WooCommerce is at least the given version
|
130 |
+
*/
|
131 |
+
public function check_woocommerce_version( $req_version ) {
|
132 |
+
return version_compare( $this->get_woocommerce_version(), $req_version, '>=' );
|
133 |
+
}
|
134 |
+
|
135 |
+
private $wc_version = null;
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Get the WooCommerce version number
|
139 |
+
* @return string|bool WC Version number or false if WC not detected
|
140 |
+
*/
|
141 |
+
public function get_woocommerce_version() {
|
142 |
+
if ($this->wc_version === null) {
|
143 |
+
// If get_plugins() isn't available, require it
|
144 |
+
if ( ! function_exists( 'get_plugins' ) ) {
|
145 |
+
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
146 |
+
}
|
147 |
+
|
148 |
+
// Create the plugins folder and file variables
|
149 |
+
$plugin_folder = get_plugins( '/woocommerce' );
|
150 |
+
$plugin_file = 'woocommerce.php';
|
151 |
+
|
152 |
+
// If the plugin version number is set, return it
|
153 |
+
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
|
154 |
+
$this->wc_version = $plugin_folder[$plugin_file]['Version'];
|
155 |
+
} else {
|
156 |
+
$this->wc_version = false; // Not found
|
157 |
+
}
|
158 |
+
|
159 |
+
}
|
160 |
+
return $this->wc_version;
|
161 |
+
}
|
162 |
+
|
163 |
+
//INSTANCE
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Singleton Instance
|
167 |
+
*
|
168 |
+
* @static
|
169 |
+
* @return Singleton Instance
|
170 |
+
*/
|
171 |
+
public static function instance() {
|
172 |
+
if ( is_null( self::$_instance ) ) {
|
173 |
+
self::$_instance = new self();
|
174 |
+
}
|
175 |
+
return self::$_instance;
|
176 |
+
}
|
177 |
+
protected static $_instance = null;
|
178 |
+
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: josk79
|
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQBCS2QHRY&lc=NL&item_name=Jos%20Koenis&item_number=wordpress%2dplugin¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
Tags: woocommerce, coupons, discount
|
5 |
Requires at least: 4.0.0
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 2.3.7
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -15,7 +15,7 @@ Additional functionality for WooCommerce Coupons: Allow discounts to be automati
|
|
15 |
"WooCommerce Extended Coupon Features" adds functionality to the WooCommerce coupons and allows for automatic discount rules.
|
16 |
Very easy to use, the functionality is conveniently integrated to the WooCommerce Edit Coupon panel.
|
17 |
|
18 |
-
Compatible with WooCommerce 2.6.
|
19 |
|
20 |
Full documentation is available at [www.soft79.nl](http://www.soft79.nl/documentation/wjecf).
|
21 |
|
@@ -106,6 +106,19 @@ Sure! [This](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQ
|
|
106 |
|
107 |
== Changelog ==
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
= 2.3.7 =
|
110 |
* PERFORMANCE: Admin could hang in some occasions on a jQuery-selector
|
111 |
* FIX: Suppresed warnings were displayed by the Query Monitor plugin if pro files are missing
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQBCS2QHRY&lc=NL&item_name=Jos%20Koenis&item_number=wordpress%2dplugin¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
Tags: woocommerce, coupons, discount
|
5 |
Requires at least: 4.0.0
|
6 |
+
Tested up to: 4.7
|
7 |
+
Stable tag: 2.3.7.4
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
15 |
"WooCommerce Extended Coupon Features" adds functionality to the WooCommerce coupons and allows for automatic discount rules.
|
16 |
Very easy to use, the functionality is conveniently integrated to the WooCommerce Edit Coupon panel.
|
17 |
|
18 |
+
Compatible with WooCommerce 2.6.11. Backwards compatible with older WooCommerce versions (2.3.0 confirmed).
|
19 |
|
20 |
Full documentation is available at [www.soft79.nl](http://www.soft79.nl/documentation/wjecf).
|
21 |
|
106 |
|
107 |
== Changelog ==
|
108 |
|
109 |
+
= 2.3.7.4 =
|
110 |
+
* FIX: Combining add-to-cart and apply_coupon in a single querystring
|
111 |
+
|
112 |
+
= 2.3.7.3 =
|
113 |
+
* FIX: Invalid usage of get_plugin_data
|
114 |
+
|
115 |
+
= 2.3.7.2 =
|
116 |
+
* FIX: Backwards compatibility with WooCommerce < 2.5.0
|
117 |
+
* INTERNAL: Introducing WJECF_WC() to maintain backwards compatibility
|
118 |
+
|
119 |
+
= 2.3.7.1 =
|
120 |
+
* (PRO) FIX: Bug in 'Limit discount to'
|
121 |
+
|
122 |
= 2.3.7 =
|
123 |
* PERFORMANCE: Admin could hang in some occasions on a jQuery-selector
|
124 |
* FIX: Suppresed warnings were displayed by the Query Monitor plugin if pro files are missing
|
woocommerce-jos-autocoupon.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WooCommerce Extended Coupon Features
|
4 |
* Plugin URI: http://www.soft79.nl
|
5 |
* Description: Additional functionality for WooCommerce Coupons: Apply certain coupons automatically, allow applying coupons via an url, etc...
|
6 |
-
* Version: 2.3.7
|
7 |
* Author: Soft79
|
8 |
* License: GPL2
|
9 |
*/
|
@@ -12,6 +12,7 @@
|
|
12 |
|
13 |
/*
|
14 |
TODO:
|
|
|
15 |
- WORK IN PROGRESS: Admin page: Option to enable/disable functionality
|
16 |
- Admin page: Enable/disable debugging
|
17 |
- Apply filter for autocoupon individual_use_filter
|
@@ -35,6 +36,7 @@ if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
|
35 |
}
|
36 |
}
|
37 |
|
|
|
38 |
require_once( 'includes/wjecf-controller.php' );
|
39 |
require_once( 'includes/abstract-wjecf-plugin.php' );
|
40 |
require_once( 'includes/admin/wjecf-admin.php' );
|
@@ -56,8 +58,9 @@ if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
|
56 |
load_plugin_textdomain('woocommerce-jos-autocoupon', false, basename(dirname(__FILE__)) . '/languages/' );
|
57 |
}
|
58 |
|
|
|
59 |
// Only Initiate the plugin if WooCommerce is active
|
60 |
-
if (
|
61 |
add_action( 'admin_notices', 'wjecf_admin_notice' );
|
62 |
function wjecf_admin_notice() {
|
63 |
$msg = __( 'WooCommerce Extended Coupon Features is disabled because WooCommerce could not be detected.', 'woocommerce-jos-autocoupon' );
|
@@ -65,6 +68,10 @@ if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
|
65 |
}
|
66 |
} else {
|
67 |
|
|
|
|
|
|
|
|
|
68 |
/**
|
69 |
* Get the instance of WJECF
|
70 |
* @return WJECF_Controller|WJECF_Pro_Controller The instance of WJECF
|
3 |
* Plugin Name: WooCommerce Extended Coupon Features
|
4 |
* Plugin URI: http://www.soft79.nl
|
5 |
* Description: Additional functionality for WooCommerce Coupons: Apply certain coupons automatically, allow applying coupons via an url, etc...
|
6 |
+
* Version: 2.3.7.4
|
7 |
* Author: Soft79
|
8 |
* License: GPL2
|
9 |
*/
|
12 |
|
13 |
/*
|
14 |
TODO:
|
15 |
+
- stop using get_plugin_data
|
16 |
- WORK IN PROGRESS: Admin page: Option to enable/disable functionality
|
17 |
- Admin page: Enable/disable debugging
|
18 |
- Apply filter for autocoupon individual_use_filter
|
36 |
}
|
37 |
}
|
38 |
|
39 |
+
require_once( 'includes/wjecf-wc.php' );
|
40 |
require_once( 'includes/wjecf-controller.php' );
|
41 |
require_once( 'includes/abstract-wjecf-plugin.php' );
|
42 |
require_once( 'includes/admin/wjecf-admin.php' );
|
58 |
load_plugin_textdomain('woocommerce-jos-autocoupon', false, basename(dirname(__FILE__)) . '/languages/' );
|
59 |
}
|
60 |
|
61 |
+
|
62 |
// Only Initiate the plugin if WooCommerce is active
|
63 |
+
if ( WJECF_WC::instance()->get_woocommerce_version() == false ) {
|
64 |
add_action( 'admin_notices', 'wjecf_admin_notice' );
|
65 |
function wjecf_admin_notice() {
|
66 |
$msg = __( 'WooCommerce Extended Coupon Features is disabled because WooCommerce could not be detected.', 'woocommerce-jos-autocoupon' );
|
68 |
}
|
69 |
} else {
|
70 |
|
71 |
+
function WJECF_WC() {
|
72 |
+
return WJECF_WC::instance();
|
73 |
+
}
|
74 |
+
|
75 |
/**
|
76 |
* Get the instance of WJECF
|
77 |
* @return WJECF_Controller|WJECF_Pro_Controller The instance of WJECF
|