WooCommerce Bulk Discount - Version 2.2

Version Description

  • (22 Feb 2013) WooCommerce 2.1 compatibility issues resolved.
Download this release

Release Info

Developer Rene Puchinger
Plugin Icon 128x128 WooCommerce Bulk Discount
Version 2.2
Comparing to
See all releases

Code changes from version 2.1.5 to 2.2

Files changed (2) hide show
  1. readme.txt +13 -5
  2. woocommerce-bulk-discount.php +71 -4
readme.txt CHANGED
@@ -3,19 +3,19 @@ Contributors: Rene Puchinger
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6VEQ8XXK6B3UE
4
  Tags: woocommerce, bulk, discount
5
  Requires at least: 3.5
6
- Tested up to: 3.8
7
- Stable tag: 2.1.5
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
11
- Apply fine-grained bulk discounts to items in the shopping cart with this WooCommerce extension. Enjoy version 2.1 with new features!
12
 
13
  == Description ==
14
 
15
  WooCommerce Bulk Discount makes it possible to apply fine-grained bulk discounts to items in the shopping cart,
16
  depending on the ordered quantity and on the specific product.
17
 
18
- **WooCommerce 2.0.x is required. The plugin is not compatible with WooCommerce 2.1+**
19
 
20
  Let us examine some examples of usage.
21
 
@@ -48,6 +48,7 @@ Here is the list of the main features:
48
  * Bulk discount can or cannot be applied if a coupon code is used, depending on configuration. **Updated in 2.1.5**
49
  * HTML markup is allowed in information about the bulk discount offer in Product Description. **New in 2.1**
50
  * Bulk Discount can be disabled more easily in the Product Options page. **New in 2.1**
 
51
 
52
  WooCommerce Bulk Discount has been localised to these languages:
53
 
@@ -59,9 +60,10 @@ WooCommerce Bulk Discount has been localised to these languages:
59
  **Check out these premium WooCommerce extensions:**
60
 
61
  * <a href="http://codecanyon.net/item/woocommerce-free-gift/6144902?ref=renp">WooCommerce Free Gift</a>
62
- * <a href="http://codecanyon.net/item/woocommerce-minute-discounts-on-crosssells/6337331?ref=renp">WooCommerce Minute Discounts on Cross-sells</a>
63
  * <a href="http://codecanyon.net/item/woocommerce-gift-coupons/6207561?ref=renp">WooCommerce Gift Coupons</a>
64
  * <a href="http://codecanyon.net/item/woocommerce-add-custom-quantity-to-cart/6360685?ref=renp">WooCommerce Add Custom Quantity to Cart</a>
 
 
65
 
66
  == Installation ==
67
 
@@ -144,6 +146,9 @@ Setting bulk discounts couldn't have been easier.
144
 
145
  == Changelog ==
146
 
 
 
 
147
  = 2.1.5 =
148
  * (7 Dec 2013) It is now possible to disable the feature of removing bulk discounts when a coupon code is applied.
149
  * Minor code cleanup and optimization.
@@ -245,6 +250,9 @@ Setting bulk discounts couldn't have been easier.
245
 
246
  == Upgrade Notice ==
247
 
 
 
 
248
  = 2.1.5 =
249
  Maintenance release.
250
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=6VEQ8XXK6B3UE
4
  Tags: woocommerce, bulk, discount
5
  Requires at least: 3.5
6
+ Tested up to: 3.9
7
+ Stable tag: 2.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
11
+ Apply fine-grained bulk discounts to items in the shopping cart with this WooCommerce extension. Now compatible with WooCommerce 2.1!
12
 
13
  == Description ==
14
 
15
  WooCommerce Bulk Discount makes it possible to apply fine-grained bulk discounts to items in the shopping cart,
16
  depending on the ordered quantity and on the specific product.
17
 
18
+ WooCommerce Bulk Discount is compatible with WooCommerce 2.0+ AND 2.1+.
19
 
20
  Let us examine some examples of usage.
21
 
48
  * Bulk discount can or cannot be applied if a coupon code is used, depending on configuration. **Updated in 2.1.5**
49
  * HTML markup is allowed in information about the bulk discount offer in Product Description. **New in 2.1**
50
  * Bulk Discount can be disabled more easily in the Product Options page. **New in 2.1**
51
+ * Compatibility with WooCommerce 2.1. **New in 2.2**
52
 
53
  WooCommerce Bulk Discount has been localised to these languages:
54
 
60
  **Check out these premium WooCommerce extensions:**
61
 
62
  * <a href="http://codecanyon.net/item/woocommerce-free-gift/6144902?ref=renp">WooCommerce Free Gift</a>
 
63
  * <a href="http://codecanyon.net/item/woocommerce-gift-coupons/6207561?ref=renp">WooCommerce Gift Coupons</a>
