WooCommerce Bulk Discount - Version 2.0.9

Version Description

  • (9 Oct 2013) Translations updated.
  • Minor code formatting changes.
Download this release

Release Info

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

Code changes from version 2.0.8 to 2.0.9

lang/wc_bulk_discount-pt_PT.mo CHANGED
Binary file
lang/wc_bulk_discount-pt_PT.po CHANGED
@@ -6,8 +6,8 @@ msgid ""
6
  msgstr ""
7
  "Project-Id-Version: WooCommerce Bulk Discount v2.0.5\n"
8
  "Report-Msgid-Bugs-To: jpBenfic@<jp.jp@sapo.pt>\n"
9
- "POT-Creation-Date: yyyy-mm-dd hh:mm+0000\n"
10
- "PO-Revision-Date: 2013-09-12 10:24+0\n"
11
  "Last-Translator: jpBenfica <jp.jp@sapo.pt>\n"
12
  "Language-Team: Portuguese <jp.jp@sapo.pt>\n"
13
  "Language: Portuguese\n"
@@ -15,56 +15,65 @@ msgstr ""
15
  "Content-Type: text/plain; charset=UTF-8\n"
16
  "Content-Transfer-Encoding: 8bit\n"
17
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
18
- "X-Generator: Easy Po 0.9.4\n"
19
  "X-Poedit-SourceCharset: utf-8\n"
20
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
 
21
  "X-Poedit-Basepath: ../\n"
22
  "X-Poedit-SourceCharset: utf-8\n"
23
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
 
24
  "X-Poedit-Basepath: ../\n"
25
- "X-Poedit-SearchPath-0: .\n"
26
  "X-Poedit-SourceCharset: utf-8\n"
27
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
 
28
  "X-Poedit-Basepath: ../\n"
29
  "X-Poedit-SourceCharset: utf-8\n"
30
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
 
31
  "X-Poedit-Basepath: ../\n"
32
- "X-Poedit-SearchPath-0: .\n"
33
  "X-Poedit-SourceCharset: utf-8\n"
34
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
 
35
  "X-Poedit-Basepath: ../\n"
36
  "X-Poedit-SourceCharset: utf-8\n"
37
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
 
38
  "X-Poedit-Basepath: ../\n"
39
- "X-Poedit-SearchPath-0: .\n"
40
  "X-Poedit-SourceCharset: utf-8\n"
41
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
 
42
  "X-Poedit-Basepath: ../\n"
43
  "X-Poedit-SourceCharset: utf-8\n"
44
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
 
45
  "X-Poedit-Basepath: ../\n"
46
  "X-Poedit-SearchPath-0: .\n"
47
 
48
- #: woocommerce-bulk-discount.php:48 woocommerce-bulk-discount.php:357
49
- #: woocommerce-bulk-discount.php:557
50
  msgid "Bulk Discount"
51
  msgstr "Desconto de quantidade"
52
 
53
- #: woocommerce-bulk-discount.php:141
 
 
 
 
54
  #, php-format
55
- msgid "%d%% bulk discount applied!"
56
- msgstr "%d%% desconto de quantidade aplicado!"
57
 
58
- #: woocommerce-bulk-discount.php:169 woocommerce-bulk-discount.php:224
59
  #, php-format
60
  msgid "Incl. %s discount"
61
  msgstr "Inclui %s desconto"
62
 
63
- #: woocommerce-bulk-discount.php:403
64
  msgid "Bulk discount info in product description"
65
  msgstr "Informação de desconto de quantidade na descrição do produto"
66
 
67
- #: woocommerce-bulk-discount.php:403
68
  msgid ""
69
  "Optionally enter bulk discount information that will be visible on the "
70
  "product page."
@@ -72,38 +81,38 @@ msgstr ""
72
  "Opcionalmente, insira as informações de desconto de quantidade que serão "
73
  "visíveis na página do produto."
74
 
75
- #: woocommerce-bulk-discount.php:417
76
  msgid "Quantity (min.)"
77
  msgstr "Quantidade (min.)"
78
 
79
- #: woocommerce-bulk-discount.php:417
80
  msgid "Enter the minimal quantity for which the discount applies."
81
  msgstr "Introduza a quantidade mínima para a qual se aplica o desconto."
82
 
83
- #: woocommerce-bulk-discount.php:419
84
  #, php-format
85
  msgid "Discount (%s)"
86
  msgstr "Desconto (%s)"
87
 
88
- #: woocommerce-bulk-discount.php:419
89
  #, php-format
90
  msgid "Enter the flat discount in %s."
91
  msgstr "Inserir o desconto fixo em %s."
92
 
93
- #: woocommerce-bulk-discount.php:421
94
  msgid "Discount (%)"
95
  msgstr "Desconto (%)"
96
 
97
- #: woocommerce-bulk-discount.php:421
98
  msgid "Enter the discount in percents (Allowed values: 0 to 100)."
99
  msgstr "Insira o desconto em porcentagens (Valores permitidos: 0 a 100)."
100
 
101
- #: woocommerce-bulk-discount.php:557
102
  msgid "The following options are specific to product bulk discount."
103
  msgstr ""
104
  "As opções a seguir são específicas para o desconto de quantidade de produto."
105
 
106
- #: woocommerce-bulk-discount.php:557
107
  msgid ""
108
  "After changing the settings, it is recommended to clear all sessions in "
109
  "WooCommerce &gt; System Status &gt; Tools."
@@ -111,15 +120,15 @@ msgstr ""
111
  "Depois de alterar as configurações, recomenda-se limpar todas as sessões do "
112
  "WooCommerce &gt; Estado do Sistema &gt; Ferramentas."
113
 
114
- #: woocommerce-bulk-discount.php:560
115
  msgid "Bulk Discount enabled"
116
  msgstr "Desconto de Quantidade habilitado"
117
 
118
- #: woocommerce-bulk-discount.php:569
119
  msgid "Discount Type"
120
  msgstr "Tipo de Desconto"
121
 
122
- #: woocommerce-bulk-discount.php:571
123
  #, php-format
124
  msgid ""
125
  "Select the type of discount. Percentage Discount deducts amount of %% from "
@@ -128,19 +137,19 @@ msgstr ""
128
  "Selecione o tipo de desconto. Desconto Percentual deduz a quantidade de %% "
129
  "do preço enquanto o Desconto Fixo deduz o montante fixo em %s"
130
 
131
- #: woocommerce-bulk-discount.php:578
132
  msgid "Percentage Discount"
133
  msgstr "Desconto Percentual"
134
 
135
- #: woocommerce-bulk-discount.php:579
136
  msgid "Flat Discount"
137
  msgstr "Desconto Fixo"
138
 
139
- #: woocommerce-bulk-discount.php:584
140
  msgid "Treat product variations separately"
141
  msgstr "Tratar as variações do produto separadamente"
142
 
143
- #: woocommerce-bulk-discount.php:586
144
  msgid ""
145
  "You need to have this option unchecked to handle discounts on product "
146
  "variations as a whole."
@@ -148,18 +157,40 @@ msgstr ""
148
  "Você precisa ter esta opção desmarcada para lidar com descontos sobre as "
149
  "variações do produto como um todo."
150
 
151
- #: woocommerce-bulk-discount.php:593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  msgid "Optionally enter information about discounts visible on cart page."
153
  msgstr ""
154
  "Opcionalmente, insira as informações sobre descontos visíveis na página do "
155
  "carrinho."
156
 
157
- #: woocommerce-bulk-discount.php:600
158
  msgid "Optionally change the CSS for old price on cart before discounting."
159
  msgstr ""
160
  "Opcionalmente altere o CSS para preço antigo no carrinho antes de descontar."
161
 
162
- #: woocommerce-bulk-discount.php:608
163
  msgid "Optionally change the CSS for new price on cart after discounting."
164
  msgstr ""
165
- "Opcionalmente, altere o CSS para novo preço no carrinho após descontar."
6
  msgstr ""
7
  "Project-Id-Version: WooCommerce Bulk Discount v2.0.5\n"
8
  "Report-Msgid-Bugs-To: jpBenfic@<jp.jp@sapo.pt>\n"
9
+ "POT-Creation-Date: 2013-10-09 19:17+0100\n"
10
+ "PO-Revision-Date: 2013-10-09 19:19+0100\n"
11
  "Last-Translator: jpBenfica <jp.jp@sapo.pt>\n"
12
  "Language-Team: Portuguese <jp.jp@sapo.pt>\n"
13
  "Language: Portuguese\n"
15
  "Content-Type: text/plain; charset=UTF-8\n"
16
  "Content-Transfer-Encoding: 8bit\n"
17
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
18
+ "X-Generator: Poedit 1.5.7\n"
19
  "X-Poedit-SourceCharset: utf-8\n"
20
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
21
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
22
  "X-Poedit-Basepath: ../\n"
23
  "X-Poedit-SourceCharset: utf-8\n"
24
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
25
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
26
  "X-Poedit-Basepath: ../\n"
 
27
  "X-Poedit-SourceCharset: utf-8\n"
28
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
29
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
30
  "X-Poedit-Basepath: ../\n"
31
  "X-Poedit-SourceCharset: utf-8\n"
32
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
33
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
34
  "X-Poedit-Basepath: ../\n"
 
35
  "X-Poedit-SourceCharset: utf-8\n"
36
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
37
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
38
  "X-Poedit-Basepath: ../\n"
39
  "X-Poedit-SourceCharset: utf-8\n"
40
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
41
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
42
  "X-Poedit-Basepath: ../\n"
 
43
  "X-Poedit-SourceCharset: utf-8\n"
44
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
45
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
46
  "X-Poedit-Basepath: ../\n"
47
  "X-Poedit-SourceCharset: utf-8\n"
48
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
49
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
50
  "X-Poedit-Basepath: ../\n"
