Version Description
Download this release
Release Info
Developer | flycart |
Plugin | Discount Rules for WooCommerce |
Version | 1.4 |
Comparing to | |
See all releases |
Code changes from version 1.3 to 1.4
- assets/js/app.js +13 -2
- helper/general-helper.php +1 -1
- includes/cart-rules.php +5 -1
- includes/discount-base.php +475 -475
- includes/pricing-rules.php +51 -36
- loader.php +1 -1
- readme.txt +1 -1
- view/includes/header.php +2 -1
- view/settings.php +18 -0
- view/template/discount-table.php +26 -6
- view/view-pricing-rules.php +259 -259
- woo-discount-rules.php +1 -1
assets/js/app.js
CHANGED
@@ -69,9 +69,10 @@ jQuery.noConflict();
|
|
69 |
if (rule_id == 0) {
|
70 |
console.log(admin_url);
|
71 |
$('#form_price_rule')[0].reset();
|
72 |
-
|
73 |
$(location).attr('href', admin_url);
|
74 |
}
|
|
|
75 |
}
|
76 |
|
77 |
});
|
@@ -93,6 +94,7 @@ jQuery.noConflict();
|
|
93 |
'</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
|
94 |
}
|
95 |
$('#discount_rule_list').append(form);
|
|
|
96 |
});
|
97 |
|
98 |
// Removing Discount Rule.
|
@@ -322,6 +324,7 @@ jQuery.noConflict();
|
|
322 |
//location.reload();
|
323 |
$(location).attr('href', admin_url + '&tab=cart-rules');
|
324 |
}
|
|
|
325 |
}
|
326 |
});
|
327 |
}
|
@@ -420,7 +423,7 @@ jQuery.noConflict();
|
|
420 |
current.removeClass('button-secondary');
|
421 |
current.val('Save Rule');
|
422 |
}, 300);
|
423 |
-
|
424 |
}
|
425 |
});
|
426 |
});
|
@@ -494,4 +497,12 @@ jQuery.noConflict();
|
|
494 |
|
495 |
}
|
496 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
})(jQuery);
|
69 |
if (rule_id == 0) {
|
70 |
console.log(admin_url);
|
71 |
$('#form_price_rule')[0].reset();
|
72 |
+
|
73 |
$(location).attr('href', admin_url);
|
74 |
}
|
75 |
+
adminNotice();
|
76 |
}
|
77 |
|
78 |
});
|
94 |
'</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
|
95 |
}
|
96 |
$('#discount_rule_list').append(form);
|
97 |
+
$('#discount_rule_list').append(form);
|
98 |
});
|
99 |
|
100 |
// Removing Discount Rule.
|
324 |
//location.reload();
|
325 |
$(location).attr('href', admin_url + '&tab=cart-rules');
|
326 |
}
|
327 |
+
adminNotice();
|
328 |
}
|
329 |
});
|
330 |
}
|
423 |
current.removeClass('button-secondary');
|
424 |
current.val('Save Rule');
|
425 |
}, 300);
|
426 |
+
adminNotice();
|
427 |
}
|
428 |
});
|
429 |
});
|
497 |
|
498 |
}
|
499 |
|
500 |
+
function adminNotice() {
|
501 |
+
jQuery('#woo-admin-message').html(' <div class="notice notice-success is-dismissable"><p>Saved Successfully !</p></div>');
|
502 |
+
|
503 |
+
setTimeout(function () {
|
504 |
+
jQuery('#woo-admin-message').html('');
|
505 |
+
}, 2000);
|
506 |
+
}
|
507 |
+
|
508 |
})(jQuery);
|
helper/general-helper.php
CHANGED
@@ -279,7 +279,7 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
279 |
public static function toInt(array &$array)
|
280 |
{
|
281 |
foreach ($array as $index => $item) {
|
282 |
-
$array[$index] = (
|
283 |
}
|
284 |
}
|
285 |
|
279 |
public static function toInt(array &$array)
|
280 |
{
|
281 |
foreach ($array as $index => $item) {
|
282 |
+
$array[$index] = intval($item);
|
283 |
}
|
284 |
}
|
285 |
|
includes/cart-rules.php
CHANGED
@@ -6,7 +6,7 @@ include_once(WOO_DISCOUNT_DIR . '/includes/discount-base.php');
|
|
6 |
/**
|
7 |
* Class woo_dicount_rules_cartRules
|
8 |
*/
|
9 |
-
if (
|
10 |
class woo_dicount_rules_cartRules
|
11 |
{
|
12 |
/**
|
@@ -315,8 +315,12 @@ if ( ! class_exists( 'woo_dicount_rules_cartRules' ) ) {
|
|
315 |
{
|
316 |
$config = new woo_dicount_rules_WooDiscountBase();
|
317 |
$config = $config->getBaseConfig();
|
|
|
|
|
|
|
318 |
// Pre-Defined alternative Coupon Code.
|
319 |
$coupon = 'Discount';
|
|
|
320 |
// Verify and overwrite the Coupon Code.
|
321 |
if (isset($config['coupon_name'])) $coupon = $config['coupon_name'];
|
322 |
return $coupon;
|
6 |
/**
|
7 |
* Class woo_dicount_rules_cartRules
|
8 |
*/
|
9 |
+
if (!class_exists('woo_dicount_rules_cartRules')) {
|
10 |
class woo_dicount_rules_cartRules
|
11 |
{
|
12 |
/**
|
315 |
{
|
316 |
$config = new woo_dicount_rules_WooDiscountBase();
|
317 |
$config = $config->getBaseConfig();
|
318 |
+
|
319 |
+
if (is_string($config)) $config = json_decode($config, true);
|
320 |
+
|
321 |
// Pre-Defined alternative Coupon Code.
|
322 |
$coupon = 'Discount';
|
323 |
+
|
324 |
// Verify and overwrite the Coupon Code.
|
325 |
if (isset($config['coupon_name'])) $coupon = $config['coupon_name'];
|
326 |
return $coupon;
|
includes/discount-base.php
CHANGED
@@ -9,557 +9,557 @@ global $woocommerce;
|
|
9 |
/**
|
10 |
* Class woo_dicount_rules_WooDiscountBase
|
11 |
*/
|
12 |
-
if (
|
13 |
-
class woo_dicount_rules_WooDiscountBase
|
14 |
-
{
|
15 |
-
/**
|
16 |
-
* @var string
|
17 |
-
*/
|
18 |
-
public $default_page = 'pricing-rules';
|
19 |
-
|
20 |
-
/**
|
21 |
-
* @var string
|
22 |
-
*/
|
23 |
-
public $default_option = 'woo-discount-config';
|
24 |
-
|
25 |
-
/**
|
26 |
-
* @var array
|
27 |
-
*/
|
28 |
-
private $instance = array();
|
29 |
-
|
30 |
-
/**
|
31 |
-
* woo_dicount_rules_WooDiscountBase constructor.
|
32 |
-
*/
|
33 |
-
public function __construct()
|
34 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
} else {
|
51 |
-
$instance =
|
52 |
}
|
53 |
-
|
54 |
-
$instance = $this->instance[$name];
|
55 |
}
|
56 |
-
return $instance;
|
57 |
-
}
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
$price_discount = $this->getInstance('woo_dicount_rules_pricingRules');
|
67 |
-
$cart_discount = $this->getInstance('woo_dicount_rules_cartRules');
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
}
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
* @param $title
|
77 |
-
* @return mixed
|
78 |
-
*/
|
79 |
-
public function modifyName($title)
|
80 |
-
{
|
81 |
-
//
|
82 |
-
return $title;
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Finally, on triggering the "Thank You" hook by WooCommerce,
|
87 |
-
* Overall session data's are stored to the order's meta as "woo_discount_log".
|
88 |
-
*
|
89 |
-
* @param integer $order_id Order ID.
|
90 |
-
*/
|
91 |
-
public function storeLog($order_id)
|
92 |
-
{
|
93 |
-
$log['price_discount'] = WC()->session->get('woo_price_discount', array());
|
94 |
-
$log['cart_discount'] = WC()->session->get('woo_cart_discount', array());
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
119 |
}
|
120 |
-
}
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
137 |
}
|
138 |
-
|
139 |
}
|
140 |
-
die();
|
141 |
-
}
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
157 |
}
|
|
|
158 |
}
|
159 |
-
die();
|
160 |
-
}
|
161 |
// -------------------------------------- PRICE RULES ---------------------------------------------------------------
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
176 |
-
$pricing_rule->save($params);
|
177 |
-
die();
|
178 |
-
}
|
179 |
-
|
180 |
-
// -------------------------------------- CART RULES ----------------------------------------------------------------
|
181 |
-
/**
|
182 |
-
* Saving the Cart Rule.
|
183 |
-
*
|
184 |
-
* @return bool
|
185 |
-
*/
|
186 |
-
public function saveCartRule()
|
187 |
-
{
|
188 |
-
|
189 |
-
$postData = \FlycartInput\FInput::getInstance();
|
190 |
-
$request = $postData->getArray();
|
191 |
-
$params = array();
|
192 |
-
if (!isset($request['data'])) return false;
|
193 |
-
parse_str($request['data'], $params);
|
194 |
-
$this->parseFormWithRules($params, true);
|
195 |
-
$pricing_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
196 |
-
$pricing_rule->save($params);
|
197 |
-
die();
|
198 |
-
}
|
199 |
-
|
200 |
-
/**
|
201 |
-
* Making the reliable end data to store.
|
202 |
-
*
|
203 |
-
* @param $cart_rules
|
204 |
-
* @param bool $isCartRules
|
205 |
-
*/
|
206 |
-
public function parseFormWithRules(&$cart_rules, $isCartRules = false)
|
207 |
-
{
|
208 |
-
$cart_rules['discount_rule'] = $this->generateFormData($cart_rules, $isCartRules);
|
209 |
-
}
|
210 |
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
*/
|
216 |
-
public function generateFormData($cart_rules, $isCartRules = false)
|
217 |
-
{
|
218 |
-
$link = $this->fieldLink();
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
-
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
}
|
233 |
-
} else {
|
234 |
-
$discount_list[$index][$value['type']] = $value['option_value'];
|
235 |
}
|
236 |
}
|
237 |
-
|
238 |
-
return $discount_list;
|
239 |
|
240 |
-
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
|
261 |
-
|
262 |
|
263 |
|
264 |
-
|
265 |
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
|
278 |
-
|
279 |
-
|
280 |
// $params[$index] = woo_dicount_rules_generalHelper::makeString($item);
|
281 |
-
|
|
|
|
|
282 |
}
|
283 |
-
$params = json_encode($params);
|
284 |
-
}
|
285 |
// else {
|
286 |
// $params = woo_dicount_rules_generalHelper::makeString($params);
|
287 |
// }
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
|
|
293 |
}
|
294 |
-
die();
|
295 |
-
}
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
|
|
307 |
}
|
308 |
-
}
|
309 |
-
|
310 |
-
// -------------------------------------------SETTINGS END----------------------------------------------------------
|
311 |
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
if (
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
|
|
|
|
|
|
342 |
}
|
343 |
}
|
344 |
}
|
345 |
}
|
346 |
-
}
|
347 |
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
|
|
|
|
|
|
363 |
}
|
364 |
-
} else {
|
365 |
-
$option = $option . '-' . $postData->get('type', '');
|
366 |
}
|
367 |
}
|
368 |
-
}
|
369 |
-
|
370 |
-
/**
|
371 |
-
* @param $request
|
372 |
-
*/
|
373 |
-
public function save($request)
|
374 |
-
{
|
375 |
-
// Save General Settings of the Plugin.
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
* @return array
|
380 |
-
*/
|
381 |
-
public function formList()
|
382 |
-
{
|
383 |
-
return array(
|
384 |
-
'pricing_rules',
|
385 |
-
'cart_rules',
|
386 |
-
'settings'
|
387 |
-
);
|
388 |
-
}
|
389 |
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
$this->checkSubmission($request);
|
398 |
|
399 |
-
|
400 |
-
|
401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
}
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
$this->
|
419 |
-
//
|
420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
}
|
422 |
-
echo $html;
|
423 |
-
}
|
424 |
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
|
|
|
|
439 |
}
|
440 |
-
return $path;
|
441 |
-
}
|
442 |
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
459 |
-
$data = $pricing_rule->getRules();
|
460 |
-
break;
|
461 |
-
// Managing Cart Rules View.
|
462 |
-
case 'cart-rules':
|
463 |
-
$cart_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
464 |
-
$data = $cart_rule->getRules();
|
465 |
-
break;
|
466 |
-
// Managing View of Settings.
|
467 |
-
case 'settings':
|
468 |
-
$data = $this->getBaseConfig();
|
469 |
-
break;
|
470 |
-
|
471 |
-
// Managing View of Pricing Rules.
|
472 |
-
case 'pricing-rules-new':
|
473 |
-
$data = new stdClass();
|
474 |
-
$data->form = 'pricing_rules_save';
|
475 |
-
if (!$isPro) {
|
476 |
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
477 |
$data = $pricing_rule->getRules();
|
478 |
-
|
479 |
-
|
480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
|
482 |
-
|
483 |
-
|
484 |
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
if (!$isPro) {
|
507 |
$cart_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
508 |
$total_record = $cart_rule->getRules(true);
|
509 |
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
510 |
}
|
511 |
-
|
512 |
|
513 |
-
|
514 |
-
|
515 |
-
if (isset($out) && !empty($out)) {
|
516 |
-
$data[] = $out;
|
517 |
-
}
|
518 |
-
break;
|
519 |
-
// Managing View of Cart Rules.
|
520 |
-
case 'cart-rules-new':
|
521 |
-
if (!$isPro) {
|
522 |
-
$cart_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
523 |
-
$total_record = $cart_rule->getRules(true);
|
524 |
-
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
525 |
-
}
|
526 |
-
break;
|
527 |
|
528 |
-
|
529 |
-
|
530 |
|
531 |
-
break;
|
532 |
}
|
533 |
|
534 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
535 |
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
return array(
|
542 |
-
$this->default_page => WOO_DISCOUNT_DIR . '/view/pricing-rules.php',
|
543 |
-
'cart-rules' => WOO_DISCOUNT_DIR . '/view/cart-rules.php',
|
544 |
-
'settings' => WOO_DISCOUNT_DIR . '/view/settings.php',
|
545 |
-
|
546 |
-
// New Rule also access the same "View" to process
|
547 |
-
'pricing-rules-new' => WOO_DISCOUNT_DIR . '/view/view-pricing-rules.php',
|
548 |
-
'cart-rules-new' => WOO_DISCOUNT_DIR . '/view/view-cart-rules.php',
|
549 |
-
|
550 |
-
// Edit Rules
|
551 |
-
'pricing-rules-view' => WOO_DISCOUNT_DIR . '/view/view-pricing-rules.php',
|
552 |
-
'cart-rules-view' => WOO_DISCOUNT_DIR . '/view/view-cart-rules.php'
|
553 |
-
);
|
554 |
-
}
|
555 |
|
556 |
-
|
557 |
-
*
|
558 |
-
*/
|
559 |
-
public function getOption()
|
560 |
-
{
|
561 |
|
562 |
}
|
563 |
-
|
564 |
-
}
|
565 |
}
|
9 |
/**
|
10 |
* Class woo_dicount_rules_WooDiscountBase
|
11 |
*/
|
12 |
+
if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
13 |
+
class woo_dicount_rules_WooDiscountBase
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
{
|
15 |
+
/**
|
16 |
+
* @var string
|
17 |
+
*/
|
18 |
+
public $default_page = 'pricing-rules';
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var string
|
22 |
+
*/
|
23 |
+
public $default_option = 'woo-discount-config';
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @var array
|
27 |
+
*/
|
28 |
+
private $instance = array();
|
29 |
+
|
30 |
+
/**
|
31 |
+
* woo_dicount_rules_WooDiscountBase constructor.
|
32 |
+
*/
|
33 |
+
public function __construct()
|
34 |
+
{
|
35 |
|
36 |
+
}
|
37 |
|
38 |
+
/**
|
39 |
+
* Singleton Instance maker.
|
40 |
+
*
|
41 |
+
* @param $name
|
42 |
+
* @return bool
|
43 |
+
*/
|
44 |
+
public function getInstance($name)
|
45 |
+
{
|
46 |
+
if (!isset($this->instance[$name])) {
|
47 |
+
if (class_exists($name)) {
|
48 |
+
$this->instance[$name] = new $name;
|
49 |
+
$instance = $this->instance[$name];
|
50 |
+
} else {
|
51 |
+
$instance = false;
|
52 |
+
}
|
53 |
} else {
|
54 |
+
$instance = $this->instance[$name];
|
55 |
}
|
56 |
+
return $instance;
|
|
|
57 |
}
|
|
|
|
|
58 |
|
59 |
+
/**
|
60 |
+
* Managing discount of Price and Cart.
|
61 |
+
*/
|
62 |
+
public function handleDiscount()
|
63 |
+
{
|
64 |
+
global $woocommerce;
|
|
|
|
|
|
|
65 |
|
66 |
+
$price_discount = $this->getInstance('woo_dicount_rules_pricingRules');
|
67 |
+
$cart_discount = $this->getInstance('woo_dicount_rules_cartRules');
|
|
|
68 |
|
69 |
+
$price_discount->analyse($woocommerce);
|
70 |
+
$cart_discount->analyse($woocommerce);
|
71 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
/**
|
74 |
+
* WooCommerce hook to change the name of a product.
|
75 |
+
*
|
76 |
+
* @param $title
|
77 |
+
* @return mixed
|
78 |
+
*/
|
79 |
+
public function modifyName($title)
|
80 |
+
{
|
81 |
+
//
|
82 |
+
return $title;
|
83 |
+
}
|
84 |
|
85 |
+
/**
|
86 |
+
* Finally, on triggering the "Thank You" hook by WooCommerce,
|
87 |
+
* Overall session data's are stored to the order's meta as "woo_discount_log".
|
88 |
+
*
|
89 |
+
* @param integer $order_id Order ID.
|
90 |
+
*/
|
91 |
+
public function storeLog($order_id)
|
92 |
+
{
|
93 |
+
$log['price_discount'] = WC()->session->get('woo_price_discount', array());
|
94 |
+
$log['cart_discount'] = WC()->session->get('woo_cart_discount', array());
|
95 |
+
|
96 |
+
add_post_meta($order_id, 'woo_discount_log', json_encode($log));
|
97 |
+
|
98 |
+
// Reset the Coupon Status.
|
99 |
+
WC()->session->set('woo_coupon_removed', '');
|
100 |
+
}
|
101 |
|
102 |
+
/**
|
103 |
+
* Create New Menu On WooCommerce.
|
104 |
+
*/
|
105 |
+
public function adminMenu()
|
106 |
+
{
|
107 |
+
if (!is_admin()) return;
|
108 |
+
|
109 |
+
global $submenu;
|
110 |
+
if (isset($submenu['woocommerce'])) {
|
111 |
+
add_submenu_page(
|
112 |
+
'woocommerce',
|
113 |
+
'Woo Discount Rules',
|
114 |
+
'Woo Discount Rules',
|
115 |
+
'edit_posts',
|
116 |
+
'woo_discount_rules',
|
117 |
+
array($this, 'viewManager')
|
118 |
+
);
|
119 |
+
}
|
120 |
}
|
|
|
121 |
|
122 |
+
/**
|
123 |
+
* Update the Status of the Rule Set.
|
124 |
+
*/
|
125 |
+
public function updateStatus()
|
126 |
+
{
|
127 |
+
$postData = \FlycartInput\FInput::getInstance();
|
128 |
+
$id = $postData->get('id', false);
|
129 |
+
if ($id) {
|
130 |
+
$status = get_post_meta($id, 'status', false);
|
131 |
+
if (isset($status[0])) {
|
132 |
+
$state = ($status[0] == 'publish') ? 'disable' : 'publish';
|
133 |
+
update_post_meta($id, 'status', $state);
|
134 |
+
} else {
|
135 |
+
add_post_meta($id, 'status', 'disable');
|
136 |
+
$state = 'disable';
|
137 |
+
}
|
138 |
+
echo ucfirst($state);
|
139 |
}
|
140 |
+
die();
|
141 |
}
|
|
|
|
|
142 |
|
143 |
+
/**
|
144 |
+
* Remove the Rule Set.
|
145 |
+
*/
|
146 |
+
public function removeRule()
|
147 |
+
{
|
148 |
+
$postData = \FlycartInput\FInput::getInstance();
|
149 |
+
$id = $postData->get('id', false);
|
150 |
+
if ($id) {
|
151 |
+
try {
|
152 |
+
$id = intval($id);
|
153 |
+
if (!$id) return false;
|
154 |
+
wp_delete_post($id);
|
155 |
+
} catch (Exception $e) {
|
156 |
+
//
|
157 |
+
}
|
158 |
}
|
159 |
+
die();
|
160 |
}
|
|
|
|
|
161 |
// -------------------------------------- PRICE RULES ---------------------------------------------------------------
|
162 |
+
/**
|
163 |
+
* Saving the Price Rule.
|
164 |
+
*
|
165 |
+
* @return bool
|
166 |
+
*/
|
167 |
+
public function savePriceRule()
|
168 |
+
{
|
169 |
+
$postData = \FlycartInput\FInput::getInstance();
|
170 |
+
$request = $postData->getArray();
|
171 |
+
$params = array();
|
172 |
+
if (!isset($request['data'])) return false;
|
173 |
+
parse_str($request['data'], $params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
+
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
176 |
+
$pricing_rule->save($params);
|
177 |
+
die();
|
178 |
+
}
|
|
|
|
|
|
|
|
|
179 |
|
180 |
+
// -------------------------------------- CART RULES ----------------------------------------------------------------
|
181 |
+
/**
|
182 |
+
* Saving the Cart Rule.
|
183 |
+
*
|
184 |
+
* @return bool
|
185 |
+
*/
|
186 |
+
public function saveCartRule()
|
187 |
+
{
|
188 |
+
|
189 |
+
$postData = \FlycartInput\FInput::getInstance();
|
190 |
+
$request = $postData->getArray();
|
191 |
+
$params = array();
|
192 |
+
if (!isset($request['data'])) return false;
|
193 |
+
parse_str($request['data'], $params);
|
194 |
+
$this->parseFormWithRules($params, true);
|
195 |
+
$pricing_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
196 |
+
$pricing_rule->save($params);
|
197 |
+
die();
|
198 |
+
}
|
199 |
|
200 |
+
/**
|
201 |
+
* Making the reliable end data to store.
|
202 |
+
*
|
203 |
+
* @param $cart_rules
|
204 |
+
* @param bool $isCartRules
|
205 |
+
*/
|
206 |
+
public function parseFormWithRules(&$cart_rules, $isCartRules = false)
|
207 |
+
{
|
208 |
+
$cart_rules['discount_rule'] = $this->generateFormData($cart_rules, $isCartRules);
|
209 |
+
}
|
210 |
|
211 |
+
/**
|
212 |
+
* @param $cart_rules
|
213 |
+
* @param bool $isCartRules
|
214 |
+
* @return array
|
215 |
+
*/
|
216 |
+
public function generateFormData($cart_rules, $isCartRules = false)
|
217 |
+
{
|
218 |
+
$link = $this->fieldLink();
|
219 |
+
|
220 |
+
$discount_list = array();
|
221 |
+
// Here, Eliminating the Cart's rule with duplicates.
|
222 |
+
$discount_rule = (isset($cart_rules['discount_rule']) ? $cart_rules['discount_rule'] : array());
|
223 |
+
if ($isCartRules) {
|
224 |
+
foreach ($discount_rule as $index => $value) {
|
225 |
+
|
226 |
+
// The Type of Option should get value from it's native index.
|
227 |
+
// $link[$value['type']] will gives the native index of the "type"
|
228 |
+
|
229 |
+
if (isset($link[$value['type']])) {
|
230 |
+
if (isset($value[$link[$value['type']]])) {
|
231 |
+
$discount_list[$index][$value['type']] = $value[$link[$value['type']]];
|
232 |
+
}
|
233 |
+
} else {
|
234 |
+
$discount_list[$index][$value['type']] = $value['option_value'];
|
235 |
}
|
|
|
|
|
236 |
}
|
237 |
}
|
238 |
+
return $discount_list;
|
|
|
239 |
|
240 |
+
}
|
241 |
|
242 |
+
/**
|
243 |
+
* @return array
|
244 |
+
*/
|
245 |
+
public function fieldLink()
|
246 |
+
{
|
247 |
+
// TODO: Check Subtotal Link
|
248 |
+
return array(
|
249 |
+
'products_atleast_one' => 'product_to_apply',
|
250 |
+
'products_not_in' => 'product_to_apply',
|
251 |
+
|
252 |
+
'categories_atleast_one' => 'category_to_apply',
|
253 |
+
'categories_not_in' => 'category_to_apply',
|
254 |
+
|
255 |
+
'users_in' => 'users_to_apply',
|
256 |
+
'roles_in' => 'user_roles_to_apply',
|
257 |
+
'shipping_countries_in' => 'countries_to_apply'
|
258 |
+
);
|
259 |
+
}
|
260 |
|
261 |
+
// ----------------------------------------- CART RULES END --------------------------------------------------------
|
262 |
|
263 |
|
264 |
+
// -------------------------------------------SETTINGS--------------------------------------------------------------
|
265 |
|
266 |
+
/**
|
267 |
+
*
|
268 |
+
*/
|
269 |
+
public function saveConfig()
|
270 |
+
{
|
271 |
+
$postData = \FlycartInput\FInput::getInstance();
|
272 |
+
$request = $postData->getArray();
|
273 |
+
$params = array();
|
274 |
+
if (isset($request['data'])) {
|
275 |
+
parse_str($request['data'], $params);
|
276 |
+
}
|
277 |
|
278 |
+
if (is_array($request)) {
|
279 |
+
foreach ($params as $index => $item) {
|
280 |
// $params[$index] = woo_dicount_rules_generalHelper::makeString($item);
|
281 |
+
$params[$index] = $item;
|
282 |
+
}
|
283 |
+
$params = json_encode($params);
|
284 |
}
|
|
|
|
|
285 |
// else {
|
286 |
// $params = woo_dicount_rules_generalHelper::makeString($params);
|
287 |
// }
|
288 |
|
289 |
+
if (get_option($this->default_option)) {
|
290 |
+
update_option($this->default_option, $params);
|
291 |
+
} else {
|
292 |
+
add_option($this->default_option, $params);
|
293 |
+
}
|
294 |
+
die();
|
295 |
}
|
|
|
|
|
296 |
|
297 |
+
/**
|
298 |
+
* @return array
|
299 |
+
*/
|
300 |
+
public function getBaseConfig()
|
301 |
+
{
|
302 |
+
$option = get_option($this->default_option);
|
303 |
+
if (!$option || is_null($option)) {
|
304 |
+
return array();
|
305 |
+
} else {
|
306 |
+
return $option;
|
307 |
+
}
|
308 |
}
|
|
|
|
|
|
|
309 |
|
310 |
+
// -------------------------------------------SETTINGS END----------------------------------------------------------
|
311 |
+
|
312 |
+
/**
|
313 |
+
* @param $request
|
314 |
+
* @return bool
|
315 |
+
*/
|
316 |
+
public function checkSubmission($request)
|
317 |
+
{
|
318 |
+
if (isset($request['form']) && !empty($request['form'])) {
|
319 |
+
$form = sanitize_text_field($request['form']);
|
320 |
+
if (strpos($form, '_save') === false) return false;
|
321 |
+
// For Saving Form
|
322 |
+
$form = str_replace('_save', '', $form);
|
323 |
+
// To Verify, the submitted form is in the Registered List or Not
|
324 |
+
if (in_array($form, $this->formList())) {
|
325 |
+
if (isset($request['page'])) {
|
326 |
+
switch ($form) {
|
327 |
+
case 'pricing_rules':
|
328 |
+
die(123);
|
329 |
+
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
330 |
+
$pricing_rule->save($request);
|
331 |
+
break;
|
332 |
+
case 'cart_rules':
|
333 |
+
$cart_rules = $this->getInstance('woo_dicount_rules_cartRules');
|
334 |
+
$cart_rules->save($request);
|
335 |
+
break;
|
336 |
+
case 'settings':
|
337 |
+
$this->save($request);
|
338 |
+
break;
|
339 |
+
default:
|
340 |
+
// Invalid Submission.
|
341 |
+
break;
|
342 |
+
}
|
343 |
}
|
344 |
}
|
345 |
}
|
346 |
}
|
|
|
347 |
|
348 |
+
/**
|
349 |
+
* @param $option
|
350 |
+
*/
|
351 |
+
public function checkAccess(&$option)
|
352 |
+
{
|
353 |
+
$postData = \FlycartInput\FInput::getInstance();
|
354 |
+
// Handling View
|
355 |
+
if ($postData->get('view', false)) {
|
356 |
+
$option = $option . '-view';
|
357 |
+
// Type : Price or Cart Discounts.
|
358 |
+
} elseif ($postData->get('type', false)) {
|
359 |
+
if ($postData->get('tab', false)) {
|
360 |
+
if ($postData->get('tab', '') == 'cart-rules') {
|
361 |
+
$option = 'cart-rules-new';
|
362 |
+
if ($postData->get('type', '') == 'view') $option = 'cart-rules-view';
|
363 |
+
}
|
364 |
+
} else {
|
365 |
+
$option = $option . '-' . $postData->get('type', '');
|
366 |
}
|
|
|
|
|
367 |
}
|
368 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
|
370 |
+
/**
|
371 |
+
* @param $request
|
372 |
+
*/
|
373 |
+
public function save($request)
|
374 |
+
{
|
375 |
+
// Save General Settings of the Plugin.
|
376 |
+
}
|
|
|
377 |
|
378 |
+
/**
|
379 |
+
* @return array
|
380 |
+
*/
|
381 |
+
public function formList()
|
382 |
+
{
|
383 |
+
return array(
|
384 |
+
'pricing_rules',
|
385 |
+
'cart_rules',
|
386 |
+
'settings'
|
387 |
+
);
|
388 |
}
|
389 |
+
|
390 |
+
/**
|
391 |
+
*
|
392 |
+
*/
|
393 |
+
public function viewManager()
|
394 |
+
{
|
395 |
+
$postData = \FlycartInput\FInput::getInstance();
|
396 |
+
$request = $postData->getArray();
|
397 |
+
$this->checkSubmission($request);
|
398 |
+
|
399 |
+
// Adding Plugin Page Script
|
400 |
+
if (function_exists('woo_discount_adminPageScript')) {
|
401 |
+
woo_discount_adminPageScript();
|
402 |
+
}
|
403 |
+
// Loading Instance.
|
404 |
+
$generalHelper = $this->getInstance('woo_dicount_rules_generalHelper');
|
405 |
+
// Sanity Check.
|
406 |
+
if (!$generalHelper) return;
|
407 |
+
// Getting Active Tab.
|
408 |
+
$tab = $generalHelper->getCurrentTab();
|
409 |
+
|
410 |
+
$path = $this->getPath($tab);
|
411 |
+
|
412 |
+
// Manage Tab.
|
413 |
+
$tab = (isset($tab) ? $tab : $this->default_page);
|
414 |
+
$html = '';
|
415 |
+
// File Check.
|
416 |
+
if (file_exists($path)) {
|
417 |
+
$data = array();
|
418 |
+
$this->fetchData($tab, $data);
|
419 |
+
// Processing View.
|
420 |
+
$html = $generalHelper->processBaseView($path, $data);
|
421 |
+
}
|
422 |
+
echo $html;
|
423 |
}
|
|
|
|
|
424 |
|
425 |
+
/**
|
426 |
+
* @param $tab
|
427 |
+
* @return mixed
|
428 |
+
*/
|
429 |
+
public function getPath(&$tab)
|
430 |
+
{
|
431 |
+
$this->checkAccess($tab);
|
432 |
+
$pages = $this->adminPages();
|
433 |
+
// Default tab.
|
434 |
+
$path = $pages[$this->default_page];
|
435 |
+
|
436 |
+
// Comparing Available Tab with Active Tab.
|
437 |
+
if (isset($pages[$tab])) {
|
438 |
+
$path = $pages[$tab];
|
439 |
+
}
|
440 |
+
return $path;
|
441 |
}
|
|
|
|
|
442 |
|
443 |
+
/**
|
444 |
+
* @param $type
|
445 |
+
* @param $data
|
446 |
+
*/
|
447 |
+
public function fetchData($type, &$data)
|
448 |
+
{
|
449 |
+
$postData = \FlycartInput\FInput::getInstance();
|
450 |
+
$request = $postData->getArray();
|
451 |
+
|
452 |
+
$helper = new woo_dicount_rules_generalHelper();
|
453 |
+
$isPro = $helper->checkPluginState();
|
454 |
+
|
455 |
+
switch ($type) {
|
456 |
+
// Managing Price Rules View.
|
457 |
+
case 'pricing-rules':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
459 |
$data = $pricing_rule->getRules();
|
460 |
+
break;
|
461 |
+
// Managing Cart Rules View.
|
462 |
+
case 'cart-rules':
|
463 |
+
$cart_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
464 |
+
$data = $cart_rule->getRules();
|
465 |
+
break;
|
466 |
+
// Managing View of Settings.
|
467 |
+
case 'settings':
|
468 |
+
$data = $this->getBaseConfig();
|
469 |
+
break;
|
470 |
+
|
471 |
+
// Managing View of Pricing Rules.
|
472 |
+
case 'pricing-rules-new':
|
473 |
+
$data = new stdClass();
|
474 |
+
$data->form = 'pricing_rules_save';
|
475 |
+
if (!$isPro) {
|
476 |
+
$pricing_rule = $this->getInstance('woo_dicount_rules_pricingRules');
|
477 |
+
$data = $pricing_rule->getRules();
|
478 |
+
if (count($data) >= 3) die('You are restricted to process this action.');
|
479 |
+
}
|
480 |
+
break;
|
481 |
|
482 |
+
// Managing View of Pricing Rules.
|
483 |
+
case 'pricing-rules-view':
|
484 |
|
485 |
+
$view = false;
|
486 |
+
// Handling View
|
487 |
+
if (isset($request['view'])) {
|
488 |
+
$view = $request['view'];
|
489 |
+
}
|
490 |
+
$html = $this->getInstance('woo_dicount_rules_pricingRules');
|
491 |
+
$out = $html->view($type, $view);
|
492 |
+
if (isset($out) && !empty($out)) {
|
493 |
+
$data = $out;
|
494 |
+
}
|
495 |
+
$data->form = 'pricing_rules_save';
|
496 |
+
break;
|
497 |
+
|
498 |
+
// Managing View of Cart Rules.
|
499 |
+
case 'cart-rules-view':
|
500 |
+
$view = false;
|
501 |
+
// Handling View
|
502 |
+
if (isset($request['view'])) {
|
503 |
+
$view = $request['view'];
|
504 |
+
} else {
|
505 |
+
|
506 |
+
if (!$isPro) {
|
507 |
+
$cart_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
508 |
+
$total_record = $cart_rule->getRules(true);
|
509 |
+
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
510 |
+
}
|
511 |
+
}
|
512 |
|
513 |
+
$html = $this->getInstance('woo_dicount_rules_cartRules');
|
514 |
+
$out = $html->view($type, $view);
|
515 |
+
if (isset($out) && !empty($out)) {
|
516 |
+
$data[] = $out;
|
517 |
+
}
|
518 |
+
break;
|
519 |
+
// Managing View of Cart Rules.
|
520 |
+
case 'cart-rules-new':
|
521 |
if (!$isPro) {
|
522 |
$cart_rule = $this->getInstance('woo_dicount_rules_cartRules');
|
523 |
$total_record = $cart_rule->getRules(true);
|
524 |
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
525 |
}
|
526 |
+
break;
|
527 |
|
528 |
+
default:
|
529 |
+
$data = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
|
531 |
+
break;
|
532 |
+
}
|
533 |
|
|
|
534 |
}
|
535 |
|
536 |
+
/**
|
537 |
+
* @return array
|
538 |
+
*/
|
539 |
+
public function adminPages()
|
540 |
+
{
|
541 |
+
return array(
|
542 |
+
$this->default_page => WOO_DISCOUNT_DIR . '/view/pricing-rules.php',
|
543 |
+
'cart-rules' => WOO_DISCOUNT_DIR . '/view/cart-rules.php',
|
544 |
+
'settings' => WOO_DISCOUNT_DIR . '/view/settings.php',
|
545 |
+
|
546 |
+
// New Rule also access the same "View" to process
|
547 |
+
'pricing-rules-new' => WOO_DISCOUNT_DIR . '/view/view-pricing-rules.php',
|
548 |
+
'cart-rules-new' => WOO_DISCOUNT_DIR . '/view/view-cart-rules.php',
|
549 |
+
|
550 |
+
// Edit Rules
|
551 |
+
'pricing-rules-view' => WOO_DISCOUNT_DIR . '/view/view-pricing-rules.php',
|
552 |
+
'cart-rules-view' => WOO_DISCOUNT_DIR . '/view/view-cart-rules.php'
|
553 |
+
);
|
554 |
+
}
|
555 |
|
556 |
+
/**
|
557 |
+
*
|
558 |
+
*/
|
559 |
+
public function getOption()
|
560 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
561 |
|
562 |
+
}
|
|
|
|
|
|
|
|
|
563 |
|
564 |
}
|
|
|
|
|
565 |
}
|
includes/pricing-rules.php
CHANGED
@@ -5,7 +5,7 @@ include_once(WOO_DISCOUNT_DIR . '/helper/general-helper.php');
|
|
5 |
/**
|
6 |
* Class woo_dicount_rules_pricingRules
|
7 |
*/
|
8 |
-
if (
|
9 |
class woo_dicount_rules_pricingRules
|
10 |
{
|
11 |
/**
|
@@ -48,6 +48,11 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
48 |
*/
|
49 |
public $apply_to;
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
public $postData;
|
52 |
|
53 |
/**
|
@@ -79,7 +84,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
79 |
*/
|
80 |
public function save($request)
|
81 |
{
|
82 |
-
|
83 |
// die();
|
84 |
// foreach ($request as $index => $value) {
|
85 |
// $request[$index] = $value;
|
@@ -139,7 +144,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
139 |
'rule_order'
|
140 |
);
|
141 |
|
142 |
-
|
143 |
// Manage Products with it's ID or Category.
|
144 |
$apply_to = 'all_products';
|
145 |
|
@@ -153,7 +158,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
153 |
$form[] = $apply_to;
|
154 |
|
155 |
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
156 |
-
|
157 |
|
158 |
// Manage Users.
|
159 |
$apply_to = 'all';
|
@@ -166,13 +171,15 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
166 |
$form[] = $apply_to;
|
167 |
|
168 |
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
169 |
-
|
170 |
|
171 |
// Manage list of Discount Ranges.
|
172 |
if (isset($request['discount_range'])) {
|
173 |
|
174 |
foreach ($request['discount_range'] as $index => $value) {
|
175 |
$request['discount_range'][$index] = woo_dicount_rules_generalHelper::makeString($value);
|
|
|
|
|
176 |
}
|
177 |
|
178 |
$request['discount_range'] = json_encode($request['discount_range']);
|
@@ -252,7 +259,6 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
252 |
foreach ($posts as $index => $item) {
|
253 |
$posts[$index]->meta = get_post_meta($posts[$index]->ID);
|
254 |
}
|
255 |
-
|
256 |
$this->rules = $posts;
|
257 |
}
|
258 |
return $posts;
|
@@ -273,6 +279,19 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
273 |
WC()->session->set('woo_price_discount', json_encode($discount_log));
|
274 |
}
|
275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
/**
|
277 |
* List of Checklist.
|
278 |
*/
|
@@ -305,7 +324,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
305 |
$today = strtotime(date('m/d/Y'));
|
306 |
|
307 |
// Validating Rule with Date of Expiry.
|
308 |
-
if (($date_from <= $today) && ($date_to > $today)) {
|
309 |
|
310 |
// Validating the Rule with its Order ID.
|
311 |
if (isset($rule->rule_order)) {
|
@@ -444,40 +463,35 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
444 |
* @param $index
|
445 |
* @param array $item line item.
|
446 |
*/
|
447 |
-
public function matchRules(
|
448 |
{
|
449 |
$applied_rules = array();
|
450 |
-
$quantity
|
451 |
-
$i
|
452 |
-
foreach (
|
453 |
-
{
|
454 |
|
455 |
-
if (
|
456 |
-
{
|
457 |
|
458 |
// Working with Products and Category.
|
459 |
-
switch (
|
460 |
-
{
|
461 |
|
462 |
case 'specific_products':
|
463 |
|
464 |
-
if (
|
465 |
-
|
466 |
-
$applied_rules[
|
467 |
-
$applied_rules[
|
468 |
-
$applied_rules[
|
469 |
-
$applied_rules[ $i ]['id'] = $item['product_id'];
|
470 |
}
|
471 |
|
472 |
break;
|
473 |
|
474 |
case 'specific_category':
|
475 |
-
if (
|
476 |
-
|
477 |
-
$applied_rules[
|
478 |
-
$applied_rules[
|
479 |
-
$applied_rules[
|
480 |
-
$applied_rules[ $i ]['id'] = $item['product_id'];
|
481 |
}
|
482 |
|
483 |
|
@@ -486,18 +500,17 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
486 |
case 'all_products':
|
487 |
default:
|
488 |
|
489 |
-
$applied_rules[
|
490 |
-
$applied_rules[
|
491 |
-
$applied_rules[
|
492 |
-
$applied_rules[
|
493 |
|
494 |
break;
|
495 |
-
|
496 |
}
|
497 |
}
|
498 |
-
$i
|
499 |
}
|
500 |
-
$this->matched_sets[
|
501 |
}
|
502 |
|
503 |
/**
|
@@ -508,6 +521,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
508 |
*/
|
509 |
public function array_first($array)
|
510 |
{
|
|
|
511 |
if (!is_array($array)) return $array;
|
512 |
foreach ($array as $first) {
|
513 |
return $first;
|
@@ -576,7 +590,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
576 |
public function isItemInProductList($product_list, $product)
|
577 |
{
|
578 |
if (!isset($product['product_id'])) return false;
|
579 |
-
if(!is_array($product_list)) $product_list = (array)
|
580 |
if (count(array_intersect($product_list, array($product['product_id']))) == 1) {
|
581 |
return true;
|
582 |
} else {
|
@@ -845,6 +859,7 @@ if ( ! class_exists( 'woo_dicount_rules_pricingRules' ) ) {
|
|
845 |
if (!isset($table_data)) return false;
|
846 |
if (!isset($path) || empty($path) || is_null($path)) return false;
|
847 |
if (!file_exists($path)) return false;
|
|
|
848 |
include($path);
|
849 |
$html = ob_get_contents();
|
850 |
ob_clean();
|
5 |
/**
|
6 |
* Class woo_dicount_rules_pricingRules
|
7 |
*/
|
8 |
+
if (!class_exists('woo_dicount_rules_pricingRules')) {
|
9 |
class woo_dicount_rules_pricingRules
|
10 |
{
|
11 |
/**
|
48 |
*/
|
49 |
public $apply_to;
|
50 |
|
51 |
+
/**
|
52 |
+
* @var string
|
53 |
+
*/
|
54 |
+
public $default_option = 'woo-discount-config';
|
55 |
+
|
56 |
public $postData;
|
57 |
|
58 |
/**
|
84 |
*/
|
85 |
public function save($request)
|
86 |
{
|
87 |
+
// var_dump($request);
|
88 |
// die();
|
89 |
// foreach ($request as $index => $value) {
|
90 |
// $request[$index] = $value;
|
144 |
'rule_order'
|
145 |
);
|
146 |
|
147 |
+
//----------------------------------------------------------------------------------------------------------
|
148 |
// Manage Products with it's ID or Category.
|
149 |
$apply_to = 'all_products';
|
150 |
|
158 |
$form[] = $apply_to;
|
159 |
|
160 |
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
161 |
+
//----------------------------------------------------------------------------------------------------------
|
162 |
|
163 |
// Manage Users.
|
164 |
$apply_to = 'all';
|
171 |
$form[] = $apply_to;
|
172 |
|
173 |
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
174 |
+
//----------------------------------------------------------------------------------------------------------
|
175 |
|
176 |
// Manage list of Discount Ranges.
|
177 |
if (isset($request['discount_range'])) {
|
178 |
|
179 |
foreach ($request['discount_range'] as $index => $value) {
|
180 |
$request['discount_range'][$index] = woo_dicount_rules_generalHelper::makeString($value);
|
181 |
+
$request['discount_range'][$index]['title'] = isset($request['rule_name']) ? $request['rule_name'] : '';
|
182 |
+
|
183 |
}
|
184 |
|
185 |
$request['discount_range'] = json_encode($request['discount_range']);
|
259 |
foreach ($posts as $index => $item) {
|
260 |
$posts[$index]->meta = get_post_meta($posts[$index]->ID);
|
261 |
}
|
|
|
262 |
$this->rules = $posts;
|
263 |
}
|
264 |
return $posts;
|
279 |
WC()->session->set('woo_price_discount', json_encode($discount_log));
|
280 |
}
|
281 |
|
282 |
+
/**
|
283 |
+
* @return array
|
284 |
+
*/
|
285 |
+
public function getBaseConfig()
|
286 |
+
{
|
287 |
+
$option = get_option($this->default_option);
|
288 |
+
if (!$option || is_null($option)) {
|
289 |
+
return array();
|
290 |
+
} else {
|
291 |
+
return $option;
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
/**
|
296 |
* List of Checklist.
|
297 |
*/
|
324 |
$today = strtotime(date('m/d/Y'));
|
325 |
|
326 |
// Validating Rule with Date of Expiry.
|
327 |
+
if (($date_from <= $today) && (($date_to == '') || ($date_to > $today))) {
|
328 |
|
329 |
// Validating the Rule with its Order ID.
|
330 |
if (isset($rule->rule_order)) {
|
463 |
* @param $index
|
464 |
* @param array $item line item.
|
465 |
*/
|
466 |
+
public function matchRules($index, $item)
|
467 |
{
|
468 |
$applied_rules = array();
|
469 |
+
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
470 |
+
$i = 0;
|
471 |
+
foreach ($this->rule_sets as $id => $rule) {
|
|
|
472 |
|
473 |
+
if (isset($rule['type']) && isset($rule['apply_to'])) {
|
|
|
474 |
|
475 |
// Working with Products and Category.
|
476 |
+
switch ($rule['apply_to']) {
|
|
|
477 |
|
478 |
case 'specific_products':
|
479 |
|
480 |
+
if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
|
481 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, (object)$this->array_first($rule['discount']));
|
482 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
483 |
+
$applied_rules[$i]['item'] = $index;
|
484 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
|
|
485 |
}
|
486 |
|
487 |
break;
|
488 |
|
489 |
case 'specific_category':
|
490 |
+
if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
|
491 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, (object)$this->array_first($rule['discount']));
|
492 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
493 |
+
$applied_rules[$i]['item'] = $index;
|
494 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
|
|
495 |
}
|
496 |
|
497 |
|
500 |
case 'all_products':
|
501 |
default:
|
502 |
|
503 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, (object)$this->array_first($rule['discount']));
|
504 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
505 |
+
$applied_rules[$i]['item'] = $index;
|
506 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
507 |
|
508 |
break;
|
|
|
509 |
}
|
510 |
}
|
511 |
+
$i++;
|
512 |
}
|
513 |
+
$this->matched_sets[$index] = $applied_rules;
|
514 |
}
|
515 |
|
516 |
/**
|
521 |
*/
|
522 |
public function array_first($array)
|
523 |
{
|
524 |
+
if (is_object($array)) $array = (array)$array;
|
525 |
if (!is_array($array)) return $array;
|
526 |
foreach ($array as $first) {
|
527 |
return $first;
|
590 |
public function isItemInProductList($product_list, $product)
|
591 |
{
|
592 |
if (!isset($product['product_id'])) return false;
|
593 |
+
if (!is_array($product_list)) $product_list = (array)$product_list;
|
594 |
if (count(array_intersect($product_list, array($product['product_id']))) == 1) {
|
595 |
return true;
|
596 |
} else {
|
859 |
if (!isset($table_data)) return false;
|
860 |
if (!isset($path) || empty($path) || is_null($path)) return false;
|
861 |
if (!file_exists($path)) return false;
|
862 |
+
$data = $this->getBaseConfig();
|
863 |
include($path);
|
864 |
$html = ob_get_contents();
|
865 |
ob_clean();
|
loader.php
CHANGED
@@ -3,7 +3,7 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
|
3 |
/**
|
4 |
* Version of Woo Discount Rules.
|
5 |
*/
|
6 |
-
define('WOO_DISCOUNT_VERSION', '1.
|
7 |
/**
|
8 |
* Required Version of WooCommerce to Run.
|
9 |
*/
|
3 |
/**
|
4 |
* Version of Woo Discount Rules.
|
5 |
*/
|
6 |
+
define('WOO_DISCOUNT_VERSION', '1.4');
|
7 |
/**
|
8 |
* Required Version of WooCommerce to Run.
|
9 |
*/
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
|
|
4 |
Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
|
5 |
Requires at least: 4.4.1
|
6 |
Tested up to: 4.7
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
4 |
Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
|
5 |
Requires at least: 4.4.1
|
6 |
Tested up to: 4.7
|
7 |
+
Stable tag: 1.4
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
view/includes/header.php
CHANGED
@@ -7,4 +7,5 @@
|
|
7 |
height: 100% !important;
|
8 |
}
|
9 |
</style>
|
10 |
-
<body style="background-color: rgb(241, 241, 241) !important;">
|
|
7 |
height: 100% !important;
|
8 |
}
|
9 |
</style>
|
10 |
+
<body style="background-color: rgb(241, 241, 241) !important;">
|
11 |
+
<span id="woo-admin-message"></span>
|
view/settings.php
CHANGED
@@ -98,6 +98,24 @@ if (is_string($data)) $data = json_decode($data, true);
|
|
98 |
</select>
|
99 |
</div>
|
100 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
<div class="row form-group">
|
102 |
<?php $data['cart_setup'] = (isset($data['cart_setup']) ? $data['cart_setup'] : 'first'); ?>
|
103 |
<div class="col-md-2">
|
98 |
</select>
|
99 |
</div>
|
100 |
</div>
|
101 |
+
<div class="row form-group">
|
102 |
+
<?php $data['show_discount_title_table'] = (isset($data['show_discount_title_table']) ? $data['show_discount_title_table'] : 'show'); ?>
|
103 |
+
<div class="col-md-2">
|
104 |
+
<label>
|
105 |
+
Show Discount Title on Table :
|
106 |
+
</label>
|
107 |
+
</div>
|
108 |
+
<div class="col-md-6">
|
109 |
+
<select class="selectpicker" name="show_discount_title_table">
|
110 |
+
<option <?php if ($data['show_discount_title_table'] == 'show') { ?> selected=selected <?php } ?>
|
111 |
+
value="show">Show
|
112 |
+
</option>
|
113 |
+
<option <?php if ($data['show_discount_title_table'] == 'dont') { ?> selected=selected <?php } ?>
|
114 |
+
value="dont">Don't Show
|
115 |
+
</option>
|
116 |
+
</select>
|
117 |
+
</div>
|
118 |
+
</div>
|
119 |
<div class="row form-group">
|
120 |
<?php $data['cart_setup'] = (isset($data['cart_setup']) ? $data['cart_setup'] : 'first'); ?>
|
121 |
<div class="col-md-2">
|
view/template/discount-table.php
CHANGED
@@ -1,10 +1,17 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
if (!isset($table_data) || empty($table_data)) return false;
|
|
|
4 |
?>
|
5 |
<table>
|
6 |
<thead>
|
7 |
<tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
<td>Range</td>
|
9 |
<td>Discount</td>
|
10 |
</tr>
|
@@ -15,21 +22,34 @@ if (!isset($table_data) || empty($table_data)) return false;
|
|
15 |
$table = $table_data;
|
16 |
foreach ($table as $index => $item) {
|
17 |
if ($item) {
|
18 |
-
$have_discount = true;
|
19 |
foreach ($item as $id => $value) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
?>
|
21 |
<tr>
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
<?php } else { ?>
|
26 |
-
<td><?php echo wc_price($
|
27 |
<?php } ?>
|
28 |
</tr>
|
29 |
<?php }
|
|
|
30 |
}
|
31 |
}
|
32 |
-
if(!$have_discount){
|
33 |
echo '<tr><td colspan="2">No Active Discounts.</td></tr>';
|
34 |
}
|
35 |
?>
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
if (!isset($table_data) || empty($table_data)) return false;
|
4 |
+
$base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : []);
|
5 |
?>
|
6 |
<table>
|
7 |
<thead>
|
8 |
<tr>
|
9 |
+
<?php if (isset($base_config['show_discount_title_table'])) {
|
10 |
+
if ($base_config['show_discount_title_table'] == 'show') {
|
11 |
+
?>
|
12 |
+
<td>Name</td>
|
13 |
+
<?php }
|
14 |
+
} ?>
|
15 |
<td>Range</td>
|
16 |
<td>Discount</td>
|
17 |
</tr>
|
22 |
$table = $table_data;
|
23 |
foreach ($table as $index => $item) {
|
24 |
if ($item) {
|
|
|
25 |
foreach ($item as $id => $value) {
|
26 |
+
|
27 |
+
$title = isset($value->title) ? $value->title : '';
|
28 |
+
$min = isset($value->min_qty) ? $value->min_qty : 0;
|
29 |
+
$max = isset($value->max_qty) ? $value->max_qty : 0;
|
30 |
+
$discount_type = isset($value->discount_type) ? $value->discount_type : 0;
|
31 |
+
$to_discount = isset($value->to_discount) ? $value->to_discount : 0;
|
32 |
+
|
33 |
?>
|
34 |
<tr>
|
35 |
+
<?php if (isset($base_config['show_discount_title_table'])) {
|
36 |
+
if ($base_config['show_discount_title_table'] == 'show') {
|
37 |
+
?>
|
38 |
+
<td><?php echo $title; ?></td>
|
39 |
+
<?php }
|
40 |
+
} ?>
|
41 |
+
<td><?php echo $min . ' - ' . $max; ?></td>
|
42 |
+
<?php if ($discount_type == 'percentage_discount') { ?>
|
43 |
+
<td><?php echo $to_discount . ' %'; ?></td>
|
44 |
<?php } else { ?>
|
45 |
+
<td><?php echo wc_price($to_discount); ?></td>
|
46 |
<?php } ?>
|
47 |
</tr>
|
48 |
<?php }
|
49 |
+
$have_discount = true;
|
50 |
}
|
51 |
}
|
52 |
+
if (!$have_discount) {
|
53 |
echo '<tr><td colspan="2">No Active Discounts.</td></tr>';
|
54 |
}
|
55 |
?>
|
view/view-pricing-rules.php
CHANGED
@@ -21,294 +21,294 @@ $data = $config;
|
|
21 |
$rule_id = (isset($data->ID)) ? $data->ID : 0;
|
22 |
|
23 |
?>
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
</div>
|
46 |
-
<div class="col-md-6"><input type="number" class="rule_order"
|
47 |
-
id="rule_order"
|
48 |
-
name="rule_order"
|
49 |
-
min=1
|
50 |
-
value="<?php echo(isset($data->rule_order) ? $data->rule_order : '-'); ?>"
|
51 |
-
placeholder="ex. 1">
|
52 |
-
<code>WARNING: More than one rule should not have same priority. </code>
|
53 |
-
</div>
|
54 |
</div>
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
<
|
62 |
-
id="rule_name"
|
63 |
-
name="rule_name"
|
64 |
-
value="<?php echo(isset($data->rule_name) ? $data->rule_name : ''); ?>"
|
65 |
-
placeholder="ex. Standard Rule."></div>
|
66 |
</div>
|
67 |
</div>
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
78 |
</div>
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
Quantity Based
|
90 |
-
</option>
|
91 |
-
</select></div>
|
92 |
-
</div>
|
93 |
</div>
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
<div class="
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
</div>
|
133 |
</div>
|
|
|
|
|
|
|
134 |
</div>
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
</select>
|
163 |
-
<div class="form-group" id="product_list">
|
164 |
-
<?php $products_list = json_decode((isset($data->product_to_apply) ? $data->product_to_apply : '{}'), true); ?>
|
165 |
-
<select class="product_list selectpicker" multiple
|
166 |
-
name="product_to_apply[]">
|
167 |
-
<?php foreach ($products as $index => $value) { ?>
|
168 |
-
<option
|
169 |
-
value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
170 |
-
<?php } ?>
|
171 |
-
</select>
|
172 |
-
</div>
|
173 |
-
<div class="form-group" id="category_list">
|
174 |
-
<?php $category_list = json_decode((isset($data->category_to_apply) ? $data->category_to_apply : '{}'), true); ?>
|
175 |
-
<select class="category_list selectpicker" multiple
|
176 |
-
name="category_to_apply[]">
|
177 |
-
<?php foreach ($category as $index => $value) { ?>
|
178 |
-
<option
|
179 |
-
value="<?php echo $index; ?>"<?php if (in_array($index, $category_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
180 |
-
<?php } ?>
|
181 |
-
</select>
|
182 |
-
</div>
|
183 |
</div>
|
184 |
</div>
|
185 |
</div>
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
</select>
|
206 |
-
<div class="form-group" id="user_list">
|
207 |
-
<?php $users_list = json_decode((isset($data->users_to_apply) ? $data->users_to_apply : '{}'), true); ?>
|
208 |
-
<select class="user_list selectpicker" multiple name="users_to_apply[]">
|
209 |
-
<?php foreach ($users as $index => $value) { ?>
|
210 |
-
<option
|
211 |
-
value="<?php echo $index; ?>"<?php if (in_array($index, $users_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
212 |
-
<?php } ?>
|
213 |
-
</select>
|
214 |
-
</div>
|
215 |
</div>
|
216 |
</div>
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
</div>
|
222 |
</div>
|
|
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
}
|
238 |
}
|
|
|
239 |
|
240 |
-
|
241 |
-
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
|
287 |
-
|
288 |
-
|
289 |
|
290 |
-
</div>
|
291 |
</div>
|
292 |
-
<?php } ?>
|
293 |
-
<div align="right">
|
294 |
-
<input type="button" class="button button-secondary restriction_tab" value="Previous">
|
295 |
</div>
|
|
|
|
|
|
|
296 |
</div>
|
297 |
</div>
|
298 |
</div>
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
</
|
|
|
313 |
|
314 |
<?php include_once(WOO_DISCOUNT_DIR . '/view/includes/footer.php'); ?>
|
21 |
$rule_id = (isset($data->ID)) ? $data->ID : 0;
|
22 |
|
23 |
?>
|
24 |
+
<div class="container-fluid">
|
25 |
+
<form id="form_price_rule">
|
26 |
+
<div class="row-fluid">
|
27 |
+
<div class="col-md-8">
|
28 |
+
<div class="col-md-12" align="right">
|
29 |
+
<input type="submit" id="savePriceRule" value="Save Rule" class="button button-primary">
|
30 |
+
<a href="?page=woo_discount_rules" class="button button-secondary">Cancel</a>
|
31 |
+
</div>
|
32 |
+
<?php if ($rule_id == 0) { ?>
|
33 |
+
<div class="col-md-12"><h2>New Price Rule</h2></div>
|
34 |
+
<?php } else { ?>
|
35 |
+
<div class="col-md-12"><h2>Edit Price Rule
|
36 |
+
| <?php echo(isset($data->rule_name) ? $data->rule_name : ''); ?></h2></div>
|
37 |
+
<?php } ?>
|
38 |
+
<div class="col-md-12" id="general_block"><h4 class="text text-muted"> General</h4>
|
39 |
+
<hr>
|
40 |
+
<div class="form-group">
|
41 |
+
<div class="row">
|
42 |
+
<div class="col-md-3"><label> Order : <i
|
43 |
+
class="text-muted glyphicon glyphicon-exclamation-sign"
|
44 |
+
title="The Simple Ranking concept to said, which one is going to execute first and so on."></i></label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
</div>
|
46 |
+
<div class="col-md-6"><input type="number" class="rule_order"
|
47 |
+
id="rule_order"
|
48 |
+
name="rule_order"
|
49 |
+
min=1
|
50 |
+
value="<?php echo(isset($data->rule_order) ? $data->rule_order : '-'); ?>"
|
51 |
+
placeholder="ex. 1">
|
52 |
+
<code>WARNING: More than one rule should not have same priority. </code>
|
|
|
|
|
|
|
|
|
53 |
</div>
|
54 |
</div>
|
55 |
+
</div>
|
56 |
+
<div class="form-group">
|
57 |
+
<div class="row">
|
58 |
+
<div class="col-md-3"><label> Rule Name <i
|
59 |
+
class="text-muted glyphicon glyphicon-exclamation-sign"
|
60 |
+
title="Rule Desctriptions."></i></label></div>
|
61 |
+
<div class="col-md-6"><input type="text" class="form-control rule_descr"
|
62 |
+
id="rule_name"
|
63 |
+
name="rule_name"
|
64 |
+
value="<?php echo(isset($data->rule_name) ? $data->rule_name : ''); ?>"
|
65 |
+
placeholder="ex. Standard Rule."></div>
|
66 |
</div>
|
67 |
+
</div>
|
68 |
+
<div class="form-group">
|
69 |
+
<div class="row">
|
70 |
+
<div class="col-md-3"><label> Rule Description <i
|
71 |
+
class="text-muted glyphicon glyphicon-exclamation-sign"
|
72 |
+
title="Rule Desctriptions."></i></label></div>
|
73 |
+
<div class="col-md-6"><input type="text" class="form-control rule_descr"
|
74 |
+
name="rule_descr"
|
75 |
+
value="<?php echo(isset($data->rule_descr) ? $data->rule_descr : ''); ?>"
|
76 |
+
id="rule_descr"></div>
|
|
|
|
|
|
|
|
|
77 |
</div>
|
78 |
+
</div>
|
79 |
+
<div class="form-group">
|
80 |
+
<div class="row">
|
81 |
+
<div class="col-md-3"><label> Method <i
|
82 |
+
class="text-muted glyphicon glyphicon-exclamation-sign"
|
83 |
+
title="Method to Apply."></i></label></div>
|
84 |
+
<?php $opt = (isset($data->rule_method) ? $data->rule_method : ''); ?>
|
85 |
+
<div class="col-md-6"><select class="form-control"
|
86 |
+
name="rule_method">
|
87 |
+
<option
|
88 |
+
value="qty_based" <?php if ($opt == 'qty_based') { ?> selected=selected <?php } ?>>
|
89 |
+
Quantity Based
|
90 |
+
</option>
|
91 |
+
</select></div>
|
92 |
+
</div>
|
93 |
+
</div>
|
94 |
+
<!-- <div class="form-group">-->
|
95 |
+
<!-- <div class="row">-->
|
96 |
+
<!-- <div class="col-md-3"><label> Quantity Based On </label></div>-->
|
97 |
+
<!-- --><?php //$opt = (isset($data->qty_based_on) ? $data->qty_based_on : ''); ?>
|
98 |
+
<!-- <div class="col-md-6"><select class="form-control"-->
|
99 |
+
<!-- name="qty_based_on">-->
|
100 |
+
<!-- <option-->
|
101 |
+
<!-- value="each_product" -->
|
102 |
+
<?php //if ($opt == 'each_product') { ?><!-- selected=selected --><?php //} ?><!-->
|
103 |
+
<!-- Qty Of Each Product Individually-->
|
104 |
+
<!-- </option>-->
|
105 |
+
<!-- <option-->
|
106 |
+
<!-- value="each_variation" -->
|
107 |
+
<?php //if ($opt == 'each_variation') { ?><!-- selected=selected --><?php //} ?><!-->
|
108 |
+
<!-- Qty Of Each Variation Individually-->
|
109 |
+
<!-- </option>-->
|
110 |
+
<!-- </select></div>-->
|
111 |
+
<!-- </div>-->
|
112 |
+
<!-- </div>-->
|
113 |
+
<div class="form-group">
|
114 |
+
<div class="row">
|
115 |
+
<div class="col-md-3"><label> Validity <i
|
116 |
+
class="text-muted glyphicon glyphicon-exclamation-sign"
|
117 |
+
title="Period of Rule Active."></i></label></div>
|
118 |
+
<div class="col-md-6">
|
119 |
+
<div class="form-inline"><input type="text"
|
120 |
+
name="date_from"
|
121 |
+
class="form-control datepicker"
|
122 |
+
value="<?php echo(isset($data->date_from) ? $data->date_from : ''); ?>"
|
123 |
+
placeholder="From">
|
124 |
+
<input type="text" name="date_to"
|
125 |
+
class="form-control datepicker"
|
126 |
+
value="<?php echo(isset($data->date_to) ? $data->date_to : ''); ?>"
|
127 |
+
placeholder="To - Leave Empty if No Expiry"></div>
|
128 |
</div>
|
129 |
</div>
|
130 |
+
<div align="right">
|
131 |
+
<input type="button" class="button button-primary restriction_tab" value="Next">
|
132 |
+
</div>
|
133 |
</div>
|
134 |
+
</div>
|
135 |
|
136 |
+
<div class="col-md-12" id="restriction_block"><h4 class="text text-muted"> Discount
|
137 |
+
Conditionss </h4>
|
138 |
+
<hr>
|
139 |
+
<div class="form-group">
|
140 |
+
<div class="row">
|
141 |
+
<div class="col-md-3"><label> Apply To </label></div>
|
142 |
+
<?php $opt = (isset($data->apply_to) ? $data->apply_to : ''); ?>
|
143 |
+
<div class="col-md-6"><select class="selectpicker"
|
144 |
+
name="apply_to" id="apply_to">
|
145 |
+
<option
|
146 |
+
value="all_products" <?php if ($opt == 'all_products') { ?> selected=selected <?php } ?>>
|
147 |
+
All Products
|
148 |
+
</option>
|
149 |
+
<option
|
150 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="specific_category" <?php }
|
151 |
+
if ($opt == 'specific_category') { ?> selected=selected <?php } ?>>
|
152 |
+
<?php if (!$pro) { ?>
|
153 |
+
Specific Categories <b><?php echo $suffix; ?></b>
|
154 |
+
<?php } else { ?>
|
155 |
+
Specific Categories
|
156 |
+
<?php } ?>
|
157 |
+
</option>
|
158 |
+
<option
|
159 |
+
value="specific_products" <?php if ($opt == 'specific_products') { ?> selected=selected <?php } ?>>
|
160 |
+
Specific Products
|
161 |
+
</option>
|
162 |
+
</select>
|
163 |
+
<div class="form-group" id="product_list">
|
164 |
+
<?php $products_list = json_decode((isset($data->product_to_apply) ? $data->product_to_apply : '{}'), true); ?>
|
165 |
+
<select class="product_list selectpicker" multiple
|
166 |
+
name="product_to_apply[]">
|
167 |
+
<?php foreach ($products as $index => $value) { ?>
|
168 |
+
<option
|
169 |
+
value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
170 |
+
<?php } ?>
|
171 |
+
</select>
|
172 |
+
</div>
|
173 |
+
<div class="form-group" id="category_list">
|
174 |
+
<?php $category_list = json_decode((isset($data->category_to_apply) ? $data->category_to_apply : '{}'), true); ?>
|
175 |
+
<select class="category_list selectpicker" multiple
|
176 |
+
name="category_to_apply[]">
|
177 |
+
<?php foreach ($category as $index => $value) { ?>
|
178 |
+
<option
|
179 |
+
value="<?php echo $index; ?>"<?php if (in_array($index, $category_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
180 |
+
<?php } ?>
|
181 |
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
</div>
|
183 |
</div>
|
184 |
</div>
|
185 |
+
</div>
|
186 |
+
<div class="form-group">
|
187 |
+
<div class="row">
|
188 |
+
<div class="col-md-3"><label> Customers </label></div>
|
189 |
+
<?php $opt = (isset($data->customer) ? $data->customer : ''); ?>
|
190 |
+
<div class="col-md-6"><select class="selectpicker"
|
191 |
+
name="customer" id="apply_customer">
|
192 |
+
<option value="all" <?php if ($opt == 'all') { ?> selected=selected <?php } ?>>
|
193 |
+
All
|
194 |
+
</option>
|
195 |
+
<option
|
196 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="only_given" <?php
|
197 |
+
}
|
198 |
+
if ($opt == 'only_given') { ?> selected=selected <?php } ?>>
|
199 |
+
<?php if (!$pro) { ?>
|
200 |
+
Only Given <b><?php echo $suffix; ?></b>
|
201 |
+
<?php } else { ?>
|
202 |
+
Only Given
|
203 |
+
<?php } ?>
|
204 |
+
</option>
|
205 |
+
</select>
|
206 |
+
<div class="form-group" id="user_list">
|
207 |
+
<?php $users_list = json_decode((isset($data->users_to_apply) ? $data->users_to_apply : '{}'), true); ?>
|
208 |
+
<select class="user_list selectpicker" multiple name="users_to_apply[]">
|
209 |
+
<?php foreach ($users as $index => $value) { ?>
|
210 |
+
<option
|
211 |
+
value="<?php echo $index; ?>"<?php if (in_array($index, $users_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
212 |
+
<?php } ?>
|
213 |
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
</div>
|
215 |
</div>
|
216 |
+
</div>
|
217 |
+
<div align="right">
|
218 |
+
<input type="button" class="button button-secondary general_tab" value="Previous">
|
219 |
+
<input type="button" class="button button-primary discount_tab" value="Next">
|
220 |
</div>
|
221 |
</div>
|
222 |
+
</div>
|
223 |
|
224 |
+
<!-- TODO: Implement ForEach Concept -->
|
225 |
+
<div class="col-md-12" id="discount_block"><h4 class="text text-muted"> Discount</h4>
|
226 |
+
<a href=javascript:void(0) class="button button-primary" id="addNewDiscountRange"><i
|
227 |
+
class="glyphicon glyphicon-plus"></i> Add New Range</a>
|
228 |
+
<hr>
|
229 |
+
<div id="discount_rule_list">
|
230 |
+
<?php
|
231 |
+
$discount_range = new stdClass();
|
232 |
+
if (isset($data->discount_range)) {
|
233 |
+
if (is_string($data->discount_range)) {
|
234 |
+
$discount_range = json_decode($data->discount_range);
|
235 |
+
} else {
|
236 |
+
$discount_range = $data->discount_range;
|
|
|
237 |
}
|
238 |
+
}
|
239 |
|
240 |
+
// Make Dummy Element.
|
241 |
+
if ($discount_range == '') $discount_range = array(0 => '');
|
242 |
|
243 |
+
foreach ($discount_range as $index => $discount) {
|
244 |
+
?>
|
245 |
+
<div class="discount_rule_list">
|
246 |
+
<div class="form-group">
|
247 |
+
<label>Min Quantity
|
248 |
+
<input type="text"
|
249 |
+
name="discount_range[<?php echo $index; ?>][min_qty]"
|
250 |
+
class="form-control"
|
251 |
+
value="<?php echo(isset($discount->min_qty) ? $discount->min_qty : ''); ?>"
|
252 |
+
placeholder="ex. 1">
|
253 |
+
</label>
|
254 |
+
<label>Max Quantity
|
255 |
+
<input type="text"
|
256 |
+
name="discount_range[<?php echo $index; ?>][max_qty]"
|
257 |
+
class="form-control"
|
258 |
+
value="<?php echo(isset($discount->max_qty) ? $discount->max_qty : ''); ?>"
|
259 |
+
placeholder="ex. 50"> </label>
|
260 |
+
<label>Adjustment Type
|
261 |
+
<select class="form-control"
|
262 |
+
name="discount_range[<?php echo $index; ?>][discount_type]">
|
263 |
+
<?php $opt = (isset($discount->discount_type) ? $discount->discount_type : ''); ?>
|
264 |
+
<option
|
265 |
+
value="percentage_discount" <?php if ($opt == 'percentage_discount') { ?> selected=selected <?php } ?> >
|
266 |
+
Percentage Discount
|
267 |
+
</option>
|
268 |
|
269 |
+
<option
|
270 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="price_discount" <?php
|
271 |
+
}
|
272 |
+
if ($opt == 'price_discount') { ?> selected=selected <?php } ?>>
|
273 |
+
<?php if (!$pro) { ?>
|
274 |
+
Price Discount <b><?php echo $suffix; ?></b>
|
275 |
+
<?php } else { ?>
|
276 |
+
Price Discount
|
277 |
+
<?php } ?>
|
278 |
+
</option>
|
279 |
+
</select></label>
|
280 |
+
<label>Value
|
281 |
+
<input type="text"
|
282 |
+
name="discount_range[<?php echo $index; ?>][to_discount]"
|
283 |
+
class="form-control"
|
284 |
+
value="<?php echo(isset($discount->to_discount) ? $discount->to_discount : ''); ?>"
|
285 |
+
placeholder="ex. 50"> </label>
|
286 |
|
287 |
+
<label>Action <a href=javascript:void(0)
|
288 |
+
class="button button-secondary form-control remove_discount_range">Remove</a></label>
|
289 |
|
|
|
290 |
</div>
|
|
|
|
|
|
|
291 |
</div>
|
292 |
+
<?php } ?>
|
293 |
+
<div align="right">
|
294 |
+
<input type="button" class="button button-secondary restriction_tab" value="Previous">
|
295 |
</div>
|
296 |
</div>
|
297 |
</div>
|
298 |
+
</div>
|
299 |
+
<div class="col-md-1"></div>
|
300 |
+
<!-- Sidebar -->
|
301 |
+
<?php include_once(__DIR__ . '/template/sidebar.php'); ?>
|
302 |
+
<!-- Sidebar END -->
|
303 |
+
<input type="hidden" name="rule_id" id="rule_id" value="<?php echo $rule_id; ?>">
|
304 |
+
<input type="hidden" name="form" value="<?php echo $form; ?>">
|
305 |
+
<input type="hidden" id="ajax_path" value="<?php echo admin_url('admin-ajax.php'); ?>">
|
306 |
+
<input type="hidden" id="admin_path"
|
307 |
+
value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
|
308 |
+
<input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
|
309 |
+
<input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
|
310 |
+
<!-- <input type="hidden" name="status" value="--><?php //echo $status; ?><!--">-->
|
311 |
+
</form>
|
312 |
+
</div>
|
313 |
|
314 |
<?php include_once(WOO_DISCOUNT_DIR . '/view/includes/footer.php'); ?>
|
woo-discount-rules.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Description: Simple Discount Rules for WooCommerce.
|
6 |
* Author: Flycart Technologies LLP
|
7 |
* Author URI: https://www.flycart.org
|
8 |
-
* Version: 1.
|
9 |
* Requires at least: 4.6.1
|
10 |
*/
|
11 |
|
5 |
* Description: Simple Discount Rules for WooCommerce.
|
6 |
* Author: Flycart Technologies LLP
|
7 |
* Author URI: https://www.flycart.org
|
8 |
+
* Version: 1.4
|
9 |
* Requires at least: 4.6.1
|
10 |
*/
|
11 |
|