64
  * <a href="http://codecanyon.net/item/woocommerce-add-custom-quantity-to-cart/6360685?ref=renp">WooCommerce Add Custom Quantity to Cart</a>
65
+ * <a href="http://codecanyon.net/item/woocommerce-minute-discounts-on-crosssells/6337331?ref=renp">WooCommerce Minute Discounts on Cross-sells</a>
66
+ * <a href="http://codecanyon.net/item/woocommerce-better-stock-overview/8376601?ref=renp">WooCommerce Better Stock Overview</a>
67
 
68
  == Installation ==
69
 
146
 
147
  == Changelog ==
148
 
149
+ = 2.2 =
150
+ * (22 Feb 2013) WooCommerce 2.1 compatibility issues resolved.
151
+
152
  = 2.1.5 =
153
  * (7 Dec 2013) It is now possible to disable the feature of removing bulk discounts when a coupon code is applied.
154
  * Minor code cleanup and optimization.
250
 
251
  == Upgrade Notice ==
252
 
253
+ = 2.2 =
254
+ Maintenance release.
255
+
256
  = 2.1.5 =
257
  Maintenance release.
258
 
woocommerce-bulk-discount.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /*
3
  Plugin Name: WooCommerce Bulk Discount
4
- Plugin URI: http://www.renepuchinger.com
5
  Description: Apply fine-grained bulk discounts to items in the shopping cart.
6
  Author: Rene Puchinger
7
- Version: 2.1.5
8
  Author URI: http://www.renepuchinger.com
9
  License: GPL3
10
 
@@ -34,6 +34,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
34
  class Woo_Bulk_Discount_Plugin_t4m {
35
 
36
  var $discount_coeffs;
 
37
 
38
  public function __construct() {
39
 
@@ -71,11 +72,11 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
71
  public function woocommerce_loaded() {
72
 
73
  if ( get_option( 'woocommerce_t4m_enable_bulk_discounts', 'yes' ) == 'yes' ) {
 
74
  add_action( 'woocommerce_before_calculate_totals', array( $this, 'action_before_calculate' ), 10, 1 );
75
  add_action( 'woocommerce_calculate_totals', array( $this, 'action_after_calculate' ), 10, 1 );
76
  add_action( 'woocommerce_before_cart_table', array( $this, 'before_cart_table' ) );
77
  add_action( 'woocommerce_single_product_summary', array( $this, 'single_product_summary' ), 45 );
78
- add_filter( 'woocommerce_cart_item_price_html', array( $this, 'filter_item_price' ), 10, 2 );
79
  add_filter( 'woocommerce_cart_item_subtotal', array( $this, 'filter_subtotal_price' ), 10, 2 );
80
  add_filter( 'woocommerce_checkout_item_subtotal', array( $this, 'filter_subtotal_price' ), 10, 2 );
81
  add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this, 'filter_subtotal_order_price' ), 10, 3 );
@@ -84,6 +85,14 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
84
  add_action( 'woocommerce_process_product_meta', array( $this, 'action_process_meta' ) );
85
  add_filter( 'woocommerce_cart_product_subtotal', array( $this, 'filter_cart_product_subtotal' ), 10, 3 );
86
  add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_update_meta' ) );
 
 
 
 
 
 
 
 
87
  }
88
 
89
  }
@@ -330,9 +339,52 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
330
  return;
331
  }
332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  $this->gather_discount_coeffs();
334
 
335
  if ( sizeof( $cart->cart_contents ) > 0 ) {
 
336
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
337
  $_product = $values['data'];
338
  if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
@@ -346,8 +398,13 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
346
 
347
  $values['data']->set_price( $row_base_price );
348
  }
 
 
 
349
  }
350
 
 
 
351
  }
352
 
353
  /**
@@ -462,14 +519,24 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
462
  * Add entry to Product Settings.
463
  */
464
  public function action_product_write_panel_tabs() {
465
- echo '<li class="bulkdiscount_tab bulkdiscount_options"><a href="#bulkdiscount_product_data">' . __( 'Bulk Discount', 'wc_bulk_discount' ) . '</a></li>';
 
 
 
 
 
 
 
 
466
  }
467
 
468
  /**
469
  * Add entry content to Product Settings.
470
  */
