WooCommerce Bulk Discount - Version 2.4.3

Version Description

  • (17 Feb 2017) Making the plugin compatible with WooCommerce 2.7.
Download this release

Release Info

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

Code changes from version 2.4.2 to 2.4.3

Files changed (2) hide show
  1. readme.txt +6 -3
  2. woocommerce-bulk-discount.php +25 -14
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.6
6
- Tested up to: 4.5.2
7
- Stable tag: 2.4.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -15,7 +15,7 @@ Apply fine-grained bulk discounts to items in the shopping cart.
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.x to 2.6.x.**
19
 
20
  Let us examine some examples of usage.
21
 
@@ -165,6 +165,9 @@ In the bulk discount section of this private product set the discount as in the
165
 
166
  == Changelog ==
167
 
 
 
 
168
  = 2.4.2 =
169
  * (25 May 2016) Testing the plugin with WooCommerce 2.6.
170
  * Added another type of discount - check carefully the FAQ section to learn the differences between the supported discount types: percentage, flat and fixed.
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.6
6
+ Tested up to: 4.7.2
7
+ Stable tag: 2.4.3
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
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.x to 2.7.x.**
19
 
20
  Let us examine some examples of usage.
21
 
165
 
166
  == Changelog ==
167
 
168
+ = 2.4.3 =
169
+ * (17 Feb 2017) Making the plugin compatible with WooCommerce 2.7.
170
+
171
  = 2.4.2 =
172
  * (25 May 2016) Testing the plugin with WooCommerce 2.6.
173
  * Added another type of discount - check carefully the FAQ section to learn the differences between the supported discount types: percentage, flat and fixed.
woocommerce-bulk-discount.php CHANGED
@@ -4,7 +4,7 @@ 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.4.2
8
  Author URI: https://profiles.wordpress.org/rene-puchinger/
9
  License: GPL3
10
 
@@ -79,7 +79,11 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
79
  add_filter( 'woocommerce_checkout_item_subtotal', array( $this, 'filter_subtotal_price' ), 10, 2 );
80
  add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this, 'filter_subtotal_order_price' ), 10, 3 );
81
  add_filter( 'woocommerce_product_write_panel_tabs', array( $this, 'action_product_write_panel_tabs' ) );
82
- add_filter( 'woocommerce_product_write_panels', array( $this, 'action_product_write_panels' ) );
 
 
 
 
83
  add_action( 'woocommerce_process_product_meta', array( $this, 'action_process_meta' ) );
84
  add_filter( 'woocommerce_cart_product_subtotal', array( $this, 'filter_cart_product_subtotal' ), 10, 3 );
85
  add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_update_meta' ) );
@@ -174,7 +178,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
174
  return $price;
175
  }
176
  $_product = $values['data'];
177
- if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
178
  return $price;
179
  }
180
  if ( ( get_option( 'woocommerce_t4m_show_on_item', 'yes' ) == 'no' ) ) {
@@ -237,7 +241,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
237
  return $price;
238
  }
239
  $_product = $values['data'];
240
- if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
241
  return $price;
242
  }
243
  if ( ( get_option( 'woocommerce_t4m_show_on_subtotal', 'yes' ) == 'no' ) ) {
@@ -279,7 +283,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
279
  $parent = $_product->parent;
280
  foreach ( $cart->cart_contents as $valuesInner ) {
281
  $p = $valuesInner['data'];
282
- if ( $p instanceof WC_Product_Variation && $p->parent && $p->parent->id == $parent->id ) {
283
  $quantity += $valuesInner['quantity'];
284
  $this->discount_coeffs[$_product->variation_id]['quantity'] = $quantity;
285
  }
@@ -287,7 +291,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
287
  } else {
288
  $quantity = $values['quantity'];
289
  }
290
- $this->discount_coeffs[$this->get_actual_id( $_product )]['coeff'] = $this->get_discounted_coeff( $_product->id, $quantity );
291
  $this->discount_coeffs[$this->get_actual_id( $_product )]['orig_price'] = $_product->get_price();
292
  $this->discount_coeffs[$this->get_actual_id( $_product )]['quantity'] = $quantity;
293
  }
@@ -322,7 +326,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
322
  if ( $_product && $_product instanceof WC_Product_Variable && $values['variation_id'] ) {
323
  $actual_id = $values['variation_id'];
324
  }
