WooCommerce Bulk Discount - Version 2.0.4

Version Description

  • (11 Sep 2013) Bugfix release.
Download this release

Release Info

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

Code changes from version 2.0.3 to 2.0.4

Files changed (2) hide show
  1. readme.txt +7 -1
  2. woocommerce-bulk-discount.php +10 -7
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_butt
4
  Tags: woocommerce, bulk, discount
5
  Requires at least: 3.5
6
  Tested up to: 3.6
7
- Stable tag: 2.0.3
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -129,6 +129,9 @@ Setting bulk discounts couldn't have been easier.
129
 
130
  == Changelog ==
131
 
 
 
 
132
  = 2.0.3 =
133
  * (11 Sep 2013) Bugfix release.
134
 
@@ -177,6 +180,9 @@ Setting bulk discounts couldn't have been easier.
177
 
178
  == Upgrade Notice ==
179
 
 
 
 
180
  = 2.0.3 =
181
  Bugfix release. Please update immediately.
182
 
4
  Tags: woocommerce, bulk, discount
5
  Requires at least: 3.5
6
  Tested up to: 3.6
7
+ Stable tag: 2.0.4
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
129
 
130
  == Changelog ==
131
 
132
+ = 2.0.4 =
133
+ * (11 Sep 2013) Bugfix release.
134
+
135
  = 2.0.3 =
136
  * (11 Sep 2013) Bugfix release.
137
 
180
 
181
  == Upgrade Notice ==
182
 
183
+ = 2.0.4 =
184
+ Bugfix release. Please update immediately.
185
+
186
  = 2.0.3 =
187
  Bugfix release. Please update immediately.
188
 
woocommerce-bulk-discount.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WooCommerce Bulk Discount
4
  Plugin URI: http://www.tools4me.net/wordpress/woocommerce-bulk-discount-plugin
5
  Description: Apply fine-grained bulk discounts to items in the shopping cart.
6
  Author: Rene Puchinger
7
- Version: 2.0.3
8
  Author URI: http://www.renepuchinger.com
9
  License: GPL3
10
 
@@ -117,9 +117,9 @@ if (!class_exists('Woo_Bulk_Discount_Plugin_t4m')) {
117
  for ($i = 1; $i <= 5; $i++) {
118
  array_push($q, get_post_meta($product_id, "_bulkdiscount_quantity_$i", true));
119
  if (get_option('woocommerce_t4m_discount_type', '') == 'flat') {
120
- array_push($d, get_post_meta($product_id, "_bulkdiscount_discount_flat_$i", true));
121
  } else {
122
- array_push($d, get_post_meta($product_id, "_bulkdiscount_discount_$i", true));
123
  }
124
  if ($quantity >= $q[$i] && $q[$i] > $q[0]) {
125
  $q[0] = $q[$i];
@@ -127,7 +127,7 @@ if (!class_exists('Woo_Bulk_Discount_Plugin_t4m')) {
127
  }
128
  }
129
  // for percentage discount convert the resulting discount from % to the multiplying coefficient
130
- return (get_option('woocommerce_t4m_discount_type', '') == 'flat') ? max(0, $d[0]) : min(100, max(0, (100.0 - $d[0]) / 100.0));
131
  }
132
 
133
  /**
@@ -232,16 +232,19 @@ if (!class_exists('Woo_Bulk_Discount_Plugin_t4m')) {
232
  {
233
  global $woocommerce;
234
  $_product = get_product($values['product_id']);
 
 
 
235
  $discount_coeffs = $this->gather_discount_coeffs_from_order($order->id);
236
- if (!$discount_coeffs) {
237
  return $price;
238
  }
239
- $coeff = $discount_coeffs[$this->get_actual_id($_product)]['coeff'];
240
  $discount_type = get_post_meta($order->id, '_woocommerce_t4m_discount_type', true);
241
  if (( $discount_type == 'flat' && $coeff == 0 ) || ($discount_type == '' && $coeff == 1.0 ) ) {
242
  return $price; // no price modification
243
  }
244
- $oldprice = woocommerce_price($discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
245
  $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
246
  $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
247
  $bulk_info = sprintf(__('Incl. %s discount', 'wc_bulk_discount'), ($discount_type == 'flat' ? get_woocommerce_currency_symbol() . $coeff : (round((1 - $coeff) * 100) . "%")));
4
  Plugin URI: http://www.tools4me.net/wordpress/woocommerce-bulk-discount-plugin
5
  Description: Apply fine-grained bulk discounts to items in the shopping cart.
6
  Author: Rene Puchinger
7
+ Version: 2.0.4
8
  Author URI: http://www.renepuchinger.com
9
  License: GPL3
10
 
117
  for ($i = 1; $i <= 5; $i++) {
118
  array_push($q, get_post_meta($product_id, "_bulkdiscount_quantity_$i", true));
119
  if (get_option('woocommerce_t4m_discount_type', '') == 'flat') {
120
+ array_push($d, get_post_meta($product_id, "_bulkdiscount_discount_flat_$i", true) ? get_post_meta($product_id, "_bulkdiscount_discount_flat_$i", true) : 0.0);
121
  } else {
122
+ array_push($d, get_post_meta($product_id, "_bulkdiscount_discount_$i", true) ? get_post_meta($product_id, "_bulkdiscount_discount_$i", true) : 0.0);
123
  }
124
  if ($quantity >= $q[$i] && $q[$i] > $q[0]) {
125
  $q[0] = $q[$i];
127
  }
128
  }
129
  // for percentage discount convert the resulting discount from % to the multiplying coefficient
130
+ return (get_option('woocommerce_t4m_discount_type', '') == 'flat') ? max(0, $d[0]) : min(1.0, max(0, (100.0 - $d[0]) / 100.0));
131
  }
132
 
133
  /**
232
  {
233
  global $woocommerce;
234
  $_product = get_product($values['product_id']);
235
+ if ($_product && $_product instanceof WC_Product_Variable && $values['variation_id']) {
236
+ $actual_id = $values['variation_id'];
237
+ }
238
  $discount_coeffs = $this->gather_discount_coeffs_from_order($order->id);
239
+ if (empty($discount_coeffs)) {
240
  return $price;
241
  }
242
+ $coeff = $discount_coeffs[$actual_id]['coeff'];
243
  $discount_type = get_post_meta($order->id, '_woocommerce_t4m_discount_type', true);
244
  if (( $discount_type == 'flat' && $coeff == 0 ) || ($discount_type == '' && $coeff == 1.0 ) ) {
245
  return $price; // no price modification
246
  }
247
+ $oldprice = woocommerce_price($discount_coeffs[$actual_id]['orig_price']);
248
  $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
249
  $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
250
  $bulk_info = sprintf(__('Incl. %s discount', 'wc_bulk_discount'), ($discount_type == 'flat' ? get_woocommerce_currency_symbol() . $coeff : (round((1 - $coeff) * 100) . "%")));