471
  public function action_product_write_panels() {
 
472
  global $thepostid, $post;
 
473
  if ( !$thepostid ) $thepostid = $post->ID;
474
  ?>
475
  <script type="text/javascript">
1
  <?php
2
  /*
3
  Plugin Name: WooCommerce Bulk Discount
4
+ Plugin URI: http://wordpress.org/plugins/woocommerce-bulk-discount/
5
  Description: Apply fine-grained bulk discounts to items in the shopping cart.
6
  Author: Rene Puchinger
7
+ Version: 2.2
8
  Author URI: http://www.renepuchinger.com
9
  License: GPL3
10
 
34
  class Woo_Bulk_Discount_Plugin_t4m {
35
 
36
  var $discount_coeffs;
37
+ var $bulk_discount_calculated = false;
38
 
39
  public function __construct() {
40
 
72
  public function woocommerce_loaded() {
73
 
74
  if ( get_option( 'woocommerce_t4m_enable_bulk_discounts', 'yes' ) == 'yes' ) {
75
+
76
  add_action( 'woocommerce_before_calculate_totals', array( $this, 'action_before_calculate' ), 10, 1 );
77
  add_action( 'woocommerce_calculate_totals', array( $this, 'action_after_calculate' ), 10, 1 );
78
  add_action( 'woocommerce_before_cart_table', array( $this, 'before_cart_table' ) );
79
  add_action( 'woocommerce_single_product_summary', array( $this, 'single_product_summary' ), 45 );
 
80
  add_filter( 'woocommerce_cart_item_subtotal', array( $this, 'filter_subtotal_price' ), 10, 2 );
81
  add_filter( 'woocommerce_checkout_item_subtotal', array( $this, 'filter_subtotal_price' ), 10, 2 );
82
  add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this, 'filter_subtotal_order_price' ), 10, 3 );
85
  add_action( 'woocommerce_process_product_meta', array( $this, 'action_process_meta' ) );
86
  add_filter( 'woocommerce_cart_product_subtotal', array( $this, 'filter_cart_product_subtotal' ), 10, 3 );
87
  add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_update_meta' ) );
88
+
89
+ if ( version_compare( WOOCOMMERCE_VERSION, "2.1.0" ) >= 0 ) {
90
+ add_filter( 'woocommerce_cart_item_price', array( $this, 'filter_item_price' ), 10, 2 );
91
+ add_filter( 'woocommerce_update_cart_validation', array( $this, 'filter_before_calculate' ), 10, 1 );
92
+ } else {
93
+ add_filter( 'woocommerce_cart_item_price_html', array( $this, 'filter_item_price' ), 10, 2 );
94
+ }
95
+
96
  }
97
 
98
  }
339
  return;
340
  }
341
 
342
+ if ($this->bulk_discount_calculated) {
343
+ return;
344
+ }
345
+
346
+ $this->gather_discount_coeffs();
347
+
348
+ if ( sizeof( $cart->cart_contents ) > 0 ) {
349
+
350
+ foreach ( $cart->cart_contents as $cart_item_key => $values ) {
351
+ $_product = $values['data'];
352
+ if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
353
+ continue;
354
+ }
355
+ if ( ( get_option( 'woocommerce_t4m_discount_type', '' ) == 'flat' ) ) {
356
+ $row_base_price = max( 0, $_product->get_price() - ( $this->discount_coeffs[$this->get_actual_id( $_product )]['coeff'] / $values['quantity'] ) );
357
+ } else {
358
+ $row_base_price = $_product->get_price() * $this->discount_coeffs[$this->get_actual_id( $_product )]['coeff'];
359
+ }
360
+
361
+ $values['data']->set_price( $row_base_price );
362
+ }
363
+
364
+ $this->bulk_discount_calculated = true;
365
+
366
+ }
367
+
368
+ }
369
+
370
+ public function filter_before_calculate( $res ) {
371
+
372
+ global $woocommerce;
373
+
374
+ if ($this->bulk_discount_calculated) {
375
+ return $res;
376
+ }
377
+
378
+ $cart = $woocommerce->cart;
379
+
380
+ if ( $this->coupon_check() ) {
381
+ return $res;
382
+ }
383
+
384
  $this->gather_discount_coeffs();
385
 
386
  if ( sizeof( $cart->cart_contents ) > 0 ) {
387
+
388
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
389
  $_product = $values['data'];
390
  if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
398
 
399
  $values['data']->set_price( $row_base_price );
400
  }
401
+
402
+ $this->bulk_discount_calculated = true;
403
+
404
  }
405
 
406
+ return $res;
407
+
408
  }
409
 
410
  /**
519
  * Add entry to Product Settings.
520
  */
521
  public function action_product_write_panel_tabs() {
522
+
523
+ $style = '';
524
+
525
+ if ( version_compare( WOOCOMMERCE_VERSION, "2.1.0" ) >= 0 ) {
526
+ $style = 'style = "padding: 10px !important"';
527
+ }
528
+
529
+ echo '<li class="bulkdiscount_tab bulkdiscount_options"><a href="#bulkdiscount_product_data" '.$style.'>' . __( 'Bulk Discount', 'wc_bulk_discount' ) . '</a></li>';
530
+
531
  }
532
 
533
  /**
534
  * Add entry content to Product Settings.
535
  */
536
  public function action_product_write_panels() {
537
+
538
  global $thepostid, $post;
539
+
540
  if ( !$thepostid ) $thepostid = $post->ID;
541
  ?>
542
  <script type="text/javascript">