325
- $discount_coeffs = $this->gather_discount_coeffs_from_order( $order->id );
326
  if ( empty( $discount_coeffs ) ) {
327
  return $price;
328
  }
@@ -330,7 +334,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
330
  if ( !$coeff ) {
331
  return $price;
332
  }
333
- $discount_type = get_post_meta( $order->id, '_woocommerce_t4m_discount_type', true );
334
  if ( ( $discount_type == 'flat' && $coeff == 0 ) || ( $discount_type == 'fixed' && $coeff == 0 ) || ( $discount_type == '' && $coeff == 1.0 ) ) {
335
  return $price; // no price modification
336
  }
@@ -383,7 +387,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
383
 
384
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
385
  $_product = $values['data'];
386
- if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
387
  continue;
388
  }
389
  if ( ( get_option( 'woocommerce_t4m_discount_type', '' ) == 'flat' ) ) {
@@ -423,7 +427,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
423
 
424
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
425
  $_product = $values['data'];
426
- if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
427
  continue;
428
  }
429
  if ( ( get_option( 'woocommerce_t4m_discount_type', '' ) == 'flat' ) ) {
@@ -454,7 +458,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
454
  if ( $product instanceof WC_Product_Variation ) {
455
  return $product->variation_id;
456
  } else {
457
- return $product->id;
458
  }
459
 
460
  }
@@ -477,7 +481,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
477
  if ( sizeof( $cart->cart_contents ) > 0 ) {
478
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
479
  $_product = $values['data'];
480
- if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
481
  continue;
482
  }
483
  $values['data']->set_price( $this->discount_coeffs[$this->get_actual_id( $_product )]['orig_price'] );
@@ -517,7 +521,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
517
  if ( $this->coupon_check() ) {
518
  return $subtotal;
519
  }
520
- if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
521
  return $subtotal;
522
  }
523
 
@@ -868,7 +872,7 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
868
  array(
869
  'title' => __( 'Discount Type', 'wc_bulk_discount' ),
870
  'id' => 'woocommerce_t4m_discount_type',
871
- 'desc' => sprintf( __( 'Select the type of discount. Percentage discount deducts amount of %% from the price while flat and fixed discounts deducts fixed amount in %s', 'wc_bulk_discount' ), get_woocommerce_currency_symbol() ),
872
  'desc_tip' => true,
873
  'std' => 'yes',
874
  'type' => 'select',
@@ -989,6 +993,13 @@ if ( !class_exists( 'Woo_Bulk_Discount_Plugin_t4m' ) ) {
989
  return !( empty( $woocommerce->cart->applied_coupons ) );
990
  }
991
 
 
 
 
 
 
 
 
992
  }
993
 
994
  new Woo_Bulk_Discount_Plugin_t4m();
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.4.3
8
  Author URI: https://profiles.wordpress.org/rene-puchinger/
9
  License: GPL3
10
 
79
  add_filter( 'woocommerce_checkout_item_subtotal', array( $this, 'filter_subtotal_price' ), 10, 2 );
80
  add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this, 'filter_subtotal_order_price' ), 10, 3 );
81
  add_filter( 'woocommerce_product_write_panel_tabs', array( $this, 'action_product_write_panel_tabs' ) );
82
+ if ( version_compare( WOOCOMMERCE_VERSION, "2.7.0" ) >= 0 ) {
83
+ add_filter( 'woocommerce_product_data_panels', array( $this, 'action_product_write_panels' ) );
84
+ } else {
85
+ add_filter( 'woocommerce_product_write_panels', array( $this, 'action_product_write_panels' ) );
86
+ }
87
  add_action( 'woocommerce_process_product_meta', array( $this, 'action_process_meta' ) );
88
  add_filter( 'woocommerce_cart_product_subtotal', array( $this, 'filter_cart_product_subtotal' ), 10, 3 );
89
  add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_update_meta' ) );
178
  return $price;
179
  }
180
  $_product = $values['data'];
181
+ if ( get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) != '' && get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) !== 'yes' ) {
182
  return $price;
183
  }
184
  if ( ( get_option( 'woocommerce_t4m_show_on_item', 'yes' ) == 'no' ) ) {
241
  return $price;
242
  }
243
  $_product = $values['data'];
244
+ if ( get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) != '' && get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) !== 'yes' ) {
245
  return $price;
246
  }