51
  "X-Poedit-SearchPath-0: .\n"
52
 
53
+ #: woocommerce-bulk-discount.php:48 woocommerce-bulk-discount.php:387
54
+ #: woocommerce-bulk-discount.php:586
55
  msgid "Bulk Discount"
56
  msgstr "Desconto de quantidade"
57
 
58
+ #: woocommerce-bulk-discount.php:98
59
+ msgid "Settings"
60
+ msgstr "Settings"
61
+
62
+ #: woocommerce-bulk-discount.php:163
63
  #, php-format
64
+ msgid "%s%% bulk discount applied!"
65
+ msgstr "%s%% desconto de quantidade aplicado!"
66
 
67
+ #: woocommerce-bulk-discount.php:194 woocommerce-bulk-discount.php:260
68
  #, php-format
69
  msgid "Incl. %s discount"
70
  msgstr "Inclui %s desconto"
71
 
72
+ #: woocommerce-bulk-discount.php:433
73
  msgid "Bulk discount info in product description"
74
  msgstr "Informação de desconto de quantidade na descrição do produto"
75
 
76
+ #: woocommerce-bulk-discount.php:433
77
  msgid ""
78
  "Optionally enter bulk discount information that will be visible on the "
79
  "product page."
81
  "Opcionalmente, insira as informações de desconto de quantidade que serão "
82
  "visíveis na página do produto."
83
 
84
+ #: woocommerce-bulk-discount.php:447
85
  msgid "Quantity (min.)"
86
  msgstr "Quantidade (min.)"
87
 
88
+ #: woocommerce-bulk-discount.php:447
89
  msgid "Enter the minimal quantity for which the discount applies."
90
  msgstr "Introduza a quantidade mínima para a qual se aplica o desconto."
91
 
92
+ #: woocommerce-bulk-discount.php:449
93
  #, php-format
94
  msgid "Discount (%s)"
95
  msgstr "Desconto (%s)"
96
 
97
+ #: woocommerce-bulk-discount.php:449
98
  #, php-format
99
  msgid "Enter the flat discount in %s."
100
  msgstr "Inserir o desconto fixo em %s."
101
 
102
+ #: woocommerce-bulk-discount.php:451
103
  msgid "Discount (%)"
104
  msgstr "Desconto (%)"
105
 
106
+ #: woocommerce-bulk-discount.php:451
107
  msgid "Enter the discount in percents (Allowed values: 0 to 100)."
108
  msgstr "Insira o desconto em porcentagens (Valores permitidos: 0 a 100)."
109
 
110
+ #: woocommerce-bulk-discount.php:586
111
  msgid "The following options are specific to product bulk discount."
112
  msgstr ""
113
  "As opções a seguir são específicas para o desconto de quantidade de produto."
114
 
115
+ #: woocommerce-bulk-discount.php:586
116
  msgid ""
117
  "After changing the settings, it is recommended to clear all sessions in "
118
  "WooCommerce &gt; System Status &gt; Tools."
120
  "Depois de alterar as configurações, recomenda-se limpar todas as sessões do "
121
  "WooCommerce &gt; Estado do Sistema &gt; Ferramentas."
122
 
123
+ #: woocommerce-bulk-discount.php:589
124
  msgid "Bulk Discount enabled"
125
  msgstr "Desconto de Quantidade habilitado"
126
 
127
+ #: woocommerce-bulk-discount.php:598
128
  msgid "Discount Type"
129
  msgstr "Tipo de Desconto"
130
 
131
+ #: woocommerce-bulk-discount.php:600
132
  #, php-format
133
  msgid ""
134
  "Select the type of discount. Percentage Discount deducts amount of %% from "
137
  "Selecione o tipo de desconto. Desconto Percentual deduz a quantidade de %% "
138
  "do preço enquanto o Desconto Fixo deduz o montante fixo em %s"
139
 
140
+ #: woocommerce-bulk-discount.php:607
141
  msgid "Percentage Discount"
142
  msgstr "Desconto Percentual"
143
 
144
+ #: woocommerce-bulk-discount.php:608
145
  msgid "Flat Discount"
146
  msgstr "Desconto Fixo"
147
 
148
+ #: woocommerce-bulk-discount.php:613
149
  msgid "Treat product variations separately"
150
  msgstr "Tratar as variações do produto separadamente"
151
 
152
+ #: woocommerce-bulk-discount.php:615
153
  msgid ""
154
  "You need to have this option unchecked to handle discounts on product "
155
  "variations as a whole."
157
  "Você precisa ter esta opção desmarcada para lidar com descontos sobre as "
158
  "variações do produto como um todo."
159
 
160
+ #: woocommerce-bulk-discount.php:622
161
+ msgid "Show discount information next to cart item price"
162
+ msgstr "Mostrar informação de desconto junto ao preço do item no carrinho"
163
+
164
+ #: woocommerce-bulk-discount.php:624
165
+ msgid "Applies only to percentage discount."
166
+ msgstr "Aplica-se somente ao desconto percentual."
167
+
168
+ #: woocommerce-bulk-discount.php:631
169
+ msgid "Show discount information next to item subtotal price"
170
+ msgstr "Mostrar informação de desconto junto ao item preço subtotal"
171
+
172
+ #: woocommerce-bulk-discount.php:639
173
+ msgid "Show discount information next to item subtotal price in order history"
174
+ msgstr ""
175
+ "Mostrar informação de desconto junto ao item preço subtotal no histórico de "
176
+ "pedidos"
177
+
178
+ #: woocommerce-bulk-discount.php:641
179
+ msgid "Includes showing discount in order e-mails and invoices."
180
+ msgstr "Mostra o desconto em pedidos de e-mails e faturas."
181
+
182
+ #: woocommerce-bulk-discount.php:648
183
  msgid "Optionally enter information about discounts visible on cart page."
184
  msgstr ""
185
  "Opcionalmente, insira as informações sobre descontos visíveis na página do "
186
  "carrinho."
187
 
188
+ #: woocommerce-bulk-discount.php:655
189
  msgid "Optionally change the CSS for old price on cart before discounting."
190
  msgstr ""
191
  "Opcionalmente altere o CSS para preço antigo no carrinho antes de descontar."
192
 
193
+ #: woocommerce-bulk-discount.php:663
194
  msgid "Optionally change the CSS for new price on cart after discounting."
195
  msgstr ""
196
+ "Opcionalmente, altere o CSS para novo preço no carrinho após descontar."
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_butt
4
  Tags: woocommerce, bulk, discount
5
  Requires at least: 3.5
6
  Tested up to: 3.6
7
- Stable tag: 2.0.8
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -135,6 +135,10 @@ Setting bulk discounts couldn't have been easier.
135
 
136
  == Changelog ==
137
 
 
 
 
 
138
  = 2.0.8 =
139
  * (6 Oct 2013) Refined discount precision for percentage discounts with decimal point (no impact on integer discounts).
140
  * Translations updated.
@@ -199,6 +203,9 @@ Setting bulk discounts couldn't have been easier.
199
 
200
  == Upgrade Notice ==
201
 
 
 
 
202
  = 2.0.8 =
203
  Maintenance release.
204
 
4
  Tags: woocommerce, bulk, discount
5
  Requires at least: 3.5
6
  Tested up to: 3.6
7
+ Stable tag: 2.0.9
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
135
 
136
  == Changelog ==
137
 
138
+ = 2.0.9 =
139
+ * (9 Oct 2013) Translations updated.
140
+ * Minor code formatting changes.
141
+
142
  = 2.0.8 =
143
  * (6 Oct 2013) Refined discount precision for percentage discounts with decimal point (no impact on integer discounts).
144
  * Translations updated.
203
 
204
  == Upgrade Notice ==
205
 
206
+ = 2.0.9 =
207
+ Maintenance release.
208
+
209
  = 2.0.8 =
210
  Maintenance release.
211
 
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.8
8
  Author URI: http://www.renepuchinger.com
9
  License: GPL3
10
 
@@ -32,654 +32,629 @@ if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get
32
 
