Version Description
- FIX: WooCommerce 2.6 and UPS / USPS Shipping method compatibility ( those plugins use : as separator )
- FIX: Coupon by url (hook on wp_loaded instead of init)
- FIX: Admin pages invalid parsing of Chosen inputboxes WooCommerce < 2.3.0
- FIX: Free product on WooCommerce < 2.3.0
- INTERNAL: Rewritten overwrite_success_message methods
- (PRO) Ajax 'Apply coupon' support for free product selection on cart and checkout page. (OVERRIDEABLE TEMPLATE FILES UPDATED!)
- (PRO) FEATURE: Remember coupons that are not valid when applying (on the cart page) and apply them automatically when they validate
Download this release
Release Info
| Developer | josk79 |
| Plugin | |
| Version | 2.3.4 |
| Comparing to | |
| See all releases | |
Code changes from version 2.3.3 to 2.3.4
- includes/admin/wjecf-admin-auto-upgrade.php +4 -0
- includes/admin/wjecf-admin.php +47 -5
- includes/wjecf-autocoupon.php +21 -134
- includes/wjecf-controller.php +52 -3
- readme.txt +12 -3
- woocommerce-jos-autocoupon.php +12 -3
includes/admin/wjecf-admin-auto-upgrade.php
CHANGED
|
@@ -8,6 +8,10 @@ class WJECF_Admin_Auto_Upgrade extends Abstract_WJECF_Plugin {
|
|
| 8 |
|
| 9 |
//Upgrade options on version change
|
| 10 |
public function auto_upgrade() {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
//WJECF()->options['db_version'] = 1;update_option( 'wjecf_options' , WJECF()->options, false ); // Will force all upgrades
|
| 12 |
global $wpdb;
|
| 13 |
$prev_version = WJECF()->options['db_version'];
|
| 8 |
|
| 9 |
//Upgrade options on version change
|
| 10 |
public function auto_upgrade() {
|
| 11 |
+
if ( ! class_exists('WC_Coupon') ) {
|
| 12 |
+
return;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
//WJECF()->options['db_version'] = 1;update_option( 'wjecf_options' , WJECF()->options, false ); // Will force all upgrades
|
| 16 |
global $wpdb;
|
| 17 |
$prev_version = WJECF()->options['db_version'];
|
includes/admin/wjecf-admin.php
CHANGED
|
@@ -10,13 +10,14 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
| 10 |
|
| 11 |
public function __construct() {
|
| 12 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
/* ADMIN HOOKS */
|
| 16 |
public function admin_init() {
|
| 17 |
if ( ! WJECF()->check_woocommerce_version('2.3.0') ) {
|
| 18 |
$this->enqueue_notice( '<p>' .
|
| 19 |
-
__( '<strong>WooCommerce Extended Coupon Features:</strong> You are using
|
| 20 |
. '</p>', 'notice-warning' );
|
| 21 |
}
|
| 22 |
//Admin hooks
|
|
@@ -60,7 +61,34 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
| 60 |
// END - ADMIN NOTICES
|
| 61 |
// ===========================================================================
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
//Add tabs to the coupon option page
|
| 65 |
public function admin_coupon_options_tabs( $tabs ) {
|
| 66 |
|
|
@@ -383,17 +411,31 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
| 383 |
$wjecf_payment_methods = isset( $_POST['wjecf_payment_methods'] ) ? $_POST['wjecf_payment_methods'] : '';
|
| 384 |
update_post_meta( $post_id, '_wjecf_payment_methods', $wjecf_payment_methods );
|
| 385 |
|
| 386 |
-
$wjecf_customer_ids
|
| 387 |
update_post_meta( $post_id, '_wjecf_customer_ids', $wjecf_customer_ids );
|
| 388 |
|
| 389 |
$wjecf_customer_roles = isset( $_POST['wjecf_customer_roles'] ) ? $_POST['wjecf_customer_roles'] : '';
|
| 390 |
update_post_meta( $post_id, '_wjecf_customer_roles', $wjecf_customer_roles );
|
| 391 |
|
| 392 |
-
$wjecf_excluded_customer_roles
|
| 393 |
update_post_meta( $post_id, '_wjecf_excluded_customer_roles', $wjecf_excluded_customer_roles );
|
| 394 |
|
| 395 |
}
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
public function render_admin_cat_selector( $dom_id, $field_name, $selected_ids, $placeholder = null ) {
|
| 398 |
if ( $placeholder === null ) $placeholder = __( 'Search for a product…', 'woocommerce' );
|
| 399 |
|
|
@@ -435,7 +477,7 @@ class WJECF_Admin extends Abstract_WJECF_Plugin {
|
|
| 435 |
private function render_admin_chosen_product_selector( $dom_id, $field_name, $selected_keys_and_values, $placeholder ) {
|
| 436 |
// $selected_keys_and_values must be an array of [ id => name ]
|
| 437 |
|
| 438 |
-
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 ) . '">';
|
| 439 |
foreach ( $selected_keys_and_values as $product_id => $product_name ) {
|
| 440 |
echo '<option value="' . $product_id . '" selected="selected">' . $product_name . '</option>';
|
| 441 |
}
|
| 10 |
|
| 11 |
public function __construct() {
|
| 12 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
| 13 |
+
//FUTURE: ADMIN MENU add_action('admin_menu', array( &$this, 'action_admin_menu' ) );
|
| 14 |
}
|
| 15 |
|
| 16 |
/* ADMIN HOOKS */
|
| 17 |
public function admin_init() {
|
| 18 |
if ( ! WJECF()->check_woocommerce_version('2.3.0') ) {
|
| 19 |
$this->enqueue_notice( '<p>' .
|
| 20 |
+
__( '<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.' )
|
| 21 |
. '</p>', 'notice-warning' );
|
| 22 |
}
|
| 23 |
//Admin hooks
|
| 61 |
// END - ADMIN NOTICES
|
| 62 |
// ===========================================================================
|
| 63 |
|
| 64 |
+
/* FUTURE: ADMIN MENU
|
| 65 |
+
public function action_admin_menu() {
|
| 66 |
+
add_options_page( __( 'WooCommerce Extended Coupon Features', 'soft79-wc-pricing-rules' ), __( 'WooCommerce Extended Coupon Features', 'soft79-wc-pricing-rules' ), 'manage_options', 'wjecf_settings', array( &$this, 'action_admin_config_page' ) );
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public function action_admin_config_page() {
|
| 70 |
+
?>
|
| 71 |
+
<h2><?php _e( 'WooCommerce Extended Coupon Features', 'soft79-wc-pricing-rules' ); ?></h2>
|
| 72 |
+
<form method="post" action="options.php">
|
| 73 |
+
<?php
|
| 74 |
+
settings_fields( 'wjecf_settings' );
|
| 75 |
+
do_settings_sections( 'wjecf_settings' );
|
| 76 |
+
?>
|
| 77 |
+
<?php submit_button(); ?>
|
| 78 |
+
</form>
|
| 79 |
+
<h3><?php _e( 'Plugins', 'soft79-wc-pricing-rules' ); ?></h3>
|
| 80 |
+
<ul>
|
| 81 |
+
<?php
|
| 82 |
+
foreach ( WJECF()->get_plugins() as $name => $plugin ) {
|
| 83 |
+
echo "<li>" . $name . "</li>\n";
|
| 84 |
+
}
|
| 85 |
+
?>
|
| 86 |
+
</ul>
|
| 87 |
+
<?php
|
| 88 |
+
|
| 89 |
+
}
|
| 90 |
+
*/
|
| 91 |
+
|
| 92 |
//Add tabs to the coupon option page
|
| 93 |
public function admin_coupon_options_tabs( $tabs ) {
|
| 94 |
|
| 411 |
$wjecf_payment_methods = isset( $_POST['wjecf_payment_methods'] ) ? $_POST['wjecf_payment_methods'] : '';
|
| 412 |
update_post_meta( $post_id, '_wjecf_payment_methods', $wjecf_payment_methods );
|
| 413 |
|
| 414 |
+
$wjecf_customer_ids = $this->comma_separated_int_array( $_POST['wjecf_customer_ids'] );
|
| 415 |
update_post_meta( $post_id, '_wjecf_customer_ids', $wjecf_customer_ids );
|
| 416 |
|
| 417 |
$wjecf_customer_roles = isset( $_POST['wjecf_customer_roles'] ) ? $_POST['wjecf_customer_roles'] : '';
|
| 418 |
update_post_meta( $post_id, '_wjecf_customer_roles', $wjecf_customer_roles );
|
| 419 |
|
| 420 |
+
$wjecf_excluded_customer_roles = isset( $_POST['wjecf_excluded_customer_roles'] ) ? $_POST['wjecf_excluded_customer_roles'] : '';
|
| 421 |
update_post_meta( $post_id, '_wjecf_excluded_customer_roles', $wjecf_excluded_customer_roles );
|
| 422 |
|
| 423 |
}
|
| 424 |
|
| 425 |
+
/**
|
| 426 |
+
* 2.3.4
|
| 427 |
+
* Parse an array or comma separated string; make sure they are valid ints and return as comma separated string
|
| 428 |
+
* @param array|string $int_array
|
| 429 |
+
* @return string comma separated int array
|
| 430 |
+
*/
|
| 431 |
+
public function comma_separated_int_array( $int_array ) {
|
| 432 |
+
//Source can be a comma separated string (select2) , or an int array (chosen)
|
| 433 |
+
if ( ! is_array( $int_array) ) {
|
| 434 |
+
$int_array = explode( ',', $int_array );
|
| 435 |
+
}
|
| 436 |
+
return implode( ',', array_filter( array_map( 'intval', $int_array ) ) );
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
public function render_admin_cat_selector( $dom_id, $field_name, $selected_ids, $placeholder = null ) {
|
| 440 |
if ( $placeholder === null ) $placeholder = __( 'Search for a product…', 'woocommerce' );
|
| 441 |
|
| 477 |
private function render_admin_chosen_product_selector( $dom_id, $field_name, $selected_keys_and_values, $placeholder ) {
|
| 478 |
// $selected_keys_and_values must be an array of [ id => name ]
|
| 479 |
|
| 480 |
+
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 ) . '">';
|
| 481 |
foreach ( $selected_keys_and_values as $product_id => $product_name ) {
|
| 482 |
echo '<option value="' . $product_id . '" selected="selected">' . $product_name . '</option>';
|
| 483 |
}
|
includes/wjecf-autocoupon.php
CHANGED
|
@@ -41,9 +41,9 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 41 |
add_filter('option_woocommerce_cart_redirect_after_add', array ( &$this, 'option_woocommerce_cart_redirect_after_add') );
|
| 42 |
|
| 43 |
if ( ! is_ajax() ) {
|
| 44 |
-
|
|
|
|
| 45 |
}
|
| 46 |
-
|
| 47 |
}
|
| 48 |
|
| 49 |
/* ADMIN HOOKS */
|
|
@@ -210,13 +210,14 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 210 |
|
| 211 |
//Apply coupon by url
|
| 212 |
if ( isset( $_GET['apply_coupon'] ) ) {
|
|
|
|
| 213 |
$this->_executed_coupon_by_url = true;
|
| 214 |
$split = explode( ",", wc_clean( $_GET['apply_coupon'] ) );
|
| 215 |
//2.2.2 Make sure a session cookie is set
|
| 216 |
if( ! WC()->session->has_session() )
|
| 217 |
{
|
| 218 |
WC()->session->set_customer_session_cookie( true );
|
| 219 |
-
}
|
| 220 |
|
| 221 |
$cart = WC()->cart;
|
| 222 |
foreach ( $split as $coupon_code ) {
|
|
@@ -228,32 +229,6 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 228 |
if ( $valid ) {
|
| 229 |
$cart->add_discount( $coupon_code );
|
| 230 |
}
|
| 231 |
-
|
| 232 |
-
//2.3.3 Keep track of apply_coupon coupons and apply when they validate
|
| 233 |
-
if ( WJECF()->is_pro() ) {
|
| 234 |
-
$by_url_coupon_codes = $this->get_by_url_coupon_codes();
|
| 235 |
-
if ( ! in_array( $coupon_code, $by_url_coupon_codes ) ) {
|
| 236 |
-
$by_url_coupon_codes[] = $coupon_code;
|
| 237 |
-
$this->set_by_url_coupon_codes( $by_url_coupon_codes );
|
| 238 |
-
}
|
| 239 |
-
if ( ! $valid ) {
|
| 240 |
-
wc_add_notice( sprintf( __( 'Coupon \'%s\' will be applied when it\'s conditions are met.', 'woocommerce-jos-autocoupon' ), $coupon_code ) );
|
| 241 |
-
$must_redirect = true;
|
| 242 |
-
}
|
| 243 |
-
}
|
| 244 |
-
}
|
| 245 |
-
}
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
//2.3.3 Keep track of apply_coupon coupons and apply when they validate
|
| 249 |
-
if ( WJECF()->is_pro() ) {
|
| 250 |
-
//Remove auto coupon codes from session
|
| 251 |
-
if ( isset( $_GET['remove_coupon'] ) ) {
|
| 252 |
-
$coupon_code = wc_clean( $_GET['remove_coupon'] );
|
| 253 |
-
$by_url_coupon_codes = $this->get_by_url_coupon_codes();
|
| 254 |
-
if( ( $key = array_search( $coupon_code, $by_url_coupon_codes ) ) !== false ) {
|
| 255 |
-
unset( $by_url_coupon_codes[$key] );
|
| 256 |
-
$this->set_by_url_coupon_codes( $by_url_coupon_codes );
|
| 257 |
}
|
| 258 |
}
|
| 259 |
}
|
|
@@ -349,8 +324,11 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 349 |
$this->update_matched_autocoupons_executed = true;
|
| 350 |
$this->log( "()" );
|
| 351 |
|
| 352 |
-
//2.3.3 Keep track of
|
| 353 |
-
$
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
//Get the coupons that should be in the cart
|
| 356 |
$valid_coupons = $this->get_valid_auto_coupons();
|
|
@@ -361,7 +339,7 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 361 |
$valid_coupon_codes[] = $coupon->code;
|
| 362 |
}
|
| 363 |
|
| 364 |
-
|
| 365 |
|
| 366 |
$calc_needed = $this->remove_unmatched_autocoupons( $valid_coupon_codes );
|
| 367 |
|
|
@@ -369,12 +347,11 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 369 |
foreach( $valid_coupons as $coupon ) {
|
| 370 |
if ( ! WC()->cart->has_discount( $coupon->code ) ) {
|
| 371 |
$this->log( sprintf( "Applying auto coupon %s", $coupon->code ) );
|
| 372 |
-
WC()->cart->add_discount( $coupon->code ); //Causes calculation and will remove other coupons if it's a individual coupon
|
| 373 |
-
$calc_needed = false; //Already done by adding the discount
|
| 374 |
|
| 375 |
$apply_silently = get_post_meta( $coupon->id, '_wjecf_apply_silently', true ) == 'yes';
|
|
|
|
| 376 |
if ( $apply_silently ) {
|
| 377 |
-
$new_succss_msg =
|
| 378 |
} else {
|
| 379 |
$coupon_excerpt = $this->coupon_excerpt($coupon);
|
| 380 |
$new_succss_msg = sprintf(
|
|
@@ -382,7 +359,13 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 382 |
__( empty( $coupon_excerpt ) ? $coupon->code : $coupon_excerpt, 'woocommerce-jos-autocoupon')
|
| 383 |
);
|
| 384 |
}
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
}
|
| 387 |
}
|
| 388 |
|
|
@@ -394,57 +377,6 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 394 |
|
| 395 |
}
|
| 396 |
|
| 397 |
-
/**
|
| 398 |
-
* Apply the valid by_url coupons
|
| 399 |
-
* @return void
|
| 400 |
-
*/
|
| 401 |
-
private function apply_valid_by_url_coupons( ) {
|
| 402 |
-
//2.3.3 Keep track of apply_coupon coupons and apply when they validate
|
| 403 |
-
if ( WJECF()->is_pro() ) {
|
| 404 |
-
$this->log( "()" );
|
| 405 |
-
$by_url_coupon_codes = $this->get_by_url_coupon_codes();
|
| 406 |
-
$this->log( "By_url coupons: " . implode( ' ', $by_url_coupon_codes ) );
|
| 407 |
-
foreach( $by_url_coupon_codes as $coupon_code ) {
|
| 408 |
-
if ( ! WC()->cart->has_discount( $coupon_code ) ) {
|
| 409 |
-
$coupon = new WC_Coupon( $coupon_code );
|
| 410 |
-
if ( $coupon->is_valid() ) {
|
| 411 |
-
$this->log( sprintf( "Applying by_url coupon %s", $coupon->code ) );
|
| 412 |
-
WC()->cart->add_discount( $coupon->code ); //Causes calculation and will remove other coupons if it's a individual coupon
|
| 413 |
-
//$calc_needed = false; //Already done by adding the discount
|
| 414 |
-
$new_succss_msg = sprintf(
|
| 415 |
-
__("Discount applied: %s", 'woocommerce-jos-autocoupon'),
|
| 416 |
-
__($coupon->code, 'woocommerce-jos-autocoupon')
|
| 417 |
-
);
|
| 418 |
-
$this->overwrite_success_message( $coupon, $new_succss_msg );
|
| 419 |
-
} elseif ( ! $coupon->exists ) {
|
| 420 |
-
//Remove non-existent
|
| 421 |
-
if( ( $key = array_search($coupon_code, $by_url_coupon_codes ) ) !== false ) {
|
| 422 |
-
unset( $by_url_coupon_codes[$key] );
|
| 423 |
-
$this->set_by_url_coupon_codes( $by_url_coupon_codes );
|
| 424 |
-
}
|
| 425 |
-
//wc_add_notice( $coupon->get_coupon_error( WC_Coupon::E_WC_COUPON_NOT_EXIST ), 'error' );
|
| 426 |
-
}
|
| 427 |
-
}
|
| 428 |
-
}
|
| 429 |
-
}
|
| 430 |
-
}
|
| 431 |
-
|
| 432 |
-
/**
|
| 433 |
-
* Get the by_url coupon codes from the session
|
| 434 |
-
* @return array The coupon codes
|
| 435 |
-
*/
|
| 436 |
-
public function get_by_url_coupon_codes() {
|
| 437 |
-
return WC()->session->get( 'wjecf_by_url_coupons' , array() );
|
| 438 |
-
}
|
| 439 |
-
/**
|
| 440 |
-
* Save the by_url coupon codes in the session
|
| 441 |
-
* @param array $coupon_codes
|
| 442 |
-
* @return void
|
| 443 |
-
*/
|
| 444 |
-
public function set_by_url_coupon_codes( $coupon_codes ) {
|
| 445 |
-
WC()->session->set( 'wjecf_by_url_coupons' , array_unique( $coupon_codes ) );
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
private function get_valid_auto_coupons( ) {
|
| 449 |
$valid_coupons = array();
|
| 450 |
foreach ( $this->get_all_auto_coupons() as $coupon ) {
|
|
@@ -509,58 +441,13 @@ class WJECF_AutoCoupon extends Abstract_WJECF_Plugin {
|
|
| 509 |
}
|
| 510 |
|
| 511 |
|
| 512 |
-
|
| 513 |
-
* Overwrite the default "Coupon added" notice with a more descriptive message.
|
| 514 |
-
* @param WC_Coupon $coupon The coupon data
|
| 515 |
-
* @param string|bool $new_succss_msg The message to display. If false (or empty string), no message will be shown
|
| 516 |
-
* @return void
|
| 517 |
-
*/
|
| 518 |
-
private function overwrite_success_message( $coupon, $new_succss_msg = false ) {
|
| 519 |
-
$succss_msg = $coupon->get_coupon_message( WC_Coupon::WC_COUPON_SUCCESS );
|
| 520 |
-
|
| 521 |
-
//If ajax, remove only
|
| 522 |
-
$remove_message_only = empty( $new_succss_msg ) || ( defined('DOING_AJAX') && DOING_AJAX );
|
| 523 |
-
|
| 524 |
-
//Compatibility woocommerce-2-1-notice-api
|
| 525 |
-
if ( function_exists('wc_get_notices') ) {
|
| 526 |
-
$all_notices = wc_get_notices();
|
| 527 |
-
if ( ! isset( $all_notices['success'] ) ) {
|
| 528 |
-
$all_notices['success'] = array();
|
| 529 |
-
}
|
| 530 |
-
$messages = $all_notices['success'];
|
| 531 |
-
} else {
|
| 532 |
-
$messages = $woocommerce->messages;
|
| 533 |
-
}
|
| 534 |
-
|
| 535 |
-
$sizeof_messages = sizeof($messages);
|
| 536 |
-
for( $y=0; $y < $sizeof_messages; $y++ ) {
|
| 537 |
-
if ( $messages[$y] == $succss_msg ) {
|
| 538 |
-
if ( isset($all_notices) ) {
|
| 539 |
-
if ( $remove_message_only ) {
|
| 540 |
-
unset ( $all_notices['success'][$y] );
|
| 541 |
-
} else {
|
| 542 |
-
$all_notices['success'][$y] = $new_succss_msg;
|
| 543 |
-
}
|
| 544 |
-
WC()->session->set( 'wc_notices', $all_notices );
|
| 545 |
-
} else {
|
| 546 |
-
if ( $remove_message_only ) {
|
| 547 |
-
unset ( $messages[$y] );
|
| 548 |
-
} else {
|
| 549 |
-
$messages[$y] = $new_succss_msg;
|
| 550 |
-
}
|
| 551 |
-
}
|
| 552 |
-
|
| 553 |
-
break;
|
| 554 |
-
}
|
| 555 |
-
}
|
| 556 |
-
}
|
| 557 |
-
|
| 558 |
/**
|
| 559 |
* Check wether the coupon is an "Auto coupon".
|
| 560 |
* @param WC_Coupon $coupon The coupon data
|
| 561 |
* @return bool true if it is an "Auto coupon"
|
| 562 |
*/
|
| 563 |
-
|
| 564 |
return get_post_meta( $coupon->id, '_wjecf_is_auto_coupon', true ) == 'yes';
|
| 565 |
}
|
| 566 |
|
| 41 |
add_filter('option_woocommerce_cart_redirect_after_add', array ( &$this, 'option_woocommerce_cart_redirect_after_add') );
|
| 42 |
|
| 43 |
if ( ! is_ajax() ) {
|
| 44 |
+
//Get cart should not be called before the wp_loaded action
|
| 45 |
+
add_action( 'wp_loaded', array( &$this, 'coupon_by_url' ) ); //Coupon through url
|
| 46 |
}
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
/* ADMIN HOOKS */
|
| 210 |
|
| 211 |
//Apply coupon by url
|
| 212 |
if ( isset( $_GET['apply_coupon'] ) ) {
|
| 213 |
+
$must_redirect = true;
|
| 214 |
$this->_executed_coupon_by_url = true;
|
| 215 |
$split = explode( ",", wc_clean( $_GET['apply_coupon'] ) );
|
| 216 |
//2.2.2 Make sure a session cookie is set
|
| 217 |
if( ! WC()->session->has_session() )
|
| 218 |
{
|
| 219 |
WC()->session->set_customer_session_cookie( true );
|
| 220 |
+
}
|
| 221 |
|
| 222 |
$cart = WC()->cart;
|
| 223 |
foreach ( $split as $coupon_code ) {
|
| 229 |
if ( $valid ) {
|
| 230 |
$cart->add_discount( $coupon_code );
|
| 231 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
}
|
| 233 |
}
|
| 234 |
}
|
| 324 |
$this->update_matched_autocoupons_executed = true;
|
| 325 |
$this->log( "()" );
|
| 326 |
|
| 327 |
+
//2.3.3 Keep track of queued coupons and apply when they validate
|
| 328 |
+
$queuer = WJECF()->get_plugin('WJECF_Pro_Coupon_Queueing');
|
| 329 |
+
if ( $queuer !== false ) {
|
| 330 |
+
$queuer->apply_valid_queued_coupons();
|
| 331 |
+
}
|
| 332 |
|
| 333 |
//Get the coupons that should be in the cart
|
| 334 |
$valid_coupons = $this->get_valid_auto_coupons();
|
| 339 |
$valid_coupon_codes[] = $coupon->code;
|
| 340 |
}
|
| 341 |
|
| 342 |
+
$this->log( sprintf( "Auto coupons that should be in cart: %s", implode( ', ', $valid_coupon_codes ) ) );
|
| 343 |
|
| 344 |
$calc_needed = $this->remove_unmatched_autocoupons( $valid_coupon_codes );
|
| 345 |
|
| 347 |
foreach( $valid_coupons as $coupon ) {
|
| 348 |
if ( ! WC()->cart->has_discount( $coupon->code ) ) {
|
| 349 |
$this->log( sprintf( "Applying auto coupon %s", $coupon->code ) );
|
|
|
|
|
|
|
| 350 |
|
| 351 |
$apply_silently = get_post_meta( $coupon->id, '_wjecf_apply_silently', true ) == 'yes';
|
| 352 |
+
|
| 353 |
if ( $apply_silently ) {
|
| 354 |
+
$new_succss_msg = ''; // no message
|
| 355 |
} else {
|
| 356 |
$coupon_excerpt = $this->coupon_excerpt($coupon);
|
| 357 |
$new_succss_msg = sprintf(
|
| 359 |
__( empty( $coupon_excerpt ) ? $coupon->code : $coupon_excerpt, 'woocommerce-jos-autocoupon')
|
| 360 |
);
|
| 361 |
}
|
| 362 |
+
|
| 363 |
+
WJECF()->start_overwrite_success_message( $coupon, $new_succss_msg );
|
| 364 |
+
WC()->cart->add_discount( $coupon->code ); //Causes calculation and will remove other coupons if it's a individual coupon
|
| 365 |
+
WJECF()->stop_overwrite_success_message();
|
| 366 |
+
|
| 367 |
+
$calc_needed = false; //Already done by adding the discount
|
| 368 |
+
|
| 369 |
}
|
| 370 |
}
|
| 371 |
|
| 377 |
|
| 378 |
}
|
| 379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
private function get_valid_auto_coupons( ) {
|
| 381 |
$valid_coupons = array();
|
| 382 |
foreach ( $this->get_all_auto_coupons() as $coupon ) {
|
| 441 |
}
|
| 442 |
|
| 443 |
|
| 444 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
/**
|
| 446 |
* Check wether the coupon is an "Auto coupon".
|
| 447 |
* @param WC_Coupon $coupon The coupon data
|
| 448 |
* @return bool true if it is an "Auto coupon"
|
| 449 |
*/
|
| 450 |
+
public function is_auto_coupon($coupon) {
|
| 451 |
return get_post_meta( $coupon->id, '_wjecf_is_auto_coupon', true ) == 'yes';
|
| 452 |
}
|
| 453 |
|
includes/wjecf-controller.php
CHANGED
|
@@ -44,7 +44,7 @@ class WJECF_Controller {
|
|
| 44 |
if ( ! class_exists('WC_Coupon') ) {
|
| 45 |
return;
|
| 46 |
}
|
| 47 |
-
$this->debug_mode = false; //
|
| 48 |
$this->log( "INIT " . ( is_ajax() ? "AJAX" : is_admin() ? "ADMIN" : "FRONTEND" ) . " " . $_SERVER['REQUEST_URI'] );
|
| 49 |
|
| 50 |
$this->init_options();
|
|
@@ -83,8 +83,17 @@ class WJECF_Controller {
|
|
| 83 |
return $this->plugins;
|
| 84 |
}
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
public function get_plugin( $class_name ) {
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
public function init_options() {
|
|
@@ -308,7 +317,9 @@ class WJECF_Controller {
|
|
| 308 |
$shipping_method_ids = $this->get_coupon_shipping_method_ids( $coupon->id );
|
| 309 |
if ( sizeof( $shipping_method_ids ) > 0 ) {
|
| 310 |
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
|
| 311 |
-
$chosen_shipping = $chosen_shipping_methods[0];
|
|
|
|
|
|
|
| 312 |
|
| 313 |
if ( ! in_array( $chosen_shipping, $shipping_method_ids ) ) {
|
| 314 |
throw new Exception( self::E_WC_COUPON_SHIPPING_METHOD_NOT_MET );
|
|
@@ -606,6 +617,44 @@ class WJECF_Controller {
|
|
| 606 |
return $this instanceof WJECF_Pro_Controller;
|
| 607 |
}
|
| 608 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
// ===========================================================================
|
| 610 |
// START - OVERWRITE COUPON DATA
|
| 611 |
// Allows for non-persistent overwriting of fields during a single PHP call.
|
| 44 |
if ( ! class_exists('WC_Coupon') ) {
|
| 45 |
return;
|
| 46 |
}
|
| 47 |
+
$this->debug_mode = false; //defined( 'WP_DEBUG' ) && WP_DEBUG;
|
| 48 |
$this->log( "INIT " . ( is_ajax() ? "AJAX" : is_admin() ? "ADMIN" : "FRONTEND" ) . " " . $_SERVER['REQUEST_URI'] );
|
| 49 |
|
| 50 |
$this->init_options();
|
| 83 |
return $this->plugins;
|
| 84 |
}
|
| 85 |
|
| 86 |
+
/**
|
| 87 |
+
* Retrieves the WJECF Plugin
|
| 88 |
+
* @param string $class_name
|
| 89 |
+
* @return object|bool The plugin if found, otherwise returns false
|
| 90 |
+
*/
|
| 91 |
public function get_plugin( $class_name ) {
|
| 92 |
+
if ( isset( $this->plugins[ $class_name ] ) ) {
|
| 93 |
+
return $this->plugins[ $class_name ];
|
| 94 |
+
} else {
|
| 95 |
+
return false;
|
| 96 |
+
}
|
| 97 |
}
|
| 98 |
|
| 99 |
public function init_options() {
|
| 317 |
$shipping_method_ids = $this->get_coupon_shipping_method_ids( $coupon->id );
|
| 318 |
if ( sizeof( $shipping_method_ids ) > 0 ) {
|
| 319 |
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
|
| 320 |
+
$chosen_shipping = empty( $chosen_shipping_methods ) ? '' : $chosen_shipping_methods[0];
|
| 321 |
+
$chosen_shipping = explode( ':', $chosen_shipping); //UPS and USPS stores extra data, seperated by colon
|
| 322 |
+
$chosen_shipping = $chosen_shipping[0];
|
| 323 |
|
| 324 |
if ( ! in_array( $chosen_shipping, $shipping_method_ids ) ) {
|
| 325 |
throw new Exception( self::E_WC_COUPON_SHIPPING_METHOD_NOT_MET );
|
| 617 |
return $this instanceof WJECF_Pro_Controller;
|
| 618 |
}
|
| 619 |
|
| 620 |
+
// ===========================================================================
|
| 621 |
+
// START - OVERWRITE INFO MESSAGES
|
| 622 |
+
// ===========================================================================
|
| 623 |
+
|
| 624 |
+
/**
|
| 625 |
+
* 2.3.4
|
| 626 |
+
* If a 'Coupon applied' message is displayed by WooCommerce, replace it by another message (or no message)
|
| 627 |
+
* @param WC_Coupon $coupon The coupon to replace the message for
|
| 628 |
+
* @param string $new_message The new message. Set to empty string if no message must be displayed
|
| 629 |
+
*/
|
| 630 |
+
public function start_overwrite_success_message( $coupon, $new_message = '' ) {
|
| 631 |
+
$this->overwrite_coupon_message[ $coupon->code ] = array( $coupon->get_coupon_message( WC_Coupon::WC_COUPON_SUCCESS ) => $new_message );
|
| 632 |
+
add_filter( 'woocommerce_coupon_message', array( $this, 'filter_woocommerce_coupon_message' ), 10, 3 );
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
/**
|
| 636 |
+
* 2.3.4
|
| 637 |
+
* Stop overwriting messages
|
| 638 |
+
*/
|
| 639 |
+
public function stop_overwrite_success_message() {
|
| 640 |
+
remove_filter( 'woocommerce_coupon_message', array( $this, 'filter_woocommerce_coupon_message' ), 10 );
|
| 641 |
+
$this->overwrite_coupon_message = array();
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
private $overwrite_coupon_message = array(); /* [ 'coupon_code' => [ old_message' => 'new_message' ] ] */
|
| 645 |
+
|
| 646 |
+
function filter_woocommerce_coupon_message( $msg, $msg_code, $coupon ) {
|
| 647 |
+
if ( isset( $this->overwrite_coupon_message[ $coupon->code ][ $msg ] ) ) {
|
| 648 |
+
$msg = $this->overwrite_coupon_message[ $coupon->code ][ $msg ];
|
| 649 |
+
}
|
| 650 |
+
return $msg;
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
// ===========================================================================
|
| 654 |
+
// END - OVERWRITE INFO MESSAGES
|
| 655 |
+
// ===========================================================================
|
| 656 |
+
|
| 657 |
+
|
| 658 |
// ===========================================================================
|
| 659 |
// START - OVERWRITE COUPON DATA
|
| 660 |
// Allows for non-persistent overwriting of fields during a single PHP call.
|
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.5.
|
| 7 |
-
Stable tag: 2.3.
|
| 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.
|
| 19 |
|
| 20 |
Full documentation is available at [www.soft79.nl](http://www.soft79.nl/documentation/wjecf).
|
| 21 |
|
|
@@ -106,6 +106,15 @@ Sure! [This](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQ
|
|
| 106 |
|
| 107 |
== Changelog ==
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
= 2.3.3 =
|
| 110 |
* FIX: limit_usage_to_x_items: Removed call to get_discount_amount from coupon_has_a_value; it is redundant and caused limit_usage_to_x_items to change
|
| 111 |
* (PRO) FEATURE: Filters wjecf_free_product_amount_for_coupon, wjecf_bogo_product_amount_for_coupon and wjecf_set_free_product_amount_in_cart
|
| 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.5.3
|
| 7 |
+
Stable tag: 2.3.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.1. 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.4 =
|
| 110 |
+
* FIX: WooCommerce 2.6 and UPS / USPS Shipping method compatibility ( those plugins use : as separator )
|
| 111 |
+
* FIX: Coupon by url (hook on wp_loaded instead of init)
|
| 112 |
+
* FIX: Admin pages invalid parsing of Chosen inputboxes WooCommerce < 2.3.0
|
| 113 |
+
* FIX: Free product on WooCommerce < 2.3.0
|
| 114 |
+
* INTERNAL: Rewritten overwrite_success_message methods
|
| 115 |
+
* (PRO) Ajax 'Apply coupon' support for free product selection on cart and checkout page. (OVERRIDEABLE TEMPLATE FILES UPDATED!)
|
| 116 |
+
* (PRO) FEATURE: Remember coupons that are not valid when applying (on the cart page) and apply them automatically when they validate
|
| 117 |
+
|
| 118 |
= 2.3.3 =
|
| 119 |
* FIX: limit_usage_to_x_items: Removed call to get_discount_amount from coupon_has_a_value; it is redundant and caused limit_usage_to_x_items to change
|
| 120 |
* (PRO) FEATURE: Filters wjecf_free_product_amount_for_coupon, wjecf_bogo_product_amount_for_coupon and wjecf_set_free_product_amount_in_cart
|
woocommerce-jos-autocoupon.php
CHANGED
|
@@ -3,13 +3,19 @@
|
|
| 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 |
* Author: Jos Koenis
|
| 8 |
* License: GPL2
|
| 9 |
*/
|
| 10 |
|
| 11 |
// Change history: see readme.txt
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
defined('ABSPATH') or die();
|
| 15 |
|
|
@@ -25,7 +31,9 @@ if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
|
| 25 |
//PRO
|
| 26 |
@include_once( 'includes/wjecf-pro-controller.php' );
|
| 27 |
@include_once( 'includes/wjecf-pro-free-products.php' );
|
| 28 |
-
@include_once( 'includes/wjecf-pro-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
// Only Initiate the plugin if WooCommerce is active
|
| 31 |
if ( WJECF_Controller::get_woocommerce_version() == false ) {
|
|
@@ -64,6 +72,7 @@ if ( ! function_exists( 'wjecf_load_plugin_textdomain' ) ) {
|
|
| 64 |
WJECF()->add_plugin('WJECF_AutoCoupon');
|
| 65 |
WJECF()->add_plugin('WJECF_WPML');
|
| 66 |
WJECF()->add_plugin('WJECF_Pro_Free_Products');
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
}
|
| 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.4
|
| 7 |
* Author: Jos Koenis
|
| 8 |
* License: GPL2
|
| 9 |
*/
|
| 10 |
|
| 11 |
// Change history: see readme.txt
|
| 12 |
+
/*
|
| 13 |
+
* TODO: Apply filter for autocoupon individual_use_filter
|
| 14 |
+
* TODO: (PRO) Eval
|
| 15 |
+
* TODO: Admin page: Option to enable/disable functionality
|
| 16 |
+
* TODO: Admin page: Enable/disable debugging
|
| 17 |
+
*
|
| 18 |
+
*/
|
| 19 |
|
| 20 |
defined('ABSPATH') or die();
|
| 21 |
|
| 31 |
//PRO
|
| 32 |
@include_once( 'includes/wjecf-pro-controller.php' );
|
| 33 |
@include_once( 'includes/wjecf-pro-free-products.php' );
|
| 34 |
+
@include_once( 'includes/wjecf-pro-coupon-queueing.php' );
|
| 35 |
+
@include_once( 'includes/wjecf-pro-api.php' );
|
| 36 |
+
|
| 37 |
|
| 38 |
// Only Initiate the plugin if WooCommerce is active
|
| 39 |
if ( WJECF_Controller::get_woocommerce_version() == false ) {
|
| 72 |
WJECF()->add_plugin('WJECF_AutoCoupon');
|
| 73 |
WJECF()->add_plugin('WJECF_WPML');
|
| 74 |
WJECF()->add_plugin('WJECF_Pro_Free_Products');
|
| 75 |
+
WJECF()->add_plugin('WJECF_Pro_Coupon_Queueing');
|
| 76 |
}
|
| 77 |
|
| 78 |
}
|