247
  if ( ( get_option( 'woocommerce_t4m_show_on_subtotal', 'yes' ) == 'no' ) ) {
283
  $parent = $_product->parent;
284
  foreach ( $cart->cart_contents as $valuesInner ) {
285
  $p = $valuesInner['data'];
286
+ if ( $p instanceof WC_Product_Variation && $p->parent && $this->get_product_id($p->parent) == $this->get_product_id($parent) ) {
287
  $quantity += $valuesInner['quantity'];
288
  $this->discount_coeffs[$_product->variation_id]['quantity'] = $quantity;
289
  }
291
  } else {
292
  $quantity = $values['quantity'];
293
  }
294
+ $this->discount_coeffs[$this->get_actual_id( $_product )]['coeff'] = $this->get_discounted_coeff( $this->get_product_id($_product), $quantity );
295
  $this->discount_coeffs[$this->get_actual_id( $_product )]['orig_price'] = $_product->get_price();
296
  $this->discount_coeffs[$this->get_actual_id( $_product )]['quantity'] = $quantity;
297
  }
326
  if ( $_product && $_product instanceof WC_Product_Variable && $values['variation_id'] ) {
327
  $actual_id = $values['variation_id'];
328
  }
329
+ $discount_coeffs = $this->gather_discount_coeffs_from_order( $this->get_product_id($order) );
330
  if ( empty( $discount_coeffs ) ) {
331
  return $price;
332
  }
334
  if ( !$coeff ) {
335
  return $price;
336
  }
337
+ $discount_type = get_post_meta( $this->get_product_id($order), '_woocommerce_t4m_discount_type', true );
338
  if ( ( $discount_type == 'flat' && $coeff == 0 ) || ( $discount_type == 'fixed' && $coeff == 0 ) || ( $discount_type == '' && $coeff == 1.0 ) ) {
339
  return $price; // no price modification
340
  }
387
 
388
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
389
  $_product = $values['data'];
390
+ if ( get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) != '' && get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) !== 'yes' ) {
391
  continue;
392
  }
393
  if ( ( get_option( 'woocommerce_t4m_discount_type', '' ) == 'flat' ) ) {
427
 
428
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
429
  $_product = $values['data'];
430
+ if ( get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) != '' && get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) !== 'yes' ) {
431
  continue;
432
  }
433
  if ( ( get_option( 'woocommerce_t4m_discount_type', '' ) == 'flat' ) ) {
458
  if ( $product instanceof WC_Product_Variation ) {
459
  return $product->variation_id;
460
  } else {
461
+ return $this->get_product_id($product);
462
  }
463
 
464
  }
481
  if ( sizeof( $cart->cart_contents ) > 0 ) {
482
  foreach ( $cart->cart_contents as $cart_item_key => $values ) {
483
  $_product = $values['data'];
484
+ if ( get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) != '' && get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) !== 'yes' ) {
485
  continue;
486
  }
487
  $values['data']->set_price( $this->discount_coeffs[$this->get_actual_id( $_product )]['orig_price'] );
521
  if ( $this->coupon_check() ) {
522
  return $subtotal;
523
  }
524
+ if ( get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) != '' && get_post_meta( $this->get_product_id($_product), "_bulkdiscount_enabled", true ) !== 'yes' ) {
525
  return $subtotal;
526
  }
527
 
872
  array(
873
  'title' => __( 'Discount Type', 'wc_bulk_discount' ),
874
  'id' => 'woocommerce_t4m_discount_type',
875
+ 'desc' => sprintf( __( 'Select the type of discount. Percentage discount deducts amount of %% from the price while flat and fixed discounts deducts fixed amount in %s', 'wc_bulk_discount' ), get_woocommerce_currency_symbol() ) . '. PLEASE READ THE DOCUMENTATION CAREFULLY.',
876
  'desc_tip' => true,
877
  'std' => 'yes',
878
  'type' => 'select',
993
  return !( empty( $woocommerce->cart->applied_coupons ) );
994
  }
995
 
996
+ protected function get_product_id($_product) {
997
+ if ( version_compare( WOOCOMMERCE_VERSION, "2.7.0" ) >= 0 ) {
998
+ return $_product->get_id();
999
+ }
1000
+ return $_product->id;
1001
+ }
1002
+
1003
  }
1004
 
1005
  new Woo_Bulk_Discount_Plugin_t4m();