33
  if (!class_exists('Woo_Bulk_Discount_Plugin_t4m')) {
34
 
35
- class Woo_Bulk_Discount_Plugin_t4m
36
- {
37
-
38
- var $discount_coeffs;
39
-
40
- public function __construct()
41
- {
42
-
43
- load_plugin_textdomain('wc_bulk_discount', false, dirname(plugin_basename(__FILE__)) . '/lang/');
44
-
45
- $this->current_tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'general';
46
-
47
- $this->settings_tabs = array(
48
- 'bulk_discount' => __('Bulk Discount', 'wc_bulk_discount')
49
- );
50
-
51
- add_action('admin_enqueue_scripts', array($this, 'action_enqueue_dependencies_admin'));
52
- add_action('wp_head', array($this, 'action_enqueue_dependencies'));
53
-
54
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
55
-
56
- add_action('woocommerce_settings_tabs', array($this, 'add_tab'), 10);
57
-
58
- // Run these actions when generating the settings tabs.
59
- foreach ($this->settings_tabs as $name => $label) {
60
- add_action('woocommerce_settings_tabs_' . $name, array($this, 'settings_tab_action'), 10);
61
- add_action('woocommerce_update_options_' . $name, array($this, 'save_settings'), 10);
62
- }
63
-
64
- // Add the settings fields to each tab.
65
- add_action('woocommerce_bulk_discount_settings', array($this, 'add_settings_fields'), 10);
66
-
67
- if (get_option('woocommerce_t4m_enable_bulk_discounts', 'yes') == 'yes') {
68
- add_action('woocommerce_before_calculate_totals', array($this, 'action_before_calculate'), 10, 1);
69
- add_action('woocommerce_calculate_totals', array($this, 'action_after_calculate'), 10, 1);
70
- add_action('woocommerce_before_cart_table', array($this, 'before_cart_table'));
71
- add_action('woocommerce_single_product_summary', array($this, 'single_product_summary'), 45);
72
- if (class_exists('WC_Inline_Javascript_Helper')) { // is WooCommerce 2.1 installed?
73
- add_filter('woocommerce_cart_item_price', array($this, 'filter_item_price'), 10, 2);
74
- } else {
75
- add_filter('woocommerce_cart_item_price_html', array($this, 'filter_item_price'), 10, 2);
76
- }
77
- add_filter('woocommerce_cart_item_subtotal', array($this, 'filter_subtotal_price'), 10, 2);
78
- add_filter('woocommerce_checkout_item_subtotal', array($this, 'filter_subtotal_price'), 10, 2);
79
- add_filter('woocommerce_order_formatted_line_subtotal', array($this, 'filter_subtotal_order_price'), 10, 3);
80
- add_filter('woocommerce_product_write_panel_tabs', array($this, 'action_product_write_panel_tabs'));
81
- add_filter('woocommerce_product_write_panels', array($this, 'action_product_write_panels'));
82
- add_action('woocommerce_process_product_meta', array($this, 'action_process_meta'));
83
- add_filter('woocommerce_cart_product_subtotal', array($this, 'filter_cart_product_subtotal'), 10, 3);
84
- add_action('woocommerce_checkout_update_order_meta', array($this, 'order_update_meta'));
85
- }
86
-
87
- }
88
-
89
- /**
90
- * Add action links under WordPress > Plugins
91
- *
92
- * @param $links
93
- * @return array
94
- */
95
- public function action_links( $links ) {
96
-
97
- $plugin_links = array(
98
- '<a href="' . admin_url( 'admin.php?page=woocommerce&tab=bulk_discount' ) . '">' . __( 'Settings', 'woocommerce' ) . '</a>',
99
- );
100
-
101
- return array_merge( $plugin_links, $links );
102
- }
103
-
104
- /**
105
- * For given product, and quantity return the price modifying factor (percentage discount) or value to deduct (flat discount).
106
- *
107
- * @param $product_id
108
- * @param $quantity
109
- * @param $order
110
- * @return float
111
- */
112
- protected function get_discounted_coeff($product_id, $quantity)
113
- {
114
- $q = array(0.0);
115
- $d = array(0.0);
116
- /* Find the appropriate discount coefficient by looping through up to the five discount settings */
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];
126
- $d[0] = $d[$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 - round($d[0], 2)) / 100.0));
131
- }
132
-
133
- /**
134
- * Filter product price so that the discount is visible.
135
- *
136
- * @param $price
137
- * @param $values
138
- * @return string
139
- */
140
- public function filter_item_price($price, $values)
141
- {
142
- global $woocommerce;
143
- if ((get_option('woocommerce_t4m_show_on_item', 'yes') == 'no')) {
144
- return $price;
145
- }
146
- if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
147
- return $price; // for flat discount this filter has no meaning
148
- }
149
- $_product = $values['data'];
150
- if (empty($this->discount_coeffs) || !isset($this->discount_coeffs[$this->get_actual_id($_product)])
151
- || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']) || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['coeff'])
152
- ) {
153
- $this->gather_discount_coeffs();
154
- }
155
- $coeff = $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
156
- if ($coeff == 1.0 ) {
157
- return $price; // no price modification
158
- }
159
- $discprice = woocommerce_price($_product->get_price() * $coeff);
160
- $oldprice = woocommerce_price($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
161
- $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
162
- $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
163
- return "<span class='discount-info' title='" . sprintf(__('%s%% bulk discount applied!', 'wc_bulk_discount'), round((1.0 - $coeff) * 100.0, 2)) . "'>" .
164
- "<span class='old-price' style='$old_css'>$oldprice</span>" .
165
- "<span class='new-price' style='$new_css'>$discprice</span></span>";
166
- }
167
-
168
- /**
169
- * Filter product price so that the discount is visible.
170
- *
171
- * @param $price
172
- * @param $values
173
- * @return string
174
- */
175
- public function filter_subtotal_price($price, $values)
176
- {
177
- global $woocommerce;
178
- if ((get_option('woocommerce_t4m_show_on_subtotal', 'yes') == 'no')) {
179
- return $price;
180
- }
181
- $_product = $values['data'];
182
- if (empty($this->discount_coeffs) || !isset($this->discount_coeffs[$this->get_actual_id($_product)])
183
- || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']) || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['coeff'])
184
- ) {
185
- $this->gather_discount_coeffs();
186
- }
187
- $coeff = $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
188
- if (( get_option('woocommerce_t4m_discount_type', '') == 'flat' && $coeff == 0 ) || (get_option('woocommerce_t4m_discount_type', '') == '' && $coeff == 1.0 ) ) {
189
- return $price; // no price modification
190
- }
191
- $oldprice = woocommerce_price($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
192
- $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
193
- $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
194
- $bulk_info = sprintf(__('Incl. %s discount', 'wc_bulk_discount'), (get_option('woocommerce_t4m_discount_type', '') == 'flat' ? get_woocommerce_currency_symbol() . $coeff : (round((1 - $coeff) * 100, 2) . "%")));
195
- return "<span class='discount-info' title='$bulk_info'>" .
196
- "<span>$price</span>" .
197
- "<span class='new-price' style='$new_css'> ($bulk_info)</span></span>";
198
- }
199
-
200
- /**
201
- * Gather discount information to the array $this->discount_coefs
202
- */
203
- protected function gather_discount_coeffs()
204
- {
205
- global $woocommerce;
206
- $cart = $woocommerce->cart;
207
- $this->discount_coeffs = array();
208
- if (sizeof($cart->cart_contents) > 0) {
209
- foreach ($cart->cart_contents as $cart_item_key => $values) {
210
- $_product = $values['data'];
211
- $quantity = 0;
212
- if (get_option('woocommerce_t4m_variations_separate', 'yes') == 'no' && $_product instanceof WC_Product_Variation && $_product->parent) {
213
- $parent = $_product->parent;
214
- foreach ($cart->cart_contents as $valuesInner) {
215
- $p = $valuesInner['data'];
216
- if ($p instanceof WC_Product_Variation && $p->parent && $p->parent->id == $parent->id) {
217
- $quantity += $valuesInner['quantity'];
218
- $this->discount_coeffs[$_product->variation_id]['quantity'] = $quantity;
219
- }
220
- }
221
- } else {
222
- $quantity = $values['quantity'];
223
- }
224
- $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'] = $this->get_discounted_coeff($_product->id, $quantity);
225
- $this->discount_coeffs[$this->get_actual_id($_product)]['orig_price'] = $_product->get_price();
226
- }
227
- }
228
- }
229
-
230
- /**
231
- * Filter product price so that the discount is visible during order viewing.
232
- *
233
- * @param $price
234
- * @param $values
235
- * @return string
236
- */
237
- public function filter_subtotal_order_price($price, $values, $order)
238
- {
239
- global $woocommerce;
240
- if ((get_option('woocommerce_t4m_show_on_order_subtotal', 'yes') == 'no')) {
241
- return $price;
242
- }
243
- $_product = get_product($values['product_id']);
244
- $actual_id = $values['product_id'];
245
- if ($_product && $_product instanceof WC_Product_Variable && $values['variation_id']) {
246
- $actual_id = $values['variation_id'];
247
- }
248
- $discount_coeffs = $this->gather_discount_coeffs_from_order($order->id);
249
- if (empty($discount_coeffs)) {
250
- return $price;
251
- }
252
- $coeff = $discount_coeffs[$actual_id]['coeff'];
253
- $discount_type = get_post_meta($order->id, '_woocommerce_t4m_discount_type', true);
254
- if (( $discount_type == 'flat' && $coeff == 0 ) || ($discount_type == '' && $coeff == 1.0 ) ) {
255
- return $price; // no price modification
256
- }
257
- $oldprice = woocommerce_price($discount_coeffs[$actual_id]['orig_price']);
258
- $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
259
- $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
260
- $bulk_info = sprintf(__('Incl. %s discount', 'wc_bulk_discount'), ($discount_type == 'flat' ? get_woocommerce_currency_symbol() . $coeff : (round((1 - $coeff) * 100, 2) . "%")));
261
- return "<span class='discount-info' title='$bulk_info'>" .
262
- "<span>$price</span>" .
263
- "<span class='new-price' style='$new_css'> ($bulk_info)</span></span>";
264
- }
265
-
266
- /**
267
- * Gather discount information from order.
268
- *
269
- * @param $order_id
270
- * @return array
271
- */
272
- protected function gather_discount_coeffs_from_order($order_id)
273
- {
274
- $meta = get_post_meta($order_id, '_woocommerce_t4m_discount_coeffs', true);
275
- if (!$meta) {
276
- return null;
277
- }
278
- $order_discount_coeffs = json_decode($meta, true);
279
- return $order_discount_coeffs;
280
- }
281
-
282
- /**
283
- * Hook to woocommerce_before_calculate_totals action.
284
- *
285
- * @param WC_Cart $cart
286
- */
287
- public function action_before_calculate(WC_Cart $cart)
288
- {
289
-
290
- $this->gather_discount_coeffs();
291
-
292
- if (sizeof($cart->cart_contents) > 0) {
293
- foreach ($cart->cart_contents as $cart_item_key => $values) {
294
- $_product = $values['data'];
295
- if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
296
- $row_base_price = max(0, $_product->get_price() - ($this->discount_coeffs[$this->get_actual_id($_product)]['coeff'] / $values['quantity']));
297
- } else {
298
- $row_base_price = $_product->get_price() * $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
299
- }
300
-
301
- $values['data']->set_price($row_base_price);
302
- }
303
- }
304
- }
305
-
306
- protected function get_actual_id($product)
307
- {
308
- if ($product instanceof WC_Product_Variation) {
309
- return $product->variation_id;
310
- } else {
311
- return $product->id;
312
- }
313
- }
314
-
315
- /**
316
- * Hook to woocommerce_calculate_totals.
317
- *
318
- * @param WC_Cart $cart
319
- */
320
- public function action_after_calculate(WC_Cart $cart)
321
- {
322
- if (sizeof($cart->cart_contents) > 0) {
323
- foreach ($cart->cart_contents as $cart_item_key => $values) {
324
- $_product = $values['data'];
325
- $values['data']->set_price($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
326
- }
327
- }
328
- }
329
-
330
- /**
331
- * Show discount info in cart.
332
- */
333
- public function before_cart_table()
334
- {
335
- echo "<div class='cart-show-discounts'>";
336
- echo get_option('woocommerce_t4m_cart_info');
337
- echo "</div>";
338
- }
339
-
340
- /**
341
- * Hook to woocommerce_cart_product_subtotal filter.
342
- *
343
- * @param $subtotal
344
- * @param $_product
345
- * @param $quantity
346
- * @param WC_Cart $cart
347
- * @return string
348
- */
349
- public function filter_cart_product_subtotal($subtotal, $_product, $quantity)
350
- {
351
- $coeff = $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
352
- if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
353
- $newsubtotal = woocommerce_price(max(0, ($_product->get_price() * $quantity) - $coeff));
354
- } else {
355
- $newsubtotal = woocommerce_price($_product->get_price() * $quantity * $coeff);
356
- }
357
- return $newsubtotal;
358
- }
359
-
360
- /**
361
- * Store discount info to order as well
362
- *
363
- * @param $order_id
364
- */
365
- public function order_update_meta($order_id) {
366
- update_post_meta($order_id, "_woocommerce_t4m_discount_type", get_option('woocommerce_t4m_discount_type', ''));
367
- update_post_meta($order_id, "_woocommerce_t4m_discount_coeffs", json_encode($this->discount_coeffs));
368
- }
369
-
370
- /**
371
- * Display discount information in Product Detail.
372
- */
373
- public function single_product_summary()
374
- {
375
- global $thepostid, $post;
376
- if (!$thepostid) $thepostid = $post->ID;
377
- echo "<div class='productinfo-show-discounts'>";
378
- echo get_post_meta($thepostid, '_bulkdiscount_text_info', true);
379
- echo "</div>";
380
- }
381
-
382
- /**
383
- * Add entry to Product Settings.
384
- */
385
- public function action_product_write_panel_tabs()
386
- {
387
- echo '<li class="bulkdiscount_tab bulkdiscount_options"><a href="#bulkdiscount_product_data">' . __('Bulk Discount', 'wc_bulk_discount') . '</a></li>';
388
- }
389
-
390
- /**
391
- * Add entry content to Product Settings.
392
- */
393
- public function action_product_write_panels()
394
- {
395
- global $thepostid, $post;
396
- if (!$thepostid) $thepostid = $post->ID;
397
- ?>
398
- <script type="text/javascript">
399
- jQuery(document).ready(function () {
400
- <?php
401
- for($i = 1; $i <= 5; $i++) :
402
- ?>
403
- jQuery('#bulkdiscount_product_data').find('.block<?php echo $i; ?>').hide();
404
- jQuery('#bulkdiscount_product_data').find('.options_group<?php echo max($i, 2); ?>').hide();
405
- jQuery('#bulkdiscount_product_data').find('#add_discount_line<?php echo max($i, 2); ?>').hide();
406
- jQuery("#bulkdiscount_product_data").find('#add_discount_line<?php echo $i; ?>').click(function () {
407
- jQuery('#bulkdiscount_product_data').find('.block<?php echo $i; ?>').show(400);
408
- jQuery('#bulkdiscount_product_data').find('.options_group<?php echo min($i+1, 5); ?>').show(400);
409
- jQuery('#bulkdiscount_product_data').find('#add_discount_line<?php echo min($i+1, 5); ?>').show(400);
410
- jQuery('#bulkdiscount_product_data').find('#add_discount_line<?php echo $i; ?>').hide(400);
411
- });
412
- <?php
413
- endfor;
414
- for ($i = 1; $i <= 5; $i++) {
415
- if (get_post_meta($thepostid, "_bulkdiscount_quantity_$i", true)) {
416
- ?>
417
- jQuery('#bulkdiscount_product_data').find('.block<?php echo $i; ?>').show();
418
- jQuery('#bulkdiscount_product_data').find('.options_group<?php echo $i; ?>').show();
419
- jQuery("#bulkdiscount_product_data").find('#add_discount_line<?php echo $i; ?>').hide();
420
- jQuery("#bulkdiscount_product_data").find('.options_group<?php echo min($i+1,5); ?>').show();
421
- jQuery("#bulkdiscount_product_data").find('#add_discount_line<?php echo min($i+1,5); ?>').show();
422
- <?php
423
- }
424
- }
425
- ?>
426
- });
427
- </script>
428
-
429
- <div id="bulkdiscount_product_data" class="panel woocommerce_options_panel">
430
-
431
- <div class="options_group">
432
- <?php
433
- woocommerce_wp_textarea_input(array('id' => "_bulkdiscount_text_info", 'label' => __('Bulk discount info in product description', 'wc_bulk_discount'), 'description' => __('Optionally enter bulk discount information that will be visible on the product page.', 'wc_bulk_discount'), 'desc_tip' => 'yes', 'class' => 'fullWidth'));
434
- ?>
435
- </div>
436
-
437
- <?php
438
- for ($i = 1; $i <= 5; $i++) :
439
- ?>
440
-
441
- <div class="options_group<?php echo $i; ?>">
442
- <a id="add_discount_line<?php echo $i; ?>" class="button-secondary"
443
- href="#block<?php echo $i; ?>">Add discount line</a>
444
-
445
- <div class="block<?php echo $i; ?>">
446
- <?php
447
- woocommerce_wp_text_input(array('id' => "_bulkdiscount_quantity_$i", 'label' => __('Quantity (min.)', 'wc_bulk_discount'), 'description' => __('Enter the minimal quantity for which the discount applies.', 'wc_bulk_discount')));
448
- if (get_option('woocommerce_t4m_discount_type', '') == 'flat') {
449
- woocommerce_wp_text_input(array('id' => "_bulkdiscount_discount_flat_$i", 'label' => sprintf(__('Discount (%s)', 'wc_bulk_discount'), get_woocommerce_currency_symbol()), 'description' => sprintf(__('Enter the flat discount in %s.', 'wc_bulk_discount'), get_woocommerce_currency_symbol())));
450
- } else {
451
- woocommerce_wp_text_input(array('id' => "_bulkdiscount_discount_$i", 'label' => __('Discount (%)', 'wc_bulk_discount'), 'description' => __('Enter the discount in percents (Allowed values: 0 to 100).', 'wc_bulk_discount')));
452
- }
453
- ?>
454
- </div>
455
- </div>
456
-
457
- <?php
458
- endfor;
459
- ?>
460
-
461
- <br/>
462
-
463
- </div>
464
-
465
- <?php
466
- }
467
-
468
- /**
469
- * Enqueue frontend dependencies.
470
- */
471
- public function action_enqueue_dependencies()
472
- {
473
- wp_register_style('woocommercebulkdiscount-style', plugins_url('css/style.css', __FILE__));
474
- wp_enqueue_style('woocommercebulkdiscount-style');
475
- wp_enqueue_script('jquery');
476
- }
477
-
478
- /**
479
- * Enqueue backend dependencies.
480
- */
481
- public function action_enqueue_dependencies_admin()
482
- {
483
- wp_register_style('woocommercebulkdiscount-style-admin', plugins_url('css/admin.css', __FILE__));
484
- wp_enqueue_style('woocommercebulkdiscount-style-admin');
485
- wp_enqueue_script('jquery');
486
- }
487
-
488
- /**
489
- * Updating post meta.
490
- *
491
- * @param $post_id
492
- */
493
- public function action_process_meta($post_id)
494
- {
495
- if (isset($_POST['_bulkdiscount_text_info'])) update_post_meta($post_id, '_bulkdiscount_text_info', esc_attr($_POST['_bulkdiscount_text_info']));
496
- for ($i = 1; $i <= 5; $i++) {
497
- if (isset($_POST["_bulkdiscount_quantity_$i"])) update_post_meta($post_id, "_bulkdiscount_quantity_$i", stripslashes($_POST["_bulkdiscount_quantity_$i"]));
498
- if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
499
- if (isset($_POST["_bulkdiscount_discount_flat_$i"])) update_post_meta($post_id, "_bulkdiscount_discount_flat_$i", stripslashes($_POST["_bulkdiscount_discount_flat_$i"]));
500
- } else {
501
- if (isset($_POST["_bulkdiscount_discount_$i"])) update_post_meta($post_id, "_bulkdiscount_discount_$i", stripslashes($_POST["_bulkdiscount_discount_$i"]));
502
- }
503
- }
504
- }
505
-
506
- /**
507
- * @access public
508
- * @return void
509
- */
510
- public function add_tab()
511
- {
512
- foreach ($this->settings_tabs as $name => $label) {
513
- $class = 'nav-tab';
514
- if ($this->current_tab == $name)
515
- $class .= ' nav-tab-active';
516
- echo '<a href="' . admin_url('admin.php?page=woocommerce&tab=' . $name) . '" class="' . $class . '">' . $label . '</a>';
517
- }
518
- }
519
-
520
- /**
521
- * @access public
522
- * @return void
523
- */
524
- public function settings_tab_action()
525
- {
526
- global $woocommerce_settings;
527
-
528
- // Determine the current tab in effect.
529
- $current_tab = $this->get_tab_in_view(current_filter(), 'woocommerce_settings_tabs_');
530
-
531
- // Hook onto this from another function to keep things clean.
532
- do_action('woocommerce_bulk_discount_settings');
533
-
534
- // Display settings for this tab (make sure to add the settings to the tab).
535
- woocommerce_admin_fields($woocommerce_settings[$current_tab]);
536
- }
537
-
538
- /**
539
- * Save settings in a single field in the database for each tab's fields (one field per tab).
540
- */
541
- public function save_settings()
542
- {
543
- global $woocommerce_settings;
544
-
545
- // Make sure our settings fields are recognised.
546
- $this->add_settings_fields();
547
-
548
- $current_tab = $this->get_tab_in_view(current_filter(), 'woocommerce_update_options_');
549
- woocommerce_update_options($woocommerce_settings[$current_tab]);
550
- }
551
-
552
- /**
553
- * Get the tab current in view/processing.
554
- */
555
- public function get_tab_in_view($current_filter, $filter_base)
556
- {
557
- return str_replace($filter_base, '', $current_filter);
558
- }
559
-
560
-
561
- /**
562
- * Add settings fields for each tab.
563
- */
564
- public function add_settings_fields()
565
- {
566
- global $woocommerce_settings;
567
-
568
- // Load the prepared form fields.
569
- $this->init_form_fields();
570
-
571
- if (is_array($this->fields))
572
- foreach ($this->fields as $k => $v)
573
- $woocommerce_settings[$k] = $v;
574
- }
575
-
576
- /**
577
- * Prepare form fields to be used in the various tabs.
578
- */
579
- public function init_form_fields()
580
- {
581
- global $woocommerce;
582
-
583
- // Define settings
584
- $this->fields['bulk_discount'] = apply_filters('woocommerce_bulk_discount_settings_fields', array(
585
-
586
- array('name' => __('Bulk Discount', 'wc_bulk_discount'), 'type' => 'title', 'desc' => __('The following options are specific to product bulk discount.', 'wc_bulk_discount') . '<br /><br/><strong><i>' . __('After changing the settings, it is recommended to clear all sessions in WooCommerce &gt; System Status &gt; Tools.', 'wc_bulk_discount') . '</i></strong>', 'id' => 't4m_bulk_discounts_options'),
587
-
588
- array(
589
- 'name' => __('Bulk Discount enabled', 'wc_bulk_discount'),
590
- 'id' => 'woocommerce_t4m_enable_bulk_discounts',
591
- 'desc' => __('', 'wc_bulk_discount'),
592
- 'std' => 'yes',
593
- 'type' => 'checkbox',
594
- 'default' => 'yes'
595
- ),
596
-
597
- array(
598
- 'title' => __('Discount Type', 'wc_bulk_discount'),
599
- 'id' => 'woocommerce_t4m_discount_type',
600
- 'desc' => sprintf(__('Select the type of discount. Percentage Discount deducts amount of %% from price while Flat Discount deducts fixed amount in %s', 'wc_bulk_discount'), get_woocommerce_currency_symbol()),
601
- 'desc_tip' => true,
602
- 'std' => 'yes',
603
- 'type' => 'select',
604
- 'css' => 'min-width:200px;',
605
- 'class' => 'chosen_select',
606
- 'options' => array(
607
- '' => __('Percentage Discount', 'wc_bulk_discount'),
608
- 'flat' => __('Flat Discount', 'wc_bulk_discount')
609
- )
610
- ),
611
-
612
- array(
613
- 'name' => __('Treat product variations separately', 'wc_bulk_discount'),
614
- 'id' => 'woocommerce_t4m_variations_separate',
615
- 'desc' => __('You need to have this option unchecked to handle discounts on product variations as a whole.', 'wc_bulk_discount'),
616
- 'std' => 'yes',
617
- 'type' => 'checkbox',
618
- 'default' => 'yes'
619
- ),
620
-
621
- array(
622
- 'name' => __('Show discount information next to cart item price', 'wc_bulk_discount'),
623
- 'id' => 'woocommerce_t4m_show_on_item',
624
- 'desc' => __('Applies only to percentage discount.', 'wc_bulk_discount'),
625
- 'std' => 'yes',
626
- 'type' => 'checkbox',
627
- 'default' => 'yes'
628
- ),
629
-
630
- array(
631
- 'name' => __('Show discount information next to item subtotal price', 'wc_bulk_discount'),
632
- 'id' => 'woocommerce_t4m_show_on_subtotal',
633
- 'std' => 'yes',
634
- 'type' => 'checkbox',
635
- 'default' => 'yes'
636
- ),
637
-
638
- array(
639
- 'name' => __('Show discount information next to item subtotal price in order history', 'wc_bulk_discount'),
640
- 'id' => 'woocommerce_t4m_show_on_order_subtotal',
641
- 'desc' => __('Includes showing discount in order e-mails and invoices.', 'wc_bulk_discount'),
642
- 'std' => 'yes',
643
- 'type' => 'checkbox',
644
- 'default' => 'yes'
645
- ),
646
-
647
- array(
648
- 'name' => __('Optionally enter information about discounts visible on cart page.', 'wc_bulk_discount'),
649
- 'id' => 'woocommerce_t4m_cart_info',
650
- 'type' => 'textarea',
651
- 'css' => 'width:100%; height: 75px;'
652
- ),
653
-
654
- array(
655
- 'name' => __('Optionally change the CSS for old price on cart before discounting.', 'wc_bulk_discount'),
656
- 'id' => 'woocommerce_t4m_css_old_price',
657
- 'type' => 'textarea',
658
- 'css' => 'width:100%;',
659
- 'default' => 'color: #777; text-decoration: line-through; margin-right: 4px;'
660
- ),
661
-
662
- array(
663
- 'name' => __('Optionally change the CSS for new price on cart after discounting.', 'wc_bulk_discount'),
664
- 'id' => 'woocommerce_t4m_css_new_price',
665
- 'type' => 'textarea',
666
- 'css' => 'width:100%;',
667
- 'default' => 'color: #4AB915; font-weight: bold;'
668
- ),
669
-
670
- array('type' => 'sectionend', 'id' => 't4m_bulk_discounts_options'),
671
-
672
- array(
673
- 'desc' => '<b>If you find WooCommerce Bulk Discount useful, please rate the plugin at <a href="http://wordpress.org/plugins/woocommerce-bulk-discount/">http://wordpress.org/plugins/woocommerce-bulk-discount/</a> or kindly consider small donation to support further development.</b>',
674
- 'id' => 'woocommerce_t4m_begging_text',
675
- 'type' => 'title'
676
- ),
677
-
678
- array('type' => 'sectionend', 'id' => 'woocommerce_t4m_begging_text'),
679
-
680
- )); // End settings
681
-
682
- $js = "
683
  jQuery('#woocommerce_t4m_enable_bulk_discounts').change(function(){
684
 
685
  jQuery('#woocommerce_t4m_cart_info, #woocommerce_t4m_variations_separate, #woocommerce_t4m_discount_type, #woocommerce_t4m_css_old_price, #woocommerce_t4m_css_new_price, #woocommerce_t4m_show_on_item, #woocommerce_t4m_show_on_subtotal, #woocommerce_t4m_show_on_order_subtotal').closest('tr').hide();
@@ -699,16 +674,16 @@ if (!class_exists('Woo_Bulk_Discount_Plugin_t4m')) {
699
 
700
  ";
701
 
702
- if (class_exists('WC_Inline_Javascript_Helper')) {
703
- $woocommerce->get_helper('inline-javascript')->add_inline_js($js);
704
- } else {
705
- $woocommerce->add_inline_js($js);
706
- }
707
 
708
- }
709
 
710
- }
711
 
712
- $woo_bulk_discount_plugin = new Woo_Bulk_Discount_Plugin_t4m();
713
 
714
  }
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.9
8
  Author URI: http://www.renepuchinger.com
9
  License: GPL3
10
 
32
 
33
  if (!class_exists('Woo_Bulk_Discount_Plugin_t4m')) {
34
 
35
+ class Woo_Bulk_Discount_Plugin_t4m {
36
+
37
+ var $discount_coeffs;
38
+
39
+ public function __construct() {
40
+
41
+ load_plugin_textdomain('wc_bulk_discount', false, dirname(plugin_basename(__FILE__)) . '/lang/');
42
+
43
+ $this->current_tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'general';
44
+
45
+ $this->settings_tabs = array(
46
+ 'bulk_discount' => __('Bulk Discount', 'wc_bulk_discount')
47
+ );
48
+
49
+ add_action('admin_enqueue_scripts', array($this, 'action_enqueue_dependencies_admin'));
50
+ add_action('wp_head', array($this, 'action_enqueue_dependencies'));
51
+
52
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'action_links'));
53
+
54
+ add_action('woocommerce_settings_tabs', array($this, 'add_tab'), 10);
55
+
56
+ // Run these actions when generating the settings tabs.
57
+ foreach ($this->settings_tabs as $name => $label) {
58
+ add_action('woocommerce_settings_tabs_' . $name, array($this, 'settings_tab_action'), 10);
59
+ add_action('woocommerce_update_options_' . $name, array($this, 'save_settings'), 10);
60
+ }
61
+
62
+ // Add the settings fields to each tab.
63
+ add_action('woocommerce_bulk_discount_settings', array($this, 'add_settings_fields'), 10);
64
+
65
+ if (get_option('woocommerce_t4m_enable_bulk_discounts', 'yes') == 'yes') {
66
+ add_action('woocommerce_before_calculate_totals', array($this, 'action_before_calculate'), 10, 1);
67
+ add_action('woocommerce_calculate_totals', array($this, 'action_after_calculate'), 10, 1);
68
+ add_action('woocommerce_before_cart_table', array($this, 'before_cart_table'));
69
+ add_action('woocommerce_single_product_summary', array($this, 'single_product_summary'), 45);
70
+ if (class_exists('WC_Inline_Javascript_Helper')) { // is WooCommerce 2.1 installed?
71
+ add_filter('woocommerce_cart_item_price', array($this, 'filter_item_price'), 10, 2);
72
+ } else {
73
+ add_filter('woocommerce_cart_item_price_html', array($this, 'filter_item_price'), 10, 2);
74
+ }
75
+ add_filter('woocommerce_cart_item_subtotal', array($this, 'filter_subtotal_price'), 10, 2);
76
+ add_filter('woocommerce_checkout_item_subtotal', array($this, 'filter_subtotal_price'), 10, 2);
77
+ add_filter('woocommerce_order_formatted_line_subtotal', array($this, 'filter_subtotal_order_price'), 10, 3);
78
+ add_filter('woocommerce_product_write_panel_tabs', array($this, 'action_product_write_panel_tabs'));
79
+ add_filter('woocommerce_product_write_panels', array($this, 'action_product_write_panels'));
80
+ add_action('woocommerce_process_product_meta', array($this, 'action_process_meta'));
81
+ add_filter('woocommerce_cart_product_subtotal', array($this, 'filter_cart_product_subtotal'), 10, 3);
82
+ add_action('woocommerce_checkout_update_order_meta', array($this, 'order_update_meta'));
83
+ }
84
+
85
+ }
86
+
87
+ /**
88
+ * Add action links under WordPress > Plugins
89
+ *
90
+ * @param $links
91
+ * @return array
92
+ */
93
+ public function action_links($links) {
94
+
95
+ $plugin_links = array(
96
+ '<a href="' . admin_url('admin.php?page=woocommerce&tab=bulk_discount') . '">' . __('Settings', 'woocommerce') . '</a>',
97
+ );
98
+
99
+ return array_merge($plugin_links, $links);
100
+ }
101
+
102
+ /**
103
+ * For given product, and quantity return the price modifying factor (percentage discount) or value to deduct (flat discount).
104
+ *
105
+ * @param $product_id
106
+ * @param $quantity
107
+ * @param $order
108
+ * @return float
109
+ */
110
+ protected function get_discounted_coeff($product_id, $quantity) {
111
+ $q = array(0.0);
112
+ $d = array(0.0);
113
+ /* Find the appropriate discount coefficient by looping through up to the five discount settings */
114
+ for ($i = 1; $i <= 5; $i++) {
115
+ array_push($q, get_post_meta($product_id, "_bulkdiscount_quantity_$i", true));
116
+ if (get_option('woocommerce_t4m_discount_type', '') == 'flat') {
117
+ 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);
118
+ } else {
119
+ array_push($d, get_post_meta($product_id, "_bulkdiscount_discount_$i", true) ? get_post_meta($product_id, "_bulkdiscount_discount_$i", true) : 0.0);
120
+ }
121
+ if ($quantity >= $q[$i] && $q[$i] > $q[0]) {
122
+ $q[0] = $q[$i];
123
+ $d[0] = $d[$i];
124
+ }
125
+ }
126
+ // for percentage discount convert the resulting discount from % to the multiplying coefficient
127
+ return (get_option('woocommerce_t4m_discount_type', '') == 'flat') ? max(0, $d[0]) : min(1.0, max(0, (100.0 - round($d[0], 2)) / 100.0));
128
+ }
129
+
130
+ /**
131
+ * Filter product price so that the discount is visible.
132
+ *
133
+ * @param $price
134
+ * @param $values
135
+ * @return string
136
+ */
137
+ public function filter_item_price($price, $values) {
138
+ global $woocommerce;
139
+ if ((get_option('woocommerce_t4m_show_on_item', 'yes') == 'no')) {
140
+ return $price;
141
+ }
142
+ if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
143
+ return $price; // for flat discount this filter has no meaning
144
+ }
145
+ $_product = $values['data'];
146
+ if (empty($this->discount_coeffs) || !isset($this->discount_coeffs[$this->get_actual_id($_product)])
147
+ || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']) || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['coeff'])
148
+ ) {
149
+ $this->gather_discount_coeffs();
150
+ }
151
+ $coeff = $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
152
+ if ($coeff == 1.0) {
153
+ return $price; // no price modification
154
+ }
155
+ $discprice = woocommerce_price($_product->get_price() * $coeff);
156
+ $oldprice = woocommerce_price($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
157
+ $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
158
+ $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
159
+ return "<span class='discount-info' title='" . sprintf(__('%s%% bulk discount applied!', 'wc_bulk_discount'), round((1.0 - $coeff) * 100.0, 2)) . "'>" .
160
+ "<span class='old-price' style='$old_css'>$oldprice</span>" .
161
+ "<span class='new-price' style='$new_css'>$discprice</span></span>";
162
+ }
163
+
164
+ /**
165
+ * Filter product price so that the discount is visible.
166
+ *
167
+ * @param $price
168
+ * @param $values
169
+ * @return string
170
+ */
171
+ public function filter_subtotal_price($price, $values) {
172
+ global $woocommerce;
173
+ if ((get_option('woocommerce_t4m_show_on_subtotal', 'yes') == 'no')) {
174
+ return $price;
175
+ }
176
+ $_product = $values['data'];
177
+ if (empty($this->discount_coeffs) || !isset($this->discount_coeffs[$this->get_actual_id($_product)])
178
+ || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']) || !isset($this->discount_coeffs[$this->get_actual_id($_product)]['coeff'])
179
+ ) {
180
+ $this->gather_discount_coeffs();
181
+ }
182
+ $coeff = $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
183
+ if ((get_option('woocommerce_t4m_discount_type', '') == 'flat' && $coeff == 0) || (get_option('woocommerce_t4m_discount_type', '') == '' && $coeff == 1.0)) {
184
+ return $price; // no price modification
185
+ }
186
+ $oldprice = woocommerce_price($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
187
+ $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
188
+ $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
189
+ $bulk_info = sprintf(__('Incl. %s discount', 'wc_bulk_discount'), (get_option('woocommerce_t4m_discount_type', '') == 'flat' ? get_woocommerce_currency_symbol() . $coeff : (round((1 - $coeff) * 100, 2) . "%")));
190
+ return "<span class='discount-info' title='$bulk_info'>" .
191
+ "<span>$price</span>" .
192
+ "<span class='new-price' style='$new_css'> ($bulk_info)</span></span>";
193
+ }
194
+
195
+ /**
196
+ * Gather discount information to the array $this->discount_coefs
197
+ */
198
+ protected function gather_discount_coeffs() {
199
+ global $woocommerce;
200
+ $cart = $woocommerce->cart;
201
+ $this->discount_coeffs = array();
202
+ if (sizeof($cart->cart_contents) > 0) {
203
+ foreach ($cart->cart_contents as $cart_item_key => $values) {
204
+ $_product = $values['data'];
205
+ $quantity = 0;
206
+ if (get_option('woocommerce_t4m_variations_separate', 'yes') == 'no' && $_product instanceof WC_Product_Variation && $_product->parent) {
207
+ $parent = $_product->parent;
208
+ foreach ($cart->cart_contents as $valuesInner) {
209
+ $p = $valuesInner['data'];
210
+ if ($p instanceof WC_Product_Variation && $p->parent && $p->parent->id == $parent->id) {
211
+ $quantity += $valuesInner['quantity'];
212
+ $this->discount_coeffs[$_product->variation_id]['quantity'] = $quantity;
213
+ }
214
+ }
215
+ } else {
216
+ $quantity = $values['quantity'];
217
+ }
218
+ $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'] = $this->get_discounted_coeff($_product->id, $quantity);
219
+ $this->discount_coeffs[$this->get_actual_id($_product)]['orig_price'] = $_product->get_price();
220
+ }
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Filter product price so that the discount is visible during order viewing.
226
+ *
227
+ * @param $price
228
+ * @param $values
229
+ * @return string
230
+ */
231
+ public function filter_subtotal_order_price($price, $values, $order) {
232
+ global $woocommerce;
233
+ if ((get_option('woocommerce_t4m_show_on_order_subtotal', 'yes') == 'no')) {
234
+ return $price;
235
+ }
236
+ $_product = get_product($values['product_id']);
237
+ $actual_id = $values['product_id'];
238
+ if ($_product && $_product instanceof WC_Product_Variable && $values['variation_id']) {
239
+ $actual_id = $values['variation_id'];
240
+ }
241
+ $discount_coeffs = $this->gather_discount_coeffs_from_order($order->id);
242
+ if (empty($discount_coeffs)) {
243
+ return $price;
244
+ }
245
+ $coeff = $discount_coeffs[$actual_id]['coeff'];
246
+ $discount_type = get_post_meta($order->id, '_woocommerce_t4m_discount_type', true);
247
+ if (($discount_type == 'flat' && $coeff == 0) || ($discount_type == '' && $coeff == 1.0)) {
248
+ return $price; // no price modification
249
+ }
250
+ $oldprice = woocommerce_price($discount_coeffs[$actual_id]['orig_price']);
251
+ $old_css = esc_attr(get_option('woocommerce_t4m_css_old_price', 'color: #777; text-decoration: line-through; margin-right: 4px;'));
252
+ $new_css = esc_attr(get_option('woocommerce_t4m_css_new_price', 'color: #4AB915; font-weight: bold;'));
253
+ $bulk_info = sprintf(__('Incl. %s discount', 'wc_bulk_discount'), ($discount_type == 'flat' ? get_woocommerce_currency_symbol() . $coeff : (round((1 - $coeff) * 100, 2) . "%")));
254
+ return "<span class='discount-info' title='$bulk_info'>" .
255
+ "<span>$price</span>" .
256
+ "<span class='new-price' style='$new_css'> ($bulk_info)</span></span>";
257
+ }
258
+
259
+ /**
260
+ * Gather discount information from order.
261
+ *
262
+ * @param $order_id
263
+ * @return array
264
+ */
265
+ protected function gather_discount_coeffs_from_order($order_id) {
266
+ $meta = get_post_meta($order_id, '_woocommerce_t4m_discount_coeffs', true);
267
+ if (!$meta) {
268
+ return null;
269
+ }
270
+ $order_discount_coeffs = json_decode($meta, true);
271
+ return $order_discount_coeffs;
272
+ }
273
+
274
+ /**
275
+ * Hook to woocommerce_before_calculate_totals action.
276
+ *
277
+ * @param WC_Cart $cart
278
+ */
279
+ public function action_before_calculate(WC_Cart $cart) {
280
+
281
+ $this->gather_discount_coeffs();
282
+
283
+ if (sizeof($cart->cart_contents) > 0) {
284
+ foreach ($cart->cart_contents as $cart_item_key => $values) {
285
+ $_product = $values['data'];
286
+ if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
287
+ $row_base_price = max(0, $_product->get_price() - ($this->discount_coeffs[$this->get_actual_id($_product)]['coeff'] / $values['quantity']));
288
+ } else {
289
+ $row_base_price = $_product->get_price() * $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
290
+ }
291
+
292
+ $values['data']->set_price($row_base_price);
293
+ }
294
+ }
295
+ }
296
+
297
+ protected function get_actual_id($product) {
298
+ if ($product instanceof WC_Product_Variation) {
299
+ return $product->variation_id;
300
+ } else {
301
+ return $product->id;
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Hook to woocommerce_calculate_totals.
307
+ *
308
+ * @param WC_Cart $cart
309
+ */
310
+ public function action_after_calculate(WC_Cart $cart) {
311
+ if (sizeof($cart->cart_contents) > 0) {
312
+ foreach ($cart->cart_contents as $cart_item_key => $values) {
313
+ $_product = $values['data'];
314
+ $values['data']->set_price($this->discount_coeffs[$this->get_actual_id($_product)]['orig_price']);
315
+ }
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Show discount info in cart.
321
+ */
322
+ public function before_cart_table() {
323
+ echo "<div class='cart-show-discounts'>";
324
+ echo get_option('woocommerce_t4m_cart_info');
325
+ echo "</div>";
326
+ }
327
+
328
+ /**
329
+ * Hook to woocommerce_cart_product_subtotal filter.
330
+ *
331
+ * @param $subtotal
332
+ * @param $_product
333
+ * @param $quantity
334
+ * @param WC_Cart $cart
335
+ * @return string
336
+ */
337
+ public function filter_cart_product_subtotal($subtotal, $_product, $quantity) {
338
+ $coeff = $this->discount_coeffs[$this->get_actual_id($_product)]['coeff'];
339
+ if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
340
+ $newsubtotal = woocommerce_price(max(0, ($_product->get_price() * $quantity) - $coeff));
341
+ } else {
342
+ $newsubtotal = woocommerce_price($_product->get_price() * $quantity * $coeff);
343
+ }
344
+ return $newsubtotal;
345
+ }
346
+
347
+ /**
348
+ * Store discount info to order as well
349
+ *
350
+ * @param $order_id
351
+ */
352
+ public function order_update_meta($order_id) {
353
+ update_post_meta($order_id, "_woocommerce_t4m_discount_type", get_option('woocommerce_t4m_discount_type', ''));
354
+ update_post_meta($order_id, "_woocommerce_t4m_discount_coeffs", json_encode($this->discount_coeffs));
355
+ }
356
+
357
+ /**
358
+ * Display discount information in Product Detail.
359
+ */
360
+ public function single_product_summary() {
361
+ global $thepostid, $post;
362
+ if (!$thepostid) $thepostid = $post->ID;
363
+ echo "<div class='productinfo-show-discounts'>";
364
+ echo get_post_meta($thepostid, '_bulkdiscount_text_info', true);
365
+ echo "</div>";
366
+ }
367
+
368
+ /**
369
+ * Add entry to Product Settings.
370
+ */
371
+ public function action_product_write_panel_tabs() {
372
+ echo '<li class="bulkdiscount_tab bulkdiscount_options"><a href="#bulkdiscount_product_data">' . __('Bulk Discount', 'wc_bulk_discount') . '</a></li>';
373
+ }
374
+
375
+ /**
376
+ * Add entry content to Product Settings.
377
+ */
378
+ public function action_product_write_panels() {
379
+ global $thepostid, $post;
380
+ if (!$thepostid) $thepostid = $post->ID;
381
+ ?>
382
+ <script type="text/javascript">
383
+ jQuery(document).ready(function () {
384
+ <?php
385
+ for($i = 1; $i <= 5; $i++) :
386
+ ?>
387
+ jQuery('#bulkdiscount_product_data').find('.block<?php echo $i; ?>').hide();
388
+ jQuery('#bulkdiscount_product_data').find('.options_group<?php echo max($i, 2); ?>').hide();
389
+ jQuery('#bulkdiscount_product_data').find('#add_discount_line<?php echo max($i, 2); ?>').hide();
390
+ jQuery("#bulkdiscount_product_data").find('#add_discount_line<?php echo $i; ?>').click(function () {
391
+ jQuery('#bulkdiscount_product_data').find('.block<?php echo $i; ?>').show(400);
392
+ jQuery('#bulkdiscount_product_data').find('.options_group<?php echo min($i+1, 5); ?>').show(400);
393
+ jQuery('#bulkdiscount_product_data').find('#add_discount_line<?php echo min($i+1, 5); ?>').show(400);
394
+ jQuery('#bulkdiscount_product_data').find('#add_discount_line<?php echo $i; ?>').hide(400);
395
+ });
396
+ <?php
397
+ endfor;
398
+ for ($i = 1; $i <= 5; $i++) {
399
+ if (get_post_meta($thepostid, "_bulkdiscount_quantity_$i", true)) {
400
+ ?>
401
+ jQuery('#bulkdiscount_product_data').find('.block<?php echo $i; ?>').show();
402
+ jQuery('#bulkdiscount_product_data').find('.options_group<?php echo $i; ?>').show();
403
+ jQuery("#bulkdiscount_product_data").find('#add_discount_line<?php echo $i; ?>').hide();
404
+ jQuery("#bulkdiscount_product_data").find('.options_group<?php echo min($i+1,5); ?>').show();
405
+ jQuery("#bulkdiscount_product_data").find('#add_discount_line<?php echo min($i+1,5); ?>').show();
406
+ <?php
407
+ }
408
+ }
409
+ ?>
410
+ });
411
+ </script>
412
+
413
+ <div id="bulkdiscount_product_data" class="panel woocommerce_options_panel">
414
+
415
+ <div class="options_group">
416
+ <?php
417
+ woocommerce_wp_textarea_input(array('id' => "_bulkdiscount_text_info", 'label' => __('Bulk discount info in product description', 'wc_bulk_discount'), 'description' => __('Optionally enter bulk discount information that will be visible on the product page.', 'wc_bulk_discount'), 'desc_tip' => 'yes', 'class' => 'fullWidth'));
418
+ ?>
419
+ </div>
420
+
421
+ <?php
422
+ for ($i = 1; $i <= 5; $i++) :
423
+ ?>
424
+
425
+ <div class="options_group<?php echo $i; ?>">
426
+ <a id="add_discount_line<?php echo $i; ?>" class="button-secondary"
427
+ href="#block<?php echo $i; ?>">Add discount line</a>
428
+
429
+ <div class="block<?php echo $i; ?>">
430
+ <?php
431
+ woocommerce_wp_text_input(array('id' => "_bulkdiscount_quantity_$i", 'label' => __('Quantity (min.)', 'wc_bulk_discount'), 'description' => __('Enter the minimal quantity for which the discount applies.', 'wc_bulk_discount')));
432
+ if (get_option('woocommerce_t4m_discount_type', '') == 'flat') {
433
+ woocommerce_wp_text_input(array('id' => "_bulkdiscount_discount_flat_$i", 'label' => sprintf(__('Discount (%s)', 'wc_bulk_discount'), get_woocommerce_currency_symbol()), 'description' => sprintf(__('Enter the flat discount in %s.', 'wc_bulk_discount'), get_woocommerce_currency_symbol())));
434
+ } else {
435
+ woocommerce_wp_text_input(array('id' => "_bulkdiscount_discount_$i", 'label' => __('Discount (%)', 'wc_bulk_discount'), 'description' => __('Enter the discount in percents (Allowed values: 0 to 100).', 'wc_bulk_discount')));
436
+ }
437
+ ?>
438
+ </div>
439
+ </div>
440
+
441
+ <?php
442
+ endfor;
443
+ ?>
444
+
445
+ <br/>
446
+
447
+ </div>
448
+
449
+ <?php
450
+ }
451
+
452
+ /**
453
+ * Enqueue frontend dependencies.
454
+ */
455
+ public function action_enqueue_dependencies() {
456
+ wp_register_style('woocommercebulkdiscount-style', plugins_url('css/style.css', __FILE__));
457
+ wp_enqueue_style('woocommercebulkdiscount-style');
458
+ wp_enqueue_script('jquery');
459
+ }
460
+
461
+ /**
462
+ * Enqueue backend dependencies.
463
+ */
464
+ public function action_enqueue_dependencies_admin() {
465
+ wp_register_style('woocommercebulkdiscount-style-admin', plugins_url('css/admin.css', __FILE__));
466
+ wp_enqueue_style('woocommercebulkdiscount-style-admin');
467
+ wp_enqueue_script('jquery');
468
+ }
469
+
470
+ /**
471
+ * Updating post meta.
472
+ *
473
+ * @param $post_id
474
+ */
475
+ public function action_process_meta($post_id) {
476
+ if (isset($_POST['_bulkdiscount_text_info'])) update_post_meta($post_id, '_bulkdiscount_text_info', esc_attr($_POST['_bulkdiscount_text_info']));
477
+ for ($i = 1; $i <= 5; $i++) {
478
+ if (isset($_POST["_bulkdiscount_quantity_$i"])) update_post_meta($post_id, "_bulkdiscount_quantity_$i", stripslashes($_POST["_bulkdiscount_quantity_$i"]));
479
+ if ((get_option('woocommerce_t4m_discount_type', '') == 'flat')) {
480
+ if (isset($_POST["_bulkdiscount_discount_flat_$i"])) update_post_meta($post_id, "_bulkdiscount_discount_flat_$i", stripslashes($_POST["_bulkdiscount_discount_flat_$i"]));
481
+ } else {
482
+ if (isset($_POST["_bulkdiscount_discount_$i"])) update_post_meta($post_id, "_bulkdiscount_discount_$i", stripslashes($_POST["_bulkdiscount_discount_$i"]));
483
+ }
484
+ }
485
+ }
486
+
487
+ /**
488
+ * @access public
489
+ * @return void
490
+ */
491
+ public function add_tab() {
492
+ foreach ($this->settings_tabs as $name => $label) {
493
+ $class = 'nav-tab';
494
+ if ($this->current_tab == $name)
495
+ $class .= ' nav-tab-active';
496
+ echo '<a href="' . admin_url('admin.php?page=woocommerce&tab=' . $name) . '" class="' . $class . '">' . $label . '</a>';
497
+ }
498
+ }
499
+
500
+ /**
501
+ * @access public
502
+ * @return void
503
+ */
504
+ public function settings_tab_action() {
505
+ global $woocommerce_settings;
506
+
507
+ // Determine the current tab in effect.
508
+ $current_tab = $this->get_tab_in_view(current_filter(), 'woocommerce_settings_tabs_');
509
+
510
+ // Hook onto this from another function to keep things clean.
511
+ do_action('woocommerce_bulk_discount_settings');
512
+
513
+ // Display settings for this tab (make sure to add the settings to the tab).
514
+ woocommerce_admin_fields($woocommerce_settings[$current_tab]);
515
+ }
516
+
517
+ /**
518
+ * Save settings in a single field in the database for each tab's fields (one field per tab).
519
+ */
520
+ public function save_settings() {
521
+ global $woocommerce_settings;
522
+
523
+ // Make sure our settings fields are recognised.
524
+ $this->add_settings_fields();
525
+
526
+ $current_tab = $this->get_tab_in_view(current_filter(), 'woocommerce_update_options_');
527
+ woocommerce_update_options($woocommerce_settings[$current_tab]);
528
+ }
529
+
530
+ /**
531
+ * Get the tab current in view/processing.
532
+ */
533
+ public function get_tab_in_view($current_filter, $filter_base) {
534
+ return str_replace($filter_base, '', $current_filter);
535
+ }
536
+
537
+
538
+ /**
539
+ * Add settings fields for each tab.
540
+ */
541
+ public function add_settings_fields() {
542
+ global $woocommerce_settings;
543
+
544
+ // Load the prepared form fields.
545
+ $this->init_form_fields();
546
+
547
+ if (is_array($this->fields))
548
+ foreach ($this->fields as $k => $v)
549
+ $woocommerce_settings[$k] = $v;
550
+ }
551
+
552
+ /**
553
+ * Prepare form fields to be used in the various tabs.
554
+ */
555
+ public function init_form_fields() {
556
+ global $woocommerce;
557
+
558
+ // Define settings
559
+ $this->fields['bulk_discount'] = apply_filters('woocommerce_bulk_discount_settings_fields', array(
560
+
561
+ array('name' => __('Bulk Discount', 'wc_bulk_discount'), 'type' => 'title', 'desc' => __('The following options are specific to product bulk discount.', 'wc_bulk_discount') . '<br /><br/><strong><i>' . __('After changing the settings, it is recommended to clear all sessions in WooCommerce &gt; System Status &gt; Tools.', 'wc_bulk_discount') . '</i></strong>', 'id' => 't4m_bulk_discounts_options'),
562
+
563
+ array(
564
+ 'name' => __('Bulk Discount enabled', 'wc_bulk_discount'),
565
+ 'id' => 'woocommerce_t4m_enable_bulk_discounts',
566
+ 'desc' => __('', 'wc_bulk_discount'),
567
+ 'std' => 'yes',
568
+ 'type' => 'checkbox',
569
+ 'default' => 'yes'
570
+ ),
571
+
572
+ array(
573
+ 'title' => __('Discount Type', 'wc_bulk_discount'),
574
+ 'id' => 'woocommerce_t4m_discount_type',
575
+ 'desc' => sprintf(__('Select the type of discount. Percentage Discount deducts amount of %% from price while Flat Discount deducts fixed amount in %s', 'wc_bulk_discount'), get_woocommerce_currency_symbol()),
576
+ 'desc_tip' => true,
577
+ 'std' => 'yes',
578
+ 'type' => 'select',
579
+ 'css' => 'min-width:200px;',
580
+ 'class' => 'chosen_select',
581
+ 'options' => array(
582
+ '' => __('Percentage Discount', 'wc_bulk_discount'),
583
+ 'flat' => __('Flat Discount', 'wc_bulk_discount')
584
+ )
585
+ ),
586
+
587
+ array(
588
+ 'name' => __('Treat product variations separately', 'wc_bulk_discount'),
589
+ 'id' => 'woocommerce_t4m_variations_separate',
590
+ 'desc' => __('You need to have this option unchecked to handle discounts on product variations as a whole.', 'wc_bulk_discount'),
591
+ 'std' => 'yes',
592
+ 'type' => 'checkbox',
593
+ 'default' => 'yes'
594
+ ),
595
+
596
+ array(
597
+ 'name' => __('Show discount information next to cart item price', 'wc_bulk_discount'),
598
+ 'id' => 'woocommerce_t4m_show_on_item',
599
+ 'desc' => __('Applies only to percentage discount.', 'wc_bulk_discount'),
600
+ 'std' => 'yes',
601
+ 'type' => 'checkbox',
602
+ 'default' => 'yes'
603
+ ),
604
+
605
+ array(
606
+ 'name' => __('Show discount information next to item subtotal price', 'wc_bulk_discount'),
607
+ 'id' => 'woocommerce_t4m_show_on_subtotal',
608
+ 'std' => 'yes',
609
+ 'type' => 'checkbox',
610
+ 'default' => 'yes'
611
+ ),
612
+
613
+ array(
614
+ 'name' => __('Show discount information next to item subtotal price in order history', 'wc_bulk_discount'),
615
+ 'id' => 'woocommerce_t4m_show_on_order_subtotal',
616
+ 'desc' => __('Includes showing discount in order e-mails and invoices.', 'wc_bulk_discount'),
617
+ 'std' => 'yes',
618
+ 'type' => 'checkbox',
619
+ 'default' => 'yes'
620
+ ),
621
+
622
+ array(
623
+ 'name' => __('Optionally enter information about discounts visible on cart page.', 'wc_bulk_discount'),
624
+ 'id' => 'woocommerce_t4m_cart_info',
625
+ 'type' => 'textarea',
626
+ 'css' => 'width:100%; height: 75px;'
627
+ ),
628
+
629
+ array(
630
+ 'name' => __('Optionally change the CSS for old price on cart before discounting.', 'wc_bulk_discount'),
631
+ 'id' => 'woocommerce_t4m_css_old_price',
632
+ 'type' => 'textarea',
633
+ 'css' => 'width:100%;',
634
+ 'default' => 'color: #777; text-decoration: line-through; margin-right: 4px;'
635
+ ),
636
+
637
+ array(
638
+ 'name' => __('Optionally change the CSS for new price on cart after discounting.', 'wc_bulk_discount'),
639
+ 'id' => 'woocommerce_t4m_css_new_price',
640
+ 'type' => 'textarea',
641
+ 'css' => 'width:100%;',
642
+ 'default' => 'color: #4AB915; font-weight: bold;'
643
+ ),
644
+
645
+ array('type' => 'sectionend', 'id' => 't4m_bulk_discounts_options'),
646
+
647
+ array(
648
+ 'desc' => '<b>If you find WooCommerce Bulk Discount useful, please rate the plugin at <a target="_blank" href="http://wordpress.org/plugins/woocommerce-bulk-discount/">http://wordpress.org/plugins/woocommerce-bulk-discount/</a> or kindly consider small donation to support further development.</b>',
649
+ 'id' => 'woocommerce_t4m_begging_text',
650
+ 'type' => 'title'
651
+ ),
652
+
653
+ array('type' => 'sectionend', 'id' => 'woocommerce_t4m_begging_text'),
654
+
655
+ )); // End settings
656
+
657
+ $js = "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  jQuery('#woocommerce_t4m_enable_bulk_discounts').change(function(){
659
 
660
  jQuery('#woocommerce_t4m_cart_info, #woocommerce_t4m_variations_separate, #woocommerce_t4m_discount_type, #woocommerce_t4m_css_old_price, #woocommerce_t4m_css_new_price, #woocommerce_t4m_show_on_item, #woocommerce_t4m_show_on_subtotal, #woocommerce_t4m_show_on_order_subtotal').closest('tr').hide();
674
 
675
  ";
676
 
677
+ if (class_exists('WC_Inline_Javascript_Helper')) {
678
+ $woocommerce->get_helper('inline-javascript')->add_inline_js($js);
679
+ } else {
680
+ $woocommerce->add_inline_js($js);
681
+ }
682
 
683
+ }
684
 
685
+ }
686
 
687
+ $woo_bulk_discount_plugin = new Woo_Bulk_Discount_Plugin_t4m();
688
 
689
  }