Version Description
- 19/12/17 =
- Fix - error message while update check
- Fix - Product category based, not worked for variant product
Download this release
Release Info
Developer | flycart |
Plugin | Discount Rules for WooCommerce |
Version | 1.4.33 |
Comparing to | |
See all releases |
Code changes from version 1.4.32 to 1.4.33
- assets/js/app.js +29 -80
- helper/activation-helper.php +3 -7
- helper/general-helper-3.php +0 -411
- helper/general-helper.php +18 -34
- helper/purchase.php +10 -10
- helper/woo-function.php +393 -0
- includes/cart-rules-3.php +0 -1156
- includes/cart-rules.php +28 -109
- includes/discount-base.php +75 -28
- includes/pricing-productbased.php +4 -4
- includes/pricing-rules-3.php +0 -1810
- includes/pricing-rules.php +276 -237
- loader.php +112 -200
- readme.txt +5 -1
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/Info.php +1 -0
- view/cart-rules.php +0 -7
- view/settings.php +2 -2
- view/template/discount-table.php +13 -18
- view/template/sidebar.php +1 -1
- view/view-cart-rules.php +0 -40
- view/view-pricing-rules.php +5 -28
- woo-discount-rules.php +1 -1
assets/js/app.js
CHANGED
@@ -25,12 +25,6 @@ function validateFields(){
|
|
25 |
var pro_suffix = $('#pro_suffix').val();
|
26 |
var is_pro = $('#is_pro').val();
|
27 |
$(".datepicker").datepicker();
|
28 |
-
// Default Hide List.
|
29 |
-
//$('#user_div_0').hide();
|
30 |
-
//$('#product_div_0').hide();
|
31 |
-
//$('#category_div_0').hide();
|
32 |
-
//$('#roles_div_0').hide();
|
33 |
-
//$('#countries_div_0').hide();
|
34 |
|
35 |
//--------------------------------------------------------------------------------------------------------------
|
36 |
//--------------------------------------------PRICING RULES-----------------------------------------------------
|
@@ -164,10 +158,7 @@ function validateFields(){
|
|
164 |
form += '<div class="price_discount_product_list_con hide">' +
|
165 |
' Apply for <select class="" name="discount_range['+count+'][discount_product_option]"><option value="all">All selected</option><option value="any_cheapest">Any one cheapest </option>' +
|
166 |
'</select><select class="product_list selectpicker price_discount_product_list" data-live-search="true" multiple name="discount_range[' + count + '][discount_product][]">';
|
167 |
-
|
168 |
-
{
|
169 |
-
form += '<option value="'+$(this).val()+'">'+$(this).html()+'</option>';
|
170 |
-
});*/
|
171 |
form += $("#product_list select.product_list").first().html();
|
172 |
form += '</select></div>';
|
173 |
form += '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
|
@@ -316,9 +307,7 @@ function validateFields(){
|
|
316 |
var form = '<div class="cart_rules_list row"> <div class="col-md-3 form-group"> <label>Type <select class="form-control cart_rule_type" id="cart_condition_type_' + count + '" name="discount_rule[' + count + '][type]"> <optgroup label="Cart Subtotal"><option value="subtotal_least" selected="selected">Subtotal at least</option><option value="subtotal_less">Subtotal less than</option></optgroup>' +
|
317 |
'<optgroup label="Cart Item Count"><option value="item_count_least">Count of cart items at least</option><option value="item_count_less">Count of cart items less than</option></optgroup>' +
|
318 |
'<optgroup label="Quantity Sum"><option value="quantity_least">Sum of item quantities at least</option><option value="quantity_less">Sum of item quantities less than</option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
|
319 |
-
//'<optgroup label="Products In Cart"><option value="products_atleast_one">At least one product in cart</option><!-- These products should not present in the cart to apply. --><option value="products_not_in">None of selected products in cart</option></optgroup>' +
|
320 |
'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. -->' +
|
321 |
-
//'<option value="categories_atleast_one">At least one category in cart</option><!-- These Category should not present in the cart to apply. --><!--<option value="categories_not_in">None of selected categories in cart</option>-->' +
|
322 |
'<option value="categories_in">Categories in cart</option>' +
|
323 |
'</optgroup>' +
|
324 |
'<optgroup label="Customer Details (must be logged in)"><option value="users_in">User in list</option><option value="roles_in">User role in list</option><option value="shipping_countries_in">Shipping country in list</option></optgroup>' +
|
@@ -326,21 +315,19 @@ function validateFields(){
|
|
326 |
'<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup>' +
|
327 |
'<optgroup label="Purchase History"><option value="customer_based_on_purchase_history">Based on Purchase history</option></optgroup></select></label></div>' +
|
328 |
'<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
|
329 |
-
'<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
|
330 |
-
'<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
|
331 |
-
'<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
|
332 |
-
'<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
|
333 |
-
'<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
|
334 |
-
'<div id="purchase_history_div_' + count + '">Total purchased amount at least <input name="discount_rule[' + count + '][purchased_history_amount]" value="" type="text"/> In Order status <select id="order_status_list_' + count + '" class="order_status_list selectpicker" multiple name="discount_rule[' + count + '][purchase_history_order_status][]"></select></div>' +
|
335 |
'</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
|
336 |
'</label></div>';
|
337 |
} else {
|
338 |
var form = '<div class="cart_rules_list row"> <div class="col-md-3 form-group"> <label>Type <select class="form-control cart_rule_type" id="cart_condition_type_' + count + '" name="discount_rule[' + count + '][type]"> <optgroup label="Cart Subtotal"><option value="subtotal_least" selected="selected">Subtotal at least</option><option value="subtotal_less">Subtotal less than</option></optgroup>' +
|
339 |
'<optgroup label="Cart Item Count"><option value="item_count_least">Count of cart items at least</option><option value="item_count_less">Count of cart items less than</option></optgroup>' +
|
340 |
'<optgroup label="Quantity Sum"><option disabled>Sum of item quantities at least <b>' + pro_suffix + '</b></option><option disabled>Sum of item quantities less than <b>' + pro_suffix + '</b></option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
|
341 |
-
//'<optgroup label="Products In Cart"><option value="products_atleast_one">At least one product in cart</option><!-- These products should not present in the cart to apply. --><option value="products_not_in">None of selected products in cart</option></optgroup>' +
|
342 |
'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. -->' +
|
343 |
-
//'<option value="categories_atleast_one">At least one category in cart</option><!-- These Category should not present in the cart to apply. --><option value="categories_not_in">None of selected categories in cart</option>' +
|
344 |
'<option disabled>Categories in cart <b>' + pro_suffix + '</b></option>' +
|
345 |
'</optgroup>' +
|
346 |
'<optgroup label="Customer Details (must be logged in)"><option disabled>User in list <b>' + pro_suffix + '</b></option><option disabled>User role in list <b>' + pro_suffix + '</b></option><option disabled>Shipping country in list <b>' + pro_suffix + '</b></option></optgroup>' +
|
@@ -348,12 +335,12 @@ function validateFields(){
|
|
348 |
'<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup>' +
|
349 |
'<optgroup label="Purchase History"><option disabled>Based on Purchase history <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
|
350 |
'<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
|
351 |
-
'<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
|
352 |
-
'<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
|
353 |
-
'<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
|
354 |
-
'<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
|
355 |
-
'<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
|
356 |
-
'<div id="purchase_history_div_' + count + '"><select id="order_status_list_' + count + '" class="order_status_list selectpicker" multiple name="discount_rule[' + count + '][purchase_history_order_status][]"></select></div>' +
|
357 |
'</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
|
358 |
'</label></div>';
|
359 |
}
|
@@ -440,10 +427,6 @@ function validateFields(){
|
|
440 |
|
441 |
// Reset, if its New Form.
|
442 |
if (rule_id == 0) {
|
443 |
-
//$('#form_cart_rule')[0].reset();
|
444 |
-
// Reset the Select Picker.
|
445 |
-
//$('.selectpicker').selectpicker('val', []);
|
446 |
-
//location.reload();
|
447 |
$(location).attr('href', admin_url + '&tab=cart-rules');
|
448 |
}
|
449 |
adminNotice();
|
@@ -478,7 +461,6 @@ function validateFields(){
|
|
478 |
type: 'POST',
|
479 |
data: {action: 'UpdateStatus', id: id, from: 'cart-rules'},
|
480 |
success: function (status) {
|
481 |
-
// After Status Changed.
|
482 |
// After Status Changed.
|
483 |
if (status == 'Disable') {
|
484 |
current.removeClass('button-primary');
|
@@ -599,63 +581,30 @@ function validateFields(){
|
|
599 |
});
|
600 |
|
601 |
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
function showOnly(option, id) {
|
603 |
if (option == 'products_atleast_one' || option == 'products_not_in') {
|
604 |
-
|
605 |
-
$('#product_div_' + id).css('display', 'block');
|
606 |
-
$('#category_div_' + id).css('display', 'none');
|
607 |
-
$('#general_' + id).css('display', 'none');
|
608 |
-
$('#roles_div_' + id).css('display', 'none');
|
609 |
-
$('#countries_div_' + id).css('display', 'none');
|
610 |
-
$('#purchase_history_div_' + id).css('display', 'none');
|
611 |
} else if (option == 'categories_atleast_one' || option == 'categories_not_in' || option == 'categories_in') {
|
612 |
-
|
613 |
-
$('#product_div_' + id).css('display', 'none');
|
614 |
-
$('#category_div_' + id).css('display', 'block');
|
615 |
-
$('#general_' + id).css('display', 'none');
|
616 |
-
$('#roles_div_' + id).css('display', 'none');
|
617 |
-
$('#countries_div_' + id).css('display', 'none');
|
618 |
-
$('#purchase_history_div_' + id).css('display', 'none');
|
619 |
} else if (option == 'users_in') {
|
620 |
-
|
621 |
-
$('#product_div_' + id).css('display', 'none');
|
622 |
-
$('#category_div_' + id).css('display', 'none');
|
623 |
-
$('#general_' + id).css('display', 'none');
|
624 |
-
$('#roles_div_' + id).css('display', 'none');
|
625 |
-
$('#countries_div_' + id).css('display', 'none');
|
626 |
-
$('#purchase_history_div_' + id).css('display', 'none');
|
627 |
} else if (option == 'roles_in') {
|
628 |
-
|
629 |
-
$('#product_div_' + id).css('display', 'none');
|
630 |
-
$('#category_div_' + id).css('display', 'none');
|
631 |
-
$('#general_' + id).css('display', 'none');
|
632 |
-
$('#roles_div_' + id).css('display', 'block');
|
633 |
-
$('#countries_div_' + id).css('display', 'none');
|
634 |
-
$('#purchase_history_div_' + id).css('display', 'none');
|
635 |
} else if (option == 'shipping_countries_in') {
|
636 |
-
|
637 |
-
$('#product_div_' + id).css('display', 'none');
|
638 |
-
$('#category_div_' + id).css('display', 'none');
|
639 |
-
$('#general_' + id).css('display', 'none');
|
640 |
-
$('#roles_div_' + id).css('display', 'none');
|
641 |
-
$('#countries_div_' + id).css('display', 'block');
|
642 |
-
$('#purchase_history_div_' + id).css('display', 'none');
|
643 |
} else if (option == 'customer_based_on_purchase_history') {
|
644 |
-
|
645 |
-
$('#product_div_' + id).css('display', 'none');
|
646 |
-
$('#category_div_' + id).css('display', 'none');
|
647 |
-
$('#general_' + id).css('display', 'none');
|
648 |
-
$('#roles_div_' + id).css('display', 'none');
|
649 |
-
$('#countries_div_' + id).css('display', 'none');
|
650 |
-
$('#purchase_history_div_' + id).css('display', 'block');
|
651 |
} else {
|
652 |
-
|
653 |
-
$('#product_div_' + id).css('display', 'none');
|
654 |
-
$('#category_div_' + id).css('display', 'none');
|
655 |
-
$('#general_' + id).css('display', 'block');
|
656 |
-
$('#roles_div_' + id).css('display', 'none');
|
657 |
-
$('#countries_div_' + id).css('display', 'none');
|
658 |
-
$('#purchase_history_div_' + id).css('display', 'none');
|
659 |
}
|
660 |
|
661 |
}
|
25 |
var pro_suffix = $('#pro_suffix').val();
|
26 |
var is_pro = $('#is_pro').val();
|
27 |
$(".datepicker").datepicker();
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
//--------------------------------------------------------------------------------------------------------------
|
30 |
//--------------------------------------------PRICING RULES-----------------------------------------------------
|
158 |
form += '<div class="price_discount_product_list_con hide">' +
|
159 |
' Apply for <select class="" name="discount_range['+count+'][discount_product_option]"><option value="all">All selected</option><option value="any_cheapest">Any one cheapest </option>' +
|
160 |
'</select><select class="product_list selectpicker price_discount_product_list" data-live-search="true" multiple name="discount_range[' + count + '][discount_product][]">';
|
161 |
+
|
|
|
|
|
|
|
162 |
form += $("#product_list select.product_list").first().html();
|
163 |
form += '</select></div>';
|
164 |
form += '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
|
307 |
var form = '<div class="cart_rules_list row"> <div class="col-md-3 form-group"> <label>Type <select class="form-control cart_rule_type" id="cart_condition_type_' + count + '" name="discount_rule[' + count + '][type]"> <optgroup label="Cart Subtotal"><option value="subtotal_least" selected="selected">Subtotal at least</option><option value="subtotal_less">Subtotal less than</option></optgroup>' +
|
308 |
'<optgroup label="Cart Item Count"><option value="item_count_least">Count of cart items at least</option><option value="item_count_less">Count of cart items less than</option></optgroup>' +
|
309 |
'<optgroup label="Quantity Sum"><option value="quantity_least">Sum of item quantities at least</option><option value="quantity_less">Sum of item quantities less than</option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
|
|
|
310 |
'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. -->' +
|
|
|
311 |
'<option value="categories_in">Categories in cart</option>' +
|
312 |
'</optgroup>' +
|
313 |
'<optgroup label="Customer Details (must be logged in)"><option value="users_in">User in list</option><option value="roles_in">User role in list</option><option value="shipping_countries_in">Shipping country in list</option></optgroup>' +
|
315 |
'<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup>' +
|
316 |
'<optgroup label="Purchase History"><option value="customer_based_on_purchase_history">Based on Purchase history</option></optgroup></select></label></div>' +
|
317 |
'<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
|
318 |
+
'<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
|
319 |
+
'<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
|
320 |
+
'<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
|
321 |
+
'<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
|
322 |
+
'<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
|
323 |
+
'<div id="purchase_history_div_' + count + '">Total purchased amount at least <input name="discount_rule[' + count + '][purchased_history_amount]" value="" type="text"/> In Order status <select id="order_status_list_' + count + '" class="order_status_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][purchase_history_order_status][]"></select></div>' +
|
324 |
'</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
|
325 |
'</label></div>';
|
326 |
} else {
|
327 |
var form = '<div class="cart_rules_list row"> <div class="col-md-3 form-group"> <label>Type <select class="form-control cart_rule_type" id="cart_condition_type_' + count + '" name="discount_rule[' + count + '][type]"> <optgroup label="Cart Subtotal"><option value="subtotal_least" selected="selected">Subtotal at least</option><option value="subtotal_less">Subtotal less than</option></optgroup>' +
|
328 |
'<optgroup label="Cart Item Count"><option value="item_count_least">Count of cart items at least</option><option value="item_count_less">Count of cart items less than</option></optgroup>' +
|
329 |
'<optgroup label="Quantity Sum"><option disabled>Sum of item quantities at least <b>' + pro_suffix + '</b></option><option disabled>Sum of item quantities less than <b>' + pro_suffix + '</b></option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
|
|
|
330 |
'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. -->' +
|
|
|
331 |
'<option disabled>Categories in cart <b>' + pro_suffix + '</b></option>' +
|
332 |
'</optgroup>' +
|
333 |
'<optgroup label="Customer Details (must be logged in)"><option disabled>User in list <b>' + pro_suffix + '</b></option><option disabled>User role in list <b>' + pro_suffix + '</b></option><option disabled>Shipping country in list <b>' + pro_suffix + '</b></option></optgroup>' +
|
335 |
'<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup>' +
|
336 |
'<optgroup label="Purchase History"><option disabled>Based on Purchase history <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
|
337 |
'<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
|
338 |
+
'<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
|
339 |
+
'<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
|
340 |
+
'<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
|
341 |
+
'<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
|
342 |
+
'<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
|
343 |
+
'<div id="purchase_history_div_' + count + '"><select id="order_status_list_' + count + '" class="order_status_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][purchase_history_order_status][]"></select></div>' +
|
344 |
'</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
|
345 |
'</label></div>';
|
346 |
}
|
427 |
|
428 |
// Reset, if its New Form.
|
429 |
if (rule_id == 0) {
|
|
|
|
|
|
|
|
|
430 |
$(location).attr('href', admin_url + '&tab=cart-rules');
|
431 |
}
|
432 |
adminNotice();
|
461 |
type: 'POST',
|
462 |
data: {action: 'UpdateStatus', id: id, from: 'cart-rules'},
|
463 |
success: function (status) {
|
|
|
464 |
// After Status Changed.
|
465 |
if (status == 'Disable') {
|
466 |
current.removeClass('button-primary');
|
581 |
});
|
582 |
|
583 |
//------------------------------------------------------------------------------------------------------------------
|
584 |
+
function processShowOnlyTags(id_prefix, id){
|
585 |
+
var availableTags = ["user_div_", "product_div_", "category_div_", "general_", "roles_div_", "countries_div_", "purchase_history_div_"];
|
586 |
+
$.each(availableTags, function( index, value ) {
|
587 |
+
if(value == id_prefix)
|
588 |
+
$('#'+value+id).css('display', 'block');
|
589 |
+
else
|
590 |
+
$('#'+value+id).css('display', 'none');
|
591 |
+
});
|
592 |
+
}
|
593 |
function showOnly(option, id) {
|
594 |
if (option == 'products_atleast_one' || option == 'products_not_in') {
|
595 |
+
processShowOnlyTags('product_div_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
} else if (option == 'categories_atleast_one' || option == 'categories_not_in' || option == 'categories_in') {
|
597 |
+
processShowOnlyTags('category_div_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
598 |
} else if (option == 'users_in') {
|
599 |
+
processShowOnlyTags('user_div_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
} else if (option == 'roles_in') {
|
601 |
+
processShowOnlyTags('roles_div_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
} else if (option == 'shipping_countries_in') {
|
603 |
+
processShowOnlyTags('countries_div_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
} else if (option == 'customer_based_on_purchase_history') {
|
605 |
+
processShowOnlyTags('purchase_history_div_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
606 |
} else {
|
607 |
+
processShowOnlyTags('general_', id);
|
|
|
|
|
|
|
|
|
|
|
|
|
608 |
}
|
609 |
|
610 |
}
|
helper/activation-helper.php
CHANGED
@@ -5,15 +5,11 @@ register_activation_hook(__FILE__, 'onWooDiscountActivate');
|
|
5 |
register_deactivation_hook(__FILE__, 'onWooDiscountDeactivation');
|
6 |
|
7 |
if (!function_exists('onWooDiscountActivate')) {
|
8 |
-
function onWooDiscountActivate()
|
9 |
-
|
10 |
-
// Dependency Check.
|
11 |
if (!in_array('woocommerce/woocommerce.php', get_option('active_plugins'))) wp_die('Please Install WooCommerce to Continue !');
|
12 |
}
|
13 |
}
|
14 |
if (!function_exists('onWooDiscountDeactivation')) {
|
15 |
-
function onWooDiscountDeactivation()
|
16 |
-
{
|
17 |
-
|
18 |
-
}
|
19 |
}
|
5 |
register_deactivation_hook(__FILE__, 'onWooDiscountDeactivation');
|
6 |
|
7 |
if (!function_exists('onWooDiscountActivate')) {
|
8 |
+
function onWooDiscountActivate() {
|
9 |
+
// Dependency Check.
|
|
|
10 |
if (!in_array('woocommerce/woocommerce.php', get_option('active_plugins'))) wp_die('Please Install WooCommerce to Continue !');
|
11 |
}
|
12 |
}
|
13 |
if (!function_exists('onWooDiscountDeactivation')) {
|
14 |
+
function onWooDiscountDeactivation() {}
|
|
|
|
|
|
|
15 |
}
|
helper/general-helper-3.php
DELETED
@@ -1,411 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
-
include_once(WOO_DISCOUNT_DIR . '/helper/purchase.php');
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class woo_dicount_rules_generalHelper
|
7 |
-
*/
|
8 |
-
if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
9 |
-
class woo_dicount_rules_generalHelper
|
10 |
-
{
|
11 |
-
|
12 |
-
public $isPro;
|
13 |
-
|
14 |
-
/**
|
15 |
-
* @var string
|
16 |
-
*/
|
17 |
-
public $default_page = 'pricing-rules';
|
18 |
-
|
19 |
-
/**
|
20 |
-
* To Process the View.
|
21 |
-
*
|
22 |
-
* @param $path
|
23 |
-
* @param $data
|
24 |
-
* @return bool|string
|
25 |
-
*/
|
26 |
-
public function processBaseView($path, $data)
|
27 |
-
{
|
28 |
-
if (!file_exists($path)) return false;
|
29 |
-
$this->checkPluginState();
|
30 |
-
$purchase = new woo_dicount_rules_purchase();
|
31 |
-
$suffix = $purchase->getSuffix();
|
32 |
-
ob_start();
|
33 |
-
$config = $data;
|
34 |
-
$pro = $this->isPro;
|
35 |
-
$products = $this->getProductList();
|
36 |
-
$category = $this->getCategoryList();
|
37 |
-
$users = $this->getUserList();
|
38 |
-
$userRoles = $this->getUserRoles();
|
39 |
-
$countries = $this->getAllCountries();
|
40 |
-
if (!isset($config)) return false;
|
41 |
-
if (!isset($path) or is_null($config)) return false;
|
42 |
-
include($path);
|
43 |
-
$html = ob_get_contents();
|
44 |
-
ob_end_clean();
|
45 |
-
return $html;
|
46 |
-
}
|
47 |
-
|
48 |
-
public function checkPluginState()
|
49 |
-
{
|
50 |
-
$purchase = new woo_dicount_rules_purchase();
|
51 |
-
$this->isPro = $purchase->isPro();
|
52 |
-
return $this->isPro;
|
53 |
-
// $this->isPro = true;
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* To Retrieve the list of Users.
|
58 |
-
*
|
59 |
-
* @return array
|
60 |
-
*/
|
61 |
-
public function getUserList()
|
62 |
-
{
|
63 |
-
$result = array();
|
64 |
-
foreach (get_users() as $user) {
|
65 |
-
$result[$user->ID] = '#' . $user->ID . ' ' . $user->user_email;
|
66 |
-
}
|
67 |
-
return $result;
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* To Retrieve the active tab.
|
72 |
-
*
|
73 |
-
* @return string
|
74 |
-
*/
|
75 |
-
public function getCurrentTab()
|
76 |
-
{
|
77 |
-
$postData = \FlycartInput\FInput::getInstance();
|
78 |
-
$tab = $this->default_page;
|
79 |
-
$empty_tab = $postData->get('tab', null);
|
80 |
-
if (!empty($empty_tab) && $postData->get('tab', '') != '') {
|
81 |
-
$tab = sanitize_text_field($postData->get('tab', ''));
|
82 |
-
}
|
83 |
-
return $tab;
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* To Get Product List.
|
88 |
-
*
|
89 |
-
* @return array
|
90 |
-
*/
|
91 |
-
public function getProductList()
|
92 |
-
{
|
93 |
-
$base = new woo_dicount_rules_WooDiscountBase();
|
94 |
-
$base = $base->getBaseConfig();
|
95 |
-
if (is_string($base)) $base = json_decode($base, true);
|
96 |
-
$show_draft = 0;
|
97 |
-
if(isset($base['show_draft']) && $base['show_draft'] == 1){
|
98 |
-
$show_draft = 1;
|
99 |
-
}
|
100 |
-
if($show_draft){
|
101 |
-
$postStatus = array('publish', 'pending', 'future', 'private', 'inherit');
|
102 |
-
} else {
|
103 |
-
$postStatus = array('publish', 'pending', 'draft', 'future', 'private', 'inherit');
|
104 |
-
}
|
105 |
-
$products = array();
|
106 |
-
$posts_raw = get_posts(array(
|
107 |
-
'posts_per_page' => -1,
|
108 |
-
'post_type' => array('product', 'product_variation'),
|
109 |
-
'post_status' => $postStatus,
|
110 |
-
'fields' => 'ids',
|
111 |
-
));
|
112 |
-
|
113 |
-
foreach ($posts_raw as $post_id) {
|
114 |
-
$product = wc_get_product($post_id);
|
115 |
-
$products[$post_id] = $product->get_formatted_name();
|
116 |
-
//$products[$post_id] = '#' . $post_id . ' ' . get_the_title($post_id);
|
117 |
-
}
|
118 |
-
asort($products);
|
119 |
-
return $products;
|
120 |
-
}
|
121 |
-
|
122 |
-
/**
|
123 |
-
* To Get All Countries.
|
124 |
-
*
|
125 |
-
* @return array
|
126 |
-
*/
|
127 |
-
public function getAllCountries()
|
128 |
-
{
|
129 |
-
$countries = new WC_Countries();
|
130 |
-
|
131 |
-
if ($countries && is_array($countries->countries)) {
|
132 |
-
return array_merge(array(), $countries->countries);
|
133 |
-
} else {
|
134 |
-
return array();
|
135 |
-
}
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
* To Get All Capabilities list.
|
140 |
-
*
|
141 |
-
* @return array
|
142 |
-
*/
|
143 |
-
public function getCapabilitiesList()
|
144 |
-
{
|
145 |
-
$capabilities = array();
|
146 |
-
|
147 |
-
if (class_exists('Groups_User') && class_exists('Groups_Wordpress') && function_exists('_groups_get_tablename')) {
|
148 |
-
|
149 |
-
global $wpdb;
|
150 |
-
$capability_table = _groups_get_tablename('capability');
|
151 |
-
$all_capabilities = $wpdb->get_results('SELECT capability FROM ' . $capability_table);
|
152 |
-
|
153 |
-
if ($all_capabilities) {
|
154 |
-
foreach ($all_capabilities as $capability) {
|
155 |
-
$capabilities[$capability->capability] = $capability->capability;
|
156 |
-
}
|
157 |
-
}
|
158 |
-
} else {
|
159 |
-
global $wp_roles;
|
160 |
-
|
161 |
-
if (!isset($wp_roles)) {
|
162 |
-
get_role('administrator');
|
163 |
-
}
|
164 |
-
|
165 |
-
$roles = $wp_roles->roles;
|
166 |
-
|
167 |
-
if (is_array($roles)) {
|
168 |
-
foreach ($roles as $rolename => $atts) {
|
169 |
-
if (isset($atts['capabilities']) && is_array($atts['capabilities'])) {
|
170 |
-
foreach ($atts['capabilities'] as $capability => $value) {
|
171 |
-
if (!in_array($capability, $capabilities)) {
|
172 |
-
$capabilities[$capability] = $capability;
|
173 |
-
}
|
174 |
-
}
|
175 |
-
}
|
176 |
-
}
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
return array_merge(array(), $capabilities);
|
181 |
-
}
|
182 |
-
|
183 |
-
/**
|
184 |
-
* @return array
|
185 |
-
*/
|
186 |
-
public function getUserRoles()
|
187 |
-
{
|
188 |
-
global $wp_roles;
|
189 |
-
|
190 |
-
if (!isset($wp_roles)) {
|
191 |
-
$wp_roles = new WP_Roles();
|
192 |
-
}
|
193 |
-
|
194 |
-
return array_merge(array(), $wp_roles->get_names());
|
195 |
-
}
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Get list of roles assigned to current user
|
199 |
-
*
|
200 |
-
* @access public
|
201 |
-
* @return array
|
202 |
-
*/
|
203 |
-
public static function getCurrentUserRoles()
|
204 |
-
{
|
205 |
-
$current_user = wp_get_current_user();
|
206 |
-
return $current_user->roles;
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* @return array
|
211 |
-
*/
|
212 |
-
public function getCategoryList()
|
213 |
-
{
|
214 |
-
$result = array();
|
215 |
-
|
216 |
-
$post_categories_raw = get_terms(array('product_cat'), array('hide_empty' => 0));
|
217 |
-
$post_categories_raw_count = count($post_categories_raw);
|
218 |
-
|
219 |
-
foreach ($post_categories_raw as $post_cat_key => $post_cat) {
|
220 |
-
$category_name = $post_cat->name;
|
221 |
-
|
222 |
-
if ($post_cat->parent) {
|
223 |
-
$parent_id = $post_cat->parent;
|
224 |
-
$has_parent = true;
|
225 |
-
|
226 |
-
// Make sure we don't have an infinite loop here (happens with some kind of "ghost" categories)
|
227 |
-
$found = false;
|
228 |
-
$i = 0;
|
229 |
-
|
230 |
-
while ($has_parent && ($i < $post_categories_raw_count || $found)) {
|
231 |
-
|
232 |
-
// Reset each time
|
233 |
-
$found = false;
|
234 |
-
$i = 0;
|
235 |
-
|
236 |
-
foreach ($post_categories_raw as $parent_post_cat_key => $parent_post_cat) {
|
237 |
-
|
238 |
-
$i++;
|
239 |
-
|
240 |
-
if ($parent_post_cat->term_id == $parent_id) {
|
241 |
-
$category_name = $parent_post_cat->name . ' → ' . $category_name;
|
242 |
-
$found = true;
|
243 |
-
|
244 |
-
if ($parent_post_cat->parent) {
|
245 |
-
$parent_id = $parent_post_cat->parent;
|
246 |
-
} else {
|
247 |
-
$has_parent = false;
|
248 |
-
}
|
249 |
-
|
250 |
-
break;
|
251 |
-
}
|
252 |
-
}
|
253 |
-
}
|
254 |
-
}
|
255 |
-
|
256 |
-
$result[$post_cat->term_id] = $category_name;
|
257 |
-
}
|
258 |
-
|
259 |
-
return $result;
|
260 |
-
}
|
261 |
-
|
262 |
-
/**
|
263 |
-
* Get Category by passing product ID or Product.
|
264 |
-
*
|
265 |
-
* @param $item
|
266 |
-
* @param bool $is_id
|
267 |
-
* @return array
|
268 |
-
*/
|
269 |
-
public static function getCategoryByPost($item, $is_id = false)
|
270 |
-
{
|
271 |
-
if ($is_id) {
|
272 |
-
$id = $item;
|
273 |
-
} else {
|
274 |
-
$id = $item['data']->get_id();
|
275 |
-
}
|
276 |
-
$id = intval($id);
|
277 |
-
if (!$id) return false;
|
278 |
-
|
279 |
-
$categories = array();
|
280 |
-
$current_categories = wp_get_post_terms($id, 'product_cat');
|
281 |
-
foreach ($current_categories as $category) {
|
282 |
-
$categories[] = $category->term_id;
|
283 |
-
}
|
284 |
-
|
285 |
-
return $categories;
|
286 |
-
}
|
287 |
-
|
288 |
-
/**
|
289 |
-
* To Parsing the Array from String to Int.
|
290 |
-
*
|
291 |
-
* @param array $array
|
292 |
-
*/
|
293 |
-
public static function toInt(array &$array)
|
294 |
-
{
|
295 |
-
foreach ($array as $index => $item) {
|
296 |
-
$array[$index] = intval($item);
|
297 |
-
}
|
298 |
-
}
|
299 |
-
|
300 |
-
/**
|
301 |
-
* @param $version
|
302 |
-
* @return bool|mixed
|
303 |
-
*/
|
304 |
-
public static function wcVersion($version)
|
305 |
-
{
|
306 |
-
if (defined('WC_VERSION') && WC_VERSION) {
|
307 |
-
return version_compare(WC_VERSION, $version, '>=');
|
308 |
-
} else if (defined('WOOCOMMERCE_VERSION') && WOOCOMMERCE_VERSION) {
|
309 |
-
return version_compare(WOOCOMMERCE_VERSION, $version, '>=');
|
310 |
-
} else {
|
311 |
-
return false;
|
312 |
-
}
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* @param $html
|
317 |
-
* @return bool|mixed
|
318 |
-
*/
|
319 |
-
static function makeString($html)
|
320 |
-
{
|
321 |
-
if (is_null($html) || empty($html) || !isset($html)) return false;
|
322 |
-
$out = $html;
|
323 |
-
// This Process only helps, single level array.
|
324 |
-
if (is_array($html)) {
|
325 |
-
foreach ($html as $id => $value) {
|
326 |
-
self::escapeCode($value);
|
327 |
-
// Finally Eliminating the Special Chars.
|
328 |
-
// $value = preg_replace('/[^A-Za-z0-9]/', '', $value);
|
329 |
-
$html[$id] = $value;
|
330 |
-
}
|
331 |
-
return $out;
|
332 |
-
} else {
|
333 |
-
self::escapeCode($html);
|
334 |
-
// Finally Eliminating the Special Chars.
|
335 |
-
// $html = preg_replace('/[^A-Za-z0-9]/', '', $html);
|
336 |
-
return $html;
|
337 |
-
}
|
338 |
-
}
|
339 |
-
|
340 |
-
/**
|
341 |
-
* Re-Arrange the Index of Array to Make Usable.[2-D Array Only]
|
342 |
-
* @param $rules
|
343 |
-
*/
|
344 |
-
public static function reArrangeArray(&$rules)
|
345 |
-
{
|
346 |
-
$result = array();
|
347 |
-
foreach ($rules as $index => $item) {
|
348 |
-
foreach ($item as $id => $value) {
|
349 |
-
$result[$id] = $value;
|
350 |
-
}
|
351 |
-
}
|
352 |
-
$rules = $result;
|
353 |
-
}
|
354 |
-
|
355 |
-
/**
|
356 |
-
* @param $value
|
357 |
-
*/
|
358 |
-
static function escapeCode(&$value)
|
359 |
-
{
|
360 |
-
// Four Possible tags for PHP to Init.
|
361 |
-
$value = preg_replace(array('/^<\?php.*\?\>/', '/^<\%.*\%\>/', '/^<\?.*\?\>/', '/^<\?=.*\?\>/'), '', $value);
|
362 |
-
$value = self::delete_all_between('<?php', '?>', $value);
|
363 |
-
$value = self::delete_all_between('<?', '?>', $value);
|
364 |
-
$value = self::delete_all_between('<?=', '?>', $value);
|
365 |
-
$value = self::delete_all_between('<%', '%>', $value);
|
366 |
-
$value = str_replace(array('<?php', '<?', '<?=', '<%', '?>'), '', $value);
|
367 |
-
}
|
368 |
-
|
369 |
-
|
370 |
-
/**
|
371 |
-
* @param $beginning
|
372 |
-
* @param $end
|
373 |
-
* @param $string
|
374 |
-
* @return mixed
|
375 |
-
*/
|
376 |
-
static function delete_all_between($beginning, $end, $string)
|
377 |
-
{
|
378 |
-
|
379 |
-
if (!is_string($string)) return false;
|
380 |
-
|
381 |
-
$beginningPos = strpos($string, $beginning);
|
382 |
-
$endPos = strpos($string, $end);
|
383 |
-
if ($beginningPos === false || $endPos === false) {
|
384 |
-
return $string;
|
385 |
-
}
|
386 |
-
|
387 |
-
$textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);
|
388 |
-
|
389 |
-
return str_replace($textToDelete, '', $string);
|
390 |
-
}
|
391 |
-
|
392 |
-
/**
|
393 |
-
* To get slider content through curl
|
394 |
-
* */
|
395 |
-
public static function getSideBarContent(){
|
396 |
-
$html = '';
|
397 |
-
if(is_callable('curl_init')) {
|
398 |
-
$ch = curl_init();
|
399 |
-
curl_setopt($ch, CURLOPT_URL, 'https://www.flycart.org/updates/woo-discount-rules.json');
|
400 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
401 |
-
$contents = curl_exec($ch);
|
402 |
-
$contents_decode = json_decode($contents);
|
403 |
-
if(isset($contents_decode['0']->promo_html)){
|
404 |
-
$html = $contents_decode['0']->promo_html;
|
405 |
-
}
|
406 |
-
}
|
407 |
-
|
408 |
-
return $html;
|
409 |
-
}
|
410 |
-
}
|
411 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
helper/general-helper.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
include_once(WOO_DISCOUNT_DIR . '/helper/purchase.php');
|
4 |
-
|
5 |
/**
|
6 |
-
* Class
|
7 |
*/
|
8 |
-
if ( ! class_exists( '
|
9 |
-
class
|
10 |
{
|
11 |
|
12 |
public $isPro;
|
@@ -27,7 +27,7 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
27 |
{
|
28 |
if (!file_exists($path)) return false;
|
29 |
$this->checkPluginState();
|
30 |
-
$purchase = new
|
31 |
$suffix = $purchase->getSuffix();
|
32 |
ob_start();
|
33 |
$config = $data;
|
@@ -47,10 +47,9 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
47 |
|
48 |
public function checkPluginState()
|
49 |
{
|
50 |
-
$purchase = new
|
51 |
$this->isPro = $purchase->isPro();
|
52 |
return $this->isPro;
|
53 |
-
// $this->isPro = true;
|
54 |
}
|
55 |
|
56 |
/**
|
@@ -90,7 +89,7 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
90 |
*/
|
91 |
public function getProductList()
|
92 |
{
|
93 |
-
$base = new
|
94 |
$base = $base->getBaseConfig();
|
95 |
if (is_string($base)) $base = json_decode($base, true);
|
96 |
$show_draft = 0;
|
@@ -111,10 +110,11 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
111 |
));
|
112 |
|
113 |
foreach ($posts_raw as $post_id) {
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
}
|
|
|
118 |
return $products;
|
119 |
}
|
120 |
|
@@ -270,19 +270,22 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
270 |
if ($is_id) {
|
271 |
$id = $item;
|
272 |
} else {
|
273 |
-
$id = $item['data']
|
274 |
}
|
275 |
-
$
|
|
|
|
|
|
|
|
|
276 |
if (!$id) return false;
|
277 |
|
278 |
$categories = array();
|
279 |
$current_categories = wp_get_post_terms($id, 'product_cat');
|
280 |
-
|
281 |
foreach ($current_categories as $category) {
|
282 |
$categories[] = $category->term_id;
|
283 |
}
|
284 |
|
285 |
-
return $categories
|
286 |
}
|
287 |
|
288 |
/**
|
@@ -297,21 +300,6 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
297 |
}
|
298 |
}
|
299 |
|
300 |
-
/**
|
301 |
-
* @param $version
|
302 |
-
* @return bool|mixed
|
303 |
-
*/
|
304 |
-
public static function wcVersion($version)
|
305 |
-
{
|
306 |
-
if (defined('WC_VERSION') && WC_VERSION) {
|
307 |
-
return version_compare(WC_VERSION, $version, '>=');
|
308 |
-
} else if (defined('WOOCOMMERCE_VERSION') && WOOCOMMERCE_VERSION) {
|
309 |
-
return version_compare(WOOCOMMERCE_VERSION, $version, '>=');
|
310 |
-
} else {
|
311 |
-
return false;
|
312 |
-
}
|
313 |
-
}
|
314 |
-
|
315 |
/**
|
316 |
* @param $html
|
317 |
* @return bool|mixed
|
@@ -324,15 +312,11 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
324 |
if (is_array($html)) {
|
325 |
foreach ($html as $id => $value) {
|
326 |
self::escapeCode($value);
|
327 |
-
// Finally Eliminating the Special Chars.
|
328 |
-
// $value = preg_replace('/[^A-Za-z0-9]/', '', $value);
|
329 |
$html[$id] = $value;
|
330 |
}
|
331 |
return $out;
|
332 |
} else {
|
333 |
self::escapeCode($html);
|
334 |
-
// Finally Eliminating the Special Chars.
|
335 |
-
// $html = preg_replace('/[^A-Za-z0-9]/', '', $html);
|
336 |
return $html;
|
337 |
}
|
338 |
}
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
include_once(WOO_DISCOUNT_DIR . '/helper/purchase.php');
|
4 |
+
include_once(WOO_DISCOUNT_DIR . '/helper/woo-function.php');
|
5 |
/**
|
6 |
+
* Class FlycartWooDiscountRulesGeneralHelper
|
7 |
*/
|
8 |
+
if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
|
9 |
+
class FlycartWooDiscountRulesGeneralHelper
|
10 |
{
|
11 |
|
12 |
public $isPro;
|
27 |
{
|
28 |
if (!file_exists($path)) return false;
|
29 |
$this->checkPluginState();
|
30 |
+
$purchase = new FlycartWooDiscountRulesPurchase();
|
31 |
$suffix = $purchase->getSuffix();
|
32 |
ob_start();
|
33 |
$config = $data;
|
47 |
|
48 |
public function checkPluginState()
|
49 |
{
|
50 |
+
$purchase = new FlycartWooDiscountRulesPurchase();
|
51 |
$this->isPro = $purchase->isPro();
|
52 |
return $this->isPro;
|
|
|
53 |
}
|
54 |
|
55 |
/**
|
89 |
*/
|
90 |
public function getProductList()
|
91 |
{
|
92 |
+
$base = new FlycartWooDiscountBase();
|
93 |
$base = $base->getBaseConfig();
|
94 |
if (is_string($base)) $base = json_decode($base, true);
|
95 |
$show_draft = 0;
|
110 |
));
|
111 |
|
112 |
foreach ($posts_raw as $post_id) {
|
113 |
+
$product = FlycartWoocommerceProduct::wc_get_product($post_id);
|
114 |
+
$products[$post_id] = FlycartWoocommerceProduct::get_formatted_name($product);
|
115 |
+
//$products[$post_id] = '#' . $post_id . ' ' . get_the_title($post_id);
|
116 |
}
|
117 |
+
asort($products);
|
118 |
return $products;
|
119 |
}
|
120 |
|
270 |
if ($is_id) {
|
271 |
$id = $item;
|
272 |
} else {
|
273 |
+
$id = FlycartWoocommerceProduct::get_id($item['data']);
|
274 |
}
|
275 |
+
$product = FlycartWoocommerceProduct::wc_get_product($id);
|
276 |
+
$categories = FlycartWoocommerceProduct::get_category_ids($product);
|
277 |
+
return $categories;
|
278 |
+
|
279 |
+
/*$id = intval($id);
|
280 |
if (!$id) return false;
|
281 |
|
282 |
$categories = array();
|
283 |
$current_categories = wp_get_post_terms($id, 'product_cat');
|
|
|
284 |
foreach ($current_categories as $category) {
|
285 |
$categories[] = $category->term_id;
|
286 |
}
|
287 |
|
288 |
+
return $categories;*/
|
289 |
}
|
290 |
|
291 |
/**
|
300 |
}
|
301 |
}
|
302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
/**
|
304 |
* @param $html
|
305 |
* @return bool|mixed
|
312 |
if (is_array($html)) {
|
313 |
foreach ($html as $id => $value) {
|
314 |
self::escapeCode($value);
|
|
|
|
|
315 |
$html[$id] = $value;
|
316 |
}
|
317 |
return $out;
|
318 |
} else {
|
319 |
self::escapeCode($html);
|
|
|
|
|
320 |
return $html;
|
321 |
}
|
322 |
}
|
helper/purchase.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
/**
|
4 |
-
* Class
|
5 |
*/
|
6 |
-
if ( ! class_exists( '
|
7 |
-
class
|
8 |
{
|
9 |
|
10 |
/**
|
@@ -18,7 +18,7 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
18 |
public $siteURL = 'https://www.flycart.org/';
|
19 |
|
20 |
/**
|
21 |
-
*
|
22 |
*/
|
23 |
public function __construct()
|
24 |
{
|
@@ -47,7 +47,7 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
47 |
|
48 |
public function errorNoticeInAdminPages(){
|
49 |
$pro = $this->isPro();
|
50 |
-
$base = new
|
51 |
$config = $base->getBaseConfig();
|
52 |
if (is_string($config)) $config = json_decode($config, true);
|
53 |
$htmlPrefix = '<div class="notice notice-warning"><p>';
|
@@ -123,7 +123,7 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
123 |
// TODO: based on plugin_data display the update info text too. We can also make the subscription expiry chk in same request
|
124 |
// and display just the notice as a warning
|
125 |
|
126 |
-
$base = new
|
127 |
$config = $base->getBaseConfig();
|
128 |
if (is_string($config)) $config = json_decode($config, true);
|
129 |
|
@@ -167,7 +167,7 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
167 |
die();
|
168 |
}
|
169 |
|
170 |
-
$base = new
|
171 |
$base->saveConfig(1);
|
172 |
|
173 |
if ( $this->validateLicenseKey() ) {
|
@@ -191,7 +191,7 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
191 |
$cache_license_check = ( $already_check == 1 ) ? true : false ;
|
192 |
|
193 |
if($run){
|
194 |
-
$base = new
|
195 |
$config = $base->getBaseConfig();
|
196 |
if (is_string($config)) $config = json_decode($config, true);
|
197 |
if ( isset( $config['license_key'] ) && !empty($config['license_key']) ) {
|
@@ -261,10 +261,10 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
261 |
public function getUpdateURL($type='updatecheck')
|
262 |
{
|
263 |
$update_url = 'https://www.flycart.org/?wpaction='.$type.'&wpslug='.$this->slug;
|
264 |
-
$purchase_helper = new
|
265 |
$update_url .= '&pro='.(int)$purchase_helper->isPro();
|
266 |
$dlid = '';
|
267 |
-
$base = new
|
268 |
$config = $base->getBaseConfig();
|
269 |
if (is_string($config)) $config = json_decode($config);
|
270 |
$dlid = isset($config->license_key)? $config->license_key: null;
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
/**
|
4 |
+
* Class FlycartWooDiscountRulesPurchase
|
5 |
*/
|
6 |
+
if ( ! class_exists( 'FlycartWooDiscountRulesPurchase' ) ) {
|
7 |
+
class FlycartWooDiscountRulesPurchase
|
8 |
{
|
9 |
|
10 |
/**
|
18 |
public $siteURL = 'https://www.flycart.org/';
|
19 |
|
20 |
/**
|
21 |
+
* FlycartWooDiscountRulesPurchase constructor.
|
22 |
*/
|
23 |
public function __construct()
|
24 |
{
|
47 |
|
48 |
public function errorNoticeInAdminPages(){
|
49 |
$pro = $this->isPro();
|
50 |
+
$base = new FlycartWooDiscountBase();
|
51 |
$config = $base->getBaseConfig();
|
52 |
if (is_string($config)) $config = json_decode($config, true);
|
53 |
$htmlPrefix = '<div class="notice notice-warning"><p>';
|
123 |
// TODO: based on plugin_data display the update info text too. We can also make the subscription expiry chk in same request
|
124 |
// and display just the notice as a warning
|
125 |
|
126 |
+
$base = new FlycartWooDiscountBase();
|
127 |
$config = $base->getBaseConfig();
|
128 |
if (is_string($config)) $config = json_decode($config, true);
|
129 |
|
167 |
die();
|
168 |
}
|
169 |
|
170 |
+
$base = new FlycartWooDiscountBase();
|
171 |
$base->saveConfig(1);
|
172 |
|
173 |
if ( $this->validateLicenseKey() ) {
|
191 |
$cache_license_check = ( $already_check == 1 ) ? true : false ;
|
192 |
|
193 |
if($run){
|
194 |
+
$base = new FlycartWooDiscountBase();
|
195 |
$config = $base->getBaseConfig();
|
196 |
if (is_string($config)) $config = json_decode($config, true);
|
197 |
if ( isset( $config['license_key'] ) && !empty($config['license_key']) ) {
|
261 |
public function getUpdateURL($type='updatecheck')
|
262 |
{
|
263 |
$update_url = 'https://www.flycart.org/?wpaction='.$type.'&wpslug='.$this->slug;
|
264 |
+
$purchase_helper = new FlycartWooDiscountRulesPurchase();
|
265 |
$update_url .= '&pro='.(int)$purchase_helper->isPro();
|
266 |
$dlid = '';
|
267 |
+
$base = new FlycartWooDiscountBase();
|
268 |
$config = $base->getBaseConfig();
|
269 |
if (is_string($config)) $config = json_decode($config);
|
270 |
$dlid = isset($config->license_key)? $config->license_key: null;
|
helper/woo-function.php
ADDED
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if(!class_exists('FlycartWoocommerceVersion')){
|
5 |
+
class FlycartWoocommerceVersion{
|
6 |
+
/**
|
7 |
+
* @param $version
|
8 |
+
* @return bool|mixed
|
9 |
+
*/
|
10 |
+
public static function wcVersion($version)
|
11 |
+
{
|
12 |
+
if (defined('WC_VERSION') && WC_VERSION) {
|
13 |
+
return version_compare(WC_VERSION, $version, '>=');
|
14 |
+
} else if (defined('WOOCOMMERCE_VERSION') && WOOCOMMERCE_VERSION) {
|
15 |
+
return version_compare(WOOCOMMERCE_VERSION, $version, '>=');
|
16 |
+
} else {
|
17 |
+
return false;
|
18 |
+
}
|
19 |
+
}
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
if(!class_exists('FlycartWoocommerceProduct')){
|
24 |
+
class FlycartWoocommerceProduct{
|
25 |
+
/**
|
26 |
+
* Get WooCommerce product
|
27 |
+
*
|
28 |
+
* @access public
|
29 |
+
* @param int $product_id
|
30 |
+
* @return object
|
31 |
+
*/
|
32 |
+
public static function wc_get_product($product_id)
|
33 |
+
{
|
34 |
+
return FlycartWoocommerceVersion::wcVersion('2.2') ? wc_get_product($product_id) : get_product($product_id);
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get WooCommerce product format name
|
39 |
+
*
|
40 |
+
* @access public
|
41 |
+
* @param array $product
|
42 |
+
* @return int
|
43 |
+
*/
|
44 |
+
public static function get_formatted_name($product)
|
45 |
+
{
|
46 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0')){
|
47 |
+
return $product->get_formatted_name();
|
48 |
+
} else {
|
49 |
+
$post_id = self::get_id($product);
|
50 |
+
return '#' . $post_id . ' ' . get_the_title($post_id);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get WooCommerce product id
|
56 |
+
*
|
57 |
+
* @access public
|
58 |
+
* @param array $product
|
59 |
+
* @return int
|
60 |
+
*/
|
61 |
+
public static function get_id($product)
|
62 |
+
{
|
63 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product , 'get_id')){
|
64 |
+
return $product->get_id();
|
65 |
+
} else {
|
66 |
+
$_product_id = $product->id;
|
67 |
+
if(isset($product->variation_id)) $_product_id = $product->variation_id;
|
68 |
+
return $_product_id;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Get WooCommerce price
|
74 |
+
*
|
75 |
+
* @access public
|
76 |
+
* @param float $amount
|
77 |
+
* @return int/float
|
78 |
+
*/
|
79 |
+
public static function wc_price($amount){
|
80 |
+
return FlycartWoocommerceVersion::wcVersion('2.1') ? wc_price($amount) : woocommerce_price($amount);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Get WooCommerce price html
|
85 |
+
*
|
86 |
+
* @access public
|
87 |
+
* @param array $product
|
88 |
+
* @return int/float
|
89 |
+
*/
|
90 |
+
public static function get_price_html($product){
|
91 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_price_html() : $product->get_price_html();
|
92 |
+
}
|
93 |
+
|
94 |
+
//get_price_html
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Get WooCommerce product parent id
|
98 |
+
*
|
99 |
+
* @access public
|
100 |
+
* @param array $product
|
101 |
+
* @return int
|
102 |
+
*/
|
103 |
+
public static function get_parent_id($product){
|
104 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_parent_id() : $product->parent_id;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Get WooCommerce product price
|
109 |
+
*
|
110 |
+
* @access public
|
111 |
+
* @param array $product
|
112 |
+
* @return int/float
|
113 |
+
*/
|
114 |
+
public static function get_price($product){
|
115 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_price() : $product->price;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Set WooCommerce product price
|
120 |
+
*
|
121 |
+
* @access public
|
122 |
+
* @param array $product
|
123 |
+
*/
|
124 |
+
public static function set_price($product, $amount){
|
125 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0')){
|
126 |
+
$product->set_price($amount);
|
127 |
+
} else {
|
128 |
+
$product->price = $amount;
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Get product price including tax
|
134 |
+
*
|
135 |
+
* @access public
|
136 |
+
* @param object $product
|
137 |
+
* @param int $quantity
|
138 |
+
* @param float $price
|
139 |
+
* @return int
|
140 |
+
*/
|
141 |
+
public static function get_price_including_tax($product, $quantity = 1, $price = '')
|
142 |
+
{
|
143 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? wc_get_price_including_tax($product, array('qty' => $quantity, 'price' => $price)) : $product->get_price_including_tax($quantity, $price);
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Get product price excluding tax
|
148 |
+
*
|
149 |
+
* @access public
|
150 |
+
* @param object $product
|
151 |
+
* @param int $quantity
|
152 |
+
* @param float $price
|
153 |
+
* @return float
|
154 |
+
*/
|
155 |
+
public static function get_price_excluding_tax($product, $quantity = 1, $price = '')
|
156 |
+
{
|
157 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? wc_get_price_excluding_tax($product, array('qty' => $quantity, 'price' => $price)) : $product->get_price_excluding_tax($quantity, $price);
|
158 |
+
}
|
159 |
+
|
160 |
+
//wc_get_price_excluding_tax
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Get WooCommerce product title
|
164 |
+
*
|
165 |
+
* @access public
|
166 |
+
* @param array $product
|
167 |
+
* @return string
|
168 |
+
*/
|
169 |
+
public static function get_title($product){
|
170 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product , 'get_title')){
|
171 |
+
return $product->get_title();
|
172 |
+
} else if(isset($product->title)){
|
173 |
+
return $product->title;
|
174 |
+
} else {
|
175 |
+
if(isset($product->post->post_title))
|
176 |
+
return $product->post->post_title;
|
177 |
+
}
|
178 |
+
return '';
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Get WooCommerce product get_permalink
|
183 |
+
*
|
184 |
+
* @access public
|
185 |
+
* @param array $product
|
186 |
+
* @return string
|
187 |
+
*/
|
188 |
+
public static function get_permalink($product){
|
189 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product , 'get_permalink')){
|
190 |
+
return $product->get_permalink();
|
191 |
+
} else if(isset($product->get_permalink) && $product->get_permalink != ''){
|
192 |
+
return $product->get_permalink;
|
193 |
+
} else {
|
194 |
+
return get_permalink(self::get_id($product));
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Get WooCommerce product attributes
|
200 |
+
*
|
201 |
+
* @access public
|
202 |
+
* @param array $product
|
203 |
+
* @return array
|
204 |
+
*/
|
205 |
+
public static function get_attributes($product){
|
206 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_attributes() : $product->attributes;
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Get WooCommerce get_variant_ids
|
211 |
+
*
|
212 |
+
* @access public
|
213 |
+
* @param int $product_id
|
214 |
+
* @return array
|
215 |
+
*/
|
216 |
+
public static function get_variant_ids($product_id)
|
217 |
+
{
|
218 |
+
$ids = array();
|
219 |
+
$productV = new WC_Product_Variable( $product_id );
|
220 |
+
$variations = $productV->get_available_variations();
|
221 |
+
if(!empty($variations))
|
222 |
+
foreach ($variations as $variation) {
|
223 |
+
$ids[] = $variation['variation_id'];
|
224 |
+
}
|
225 |
+
return $ids;
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Get WooCommerce get_category_ids
|
230 |
+
*
|
231 |
+
* @access public
|
232 |
+
* @param object $product
|
233 |
+
* @return array
|
234 |
+
*/
|
235 |
+
public static function get_category_ids($product)
|
236 |
+
{
|
237 |
+
$parent = self::get_parent_id($product);
|
238 |
+
if($parent) $product = self::wc_get_product($parent);
|
239 |
+
$cat_id = array();
|
240 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product, 'get_category_ids')){
|
241 |
+
$cat_id = $product->get_category_ids();
|
242 |
+
} else {
|
243 |
+
$terms = get_the_terms ( self::get_id($product), 'product_cat' );
|
244 |
+
if(!empty($terms))
|
245 |
+
foreach ( $terms as $term ) {
|
246 |
+
$cat_id[] = $term->term_id;
|
247 |
+
}
|
248 |
+
}
|
249 |
+
return $cat_id;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
if(!class_exists('FlycartWoocommerceCartProduct')){
|
255 |
+
class FlycartWoocommerceCart{
|
256 |
+
/**
|
257 |
+
* Get cart
|
258 |
+
*
|
259 |
+
* @access public
|
260 |
+
* @return array
|
261 |
+
*/
|
262 |
+
public static function get_cart()
|
263 |
+
{
|
264 |
+
return WC()->cart->get_cart();
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Remove cart item
|
269 |
+
*
|
270 |
+
* @access public
|
271 |
+
* @return boolean
|
272 |
+
*/
|
273 |
+
public static function remove_cart_item($_cart_item_key)
|
274 |
+
{
|
275 |
+
return WC()->cart->remove_cart_item( $_cart_item_key );
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Add cart item
|
280 |
+
*
|
281 |
+
* @access public
|
282 |
+
* @param int $product_id
|
283 |
+
* @param int $quantity
|
284 |
+
* @param int $variation_id
|
285 |
+
* @param array $variation
|
286 |
+
* @param array $cart_item_data
|
287 |
+
* @return boolean
|
288 |
+
*/
|
289 |
+
public static function add_to_cart($product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array())
|
290 |
+
{
|
291 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0')){
|
292 |
+
return WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data);
|
293 |
+
} else {
|
294 |
+
ob_start();
|
295 |
+
return WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data);
|
296 |
+
ob_end_flush();
|
297 |
+
}
|
298 |
+
}
|
299 |
+
}
|
300 |
+
}
|
301 |
+
|
302 |
+
if(!class_exists('FlycartWoocommerceOrder')){
|
303 |
+
class FlycartWoocommerceOrder{
|
304 |
+
/**
|
305 |
+
* Get order id
|
306 |
+
*
|
307 |
+
* @access public
|
308 |
+
* @param object $order
|
309 |
+
* @return int
|
310 |
+
*/
|
311 |
+
public static function get_id($order)
|
312 |
+
{
|
313 |
+
FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_id() : $order->id;
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Get WooCommerce order
|
318 |
+
*
|
319 |
+
* @access public
|
320 |
+
* @param int $order_id
|
321 |
+
* @return object
|
322 |
+
*/
|
323 |
+
public static function wc_get_order($order_id)
|
324 |
+
{
|
325 |
+
return FlycartWoocommerceVersion::wcVersion('2.2') ? wc_get_order($order_id) : new WC_Order($order_id);
|
326 |
+
}
|
327 |
+
|
328 |
+
/**
|
329 |
+
* Get order total
|
330 |
+
*
|
331 |
+
* @access public
|
332 |
+
* @param object $order
|
333 |
+
* @return float
|
334 |
+
*/
|
335 |
+
public static function get_total($order)
|
336 |
+
{
|
337 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_total() : $order->order_total;
|
338 |
+
}
|
339 |
+
|
340 |
+
/**
|
341 |
+
* Get order billing_email
|
342 |
+
*
|
343 |
+
* @access public
|
344 |
+
* @param object $order
|
345 |
+
* @return float
|
346 |
+
*/
|
347 |
+
public static function get_billing_email($order)
|
348 |
+
{
|
349 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_billing_email() : $order->billing_email;
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Get order billing city
|
354 |
+
*
|
355 |
+
* @access public
|
356 |
+
* @param object $order
|
357 |
+
* @return float
|
358 |
+
*/
|
359 |
+
public static function get_billing_city($order)
|
360 |
+
{
|
361 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_billing_city() : $order->billing_city;
|
362 |
+
}
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
if(!class_exists('FlycartWoocommerceCoupon')){
|
367 |
+
class FlycartWoocommerceCoupon{
|
368 |
+
|
369 |
+
/**
|
370 |
+
* Get WooCommerce Coupon
|
371 |
+
*
|
372 |
+
* @access public
|
373 |
+
* @param int $coupon_code
|
374 |
+
* @return object
|
375 |
+
*/
|
376 |
+
public static function wc_get_coupon($coupon_code)
|
377 |
+
{
|
378 |
+
return new WC_Coupon($coupon_code);
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Get Coupon individual_use
|
383 |
+
*
|
384 |
+
* @access public
|
385 |
+
* @param object $coupon
|
386 |
+
* @return boolean
|
387 |
+
*/
|
388 |
+
public static function get_individual_use($coupon)
|
389 |
+
{
|
390 |
+
return FlycartWoocommerceVersion::wcVersion('3.0') ? $coupon->get_individual_use() : $coupon->individual_use;
|
391 |
+
}
|
392 |
+
}
|
393 |
+
}
|
includes/cart-rules-3.php
DELETED
@@ -1,1156 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
-
include_once(WOO_DISCOUNT_DIR . '/helper/general-helper-3.php');
|
4 |
-
include_once(WOO_DISCOUNT_DIR . '/includes/discount-base.php');
|
5 |
-
|
6 |
-
/**
|
7 |
-
* Class woo_dicount_rules_cartRules
|
8 |
-
*/
|
9 |
-
if (!class_exists('woo_dicount_rules_cartRules')) {
|
10 |
-
class woo_dicount_rules_cartRules
|
11 |
-
{
|
12 |
-
/**
|
13 |
-
* @var string
|
14 |
-
*/
|
15 |
-
private $option_name = 'woo_discount_cart_option';
|
16 |
-
|
17 |
-
/**
|
18 |
-
* @var string
|
19 |
-
*/
|
20 |
-
public $post_type = 'woo_discount_cart';
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @var bool
|
24 |
-
*/
|
25 |
-
public $discount_applied = false;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @var
|
29 |
-
*/
|
30 |
-
private $rules;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* @var
|
34 |
-
*/
|
35 |
-
public $rule_sets;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* @var array
|
39 |
-
*/
|
40 |
-
public $cart_items;
|
41 |
-
|
42 |
-
/**
|
43 |
-
* @var
|
44 |
-
*/
|
45 |
-
public $sub_total;
|
46 |
-
|
47 |
-
/**
|
48 |
-
* @var int
|
49 |
-
*/
|
50 |
-
public $discount_total = 0;
|
51 |
-
|
52 |
-
/**
|
53 |
-
* @var array
|
54 |
-
*/
|
55 |
-
public $coupon_list;
|
56 |
-
|
57 |
-
/**
|
58 |
-
* @var string
|
59 |
-
*/
|
60 |
-
public $coupon_code;
|
61 |
-
|
62 |
-
/**
|
63 |
-
* @var
|
64 |
-
*/
|
65 |
-
public $matched_sets;
|
66 |
-
|
67 |
-
public $postData;
|
68 |
-
|
69 |
-
/**
|
70 |
-
* woo_dicount_rules_cartRules constructor.
|
71 |
-
*/
|
72 |
-
public function __construct()
|
73 |
-
{
|
74 |
-
global $woocommerce;
|
75 |
-
|
76 |
-
$this->postData = \FlycartInput\FInput::getInstance();
|
77 |
-
$this->cart_items = (isset($woocommerce->cart->cart_contents) ? $woocommerce->cart->cart_contents : array());
|
78 |
-
$this->calculateCartSubtotal();
|
79 |
-
$this->coupon_list = (isset($woocommerce->cart->applied_coupons) ? $woocommerce->cart->applied_coupons : array());
|
80 |
-
|
81 |
-
// Check for Remove Coupon Request.
|
82 |
-
if (!is_null($this->postData->get('remove_coupon', null))) $this->removeWoocommerceCoupon($this->postData->get('remove_coupon'));
|
83 |
-
|
84 |
-
// Update Coupon Code
|
85 |
-
$this->coupon_code = strtolower($this->getCouponCode());
|
86 |
-
|
87 |
-
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Save Cart Configs.
|
92 |
-
*
|
93 |
-
* @param array $request bulk request data.
|
94 |
-
* @return bool
|
95 |
-
*/
|
96 |
-
public function save($request)
|
97 |
-
{
|
98 |
-
foreach ($request as $index => $value) {
|
99 |
-
if ($index !== 'discount_rule') {
|
100 |
-
// $request[$index] = generalHelper::makeString($value);
|
101 |
-
$request[$index] = woo_dicount_rules_generalHelper::makeString($value);
|
102 |
-
}
|
103 |
-
}
|
104 |
-
|
105 |
-
$id = (isset($request['rule_id']) ? $request['rule_id'] : false);
|
106 |
-
|
107 |
-
$id = intval($id);
|
108 |
-
if (!$id && $id != 0) return false;
|
109 |
-
|
110 |
-
$title = (isset($request['rule_name']) ? $request['rule_name'] : 'New');
|
111 |
-
$slug = str_replace(' ', '-', strtolower($title));
|
112 |
-
|
113 |
-
// To Lowercase.
|
114 |
-
$slug = strtolower($slug);
|
115 |
-
|
116 |
-
// Encoding String with Space.
|
117 |
-
$slug = str_replace(' ', '-', $slug);
|
118 |
-
|
119 |
-
$form = array(
|
120 |
-
'rule_name',
|
121 |
-
'rule_descr',
|
122 |
-
'date_from',
|
123 |
-
'date_to',
|
124 |
-
'apply_to',
|
125 |
-
'discount_type',
|
126 |
-
'to_discount',
|
127 |
-
'discount_rule',
|
128 |
-
'rule_order',
|
129 |
-
'status'
|
130 |
-
);
|
131 |
-
|
132 |
-
if ($id) {
|
133 |
-
$post = array(
|
134 |
-
'ID' => $id,
|
135 |
-
'post_title' => $title,
|
136 |
-
'post_name' => $slug,
|
137 |
-
'post_content' => 'New Rule',
|
138 |
-
'post_type' => $this->post_type,
|
139 |
-
'post_status' => 'publish'
|
140 |
-
);
|
141 |
-
wp_update_post($post);
|
142 |
-
} else {
|
143 |
-
$post = array(
|
144 |
-
'post_title' => $title,
|
145 |
-
'post_name' => $slug,
|
146 |
-
'post_content' => 'New Rule',
|
147 |
-
'post_type' => $this->post_type,
|
148 |
-
'post_status' => 'publish'
|
149 |
-
);
|
150 |
-
$id = wp_insert_post($post);
|
151 |
-
$request['status'] = 'publish';
|
152 |
-
}
|
153 |
-
foreach ($request['discount_rule'] as $index => $value) {
|
154 |
-
$request['discount_rule'][$index] = woo_dicount_rules_generalHelper::makeString($value);
|
155 |
-
}
|
156 |
-
|
157 |
-
if (isset($request['discount_rule'])) $request['discount_rule'] = json_encode($request['discount_rule']);
|
158 |
-
|
159 |
-
if (is_null($id) || !isset($id)) return false;
|
160 |
-
|
161 |
-
foreach ($request as $index => $value) {
|
162 |
-
if (in_array($index, $form)) {
|
163 |
-
if (get_post_meta($id, $index)) {
|
164 |
-
update_post_meta($id, $index, $value);
|
165 |
-
} else {
|
166 |
-
add_post_meta($id, $index, $value);
|
167 |
-
}
|
168 |
-
}
|
169 |
-
}
|
170 |
-
}
|
171 |
-
|
172 |
-
/**
|
173 |
-
* Load View Data.
|
174 |
-
*
|
175 |
-
* @param $option
|
176 |
-
* @param integer $id to load post.
|
177 |
-
* @return string mixed response.
|
178 |
-
*/
|
179 |
-
public function view($option, $id)
|
180 |
-
{
|
181 |
-
$id = intval($id);
|
182 |
-
if (!$id) return false;
|
183 |
-
|
184 |
-
$post = get_post($id, 'OBJECT');
|
185 |
-
if (isset($post)) {
|
186 |
-
if (isset($post->ID)) {
|
187 |
-
$post->meta = get_post_meta($post->ID);
|
188 |
-
}
|
189 |
-
}
|
190 |
-
return $post;
|
191 |
-
}
|
192 |
-
|
193 |
-
/**
|
194 |
-
* List of Checklist.
|
195 |
-
*/
|
196 |
-
public function checkPoint()
|
197 |
-
{
|
198 |
-
// Apply rules with products.
|
199 |
-
// NOT YET USED.
|
200 |
-
if ($this->discount_applied) return true;
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Load List of Rules.
|
205 |
-
*
|
206 |
-
* @return mixed
|
207 |
-
*/
|
208 |
-
public function getRules($onlyCount = false)
|
209 |
-
{
|
210 |
-
$posts = get_posts(array('post_type' => $this->post_type, 'numberposts' => '-1'));
|
211 |
-
if ($onlyCount) return count($posts);
|
212 |
-
if (isset($posts) && count($posts) > 0) {
|
213 |
-
foreach ($posts as $index => $item) {
|
214 |
-
$posts[$index]->meta = get_post_meta($posts[$index]->ID);
|
215 |
-
}
|
216 |
-
|
217 |
-
$this->rules = $posts;
|
218 |
-
}
|
219 |
-
return $posts;
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* To Analyzing the Pricing Rules to Apply the Discount in terms of price.
|
224 |
-
*/
|
225 |
-
public function analyse($woocommerce)
|
226 |
-
{
|
227 |
-
global $woocommerce;
|
228 |
-
// Re-arranging the Rules.
|
229 |
-
$this->organizeRules();
|
230 |
-
// Apply Group of Rules.
|
231 |
-
$this->applyRules();
|
232 |
-
// Get Overall Discounts.
|
233 |
-
$this->getDiscountAmount();
|
234 |
-
// Add a Coupon Virtually (Temporary access).
|
235 |
-
if ($this->discount_total != 0) {
|
236 |
-
add_filter('woocommerce_get_shop_coupon_data', array($this, 'addVirtualCoupon'), 10, 2);
|
237 |
-
add_action('woocommerce_after_calculate_totals', array($this, 'applyFakeCoupons'));
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
/**
|
242 |
-
*
|
243 |
-
*/
|
244 |
-
public function appliedCoupons()
|
245 |
-
{
|
246 |
-
|
247 |
-
}
|
248 |
-
|
249 |
-
|
250 |
-
/**
|
251 |
-
* To Make record of discount changes.
|
252 |
-
*
|
253 |
-
* @return bool
|
254 |
-
*/
|
255 |
-
public function makeLog()
|
256 |
-
{
|
257 |
-
if (is_null($this->coupon_code) || empty($this->coupon_code)) return false;
|
258 |
-
|
259 |
-
$discount_log = array(
|
260 |
-
'coupon_name' => $this->coupon_code,
|
261 |
-
'discount' => $this->discount_total,
|
262 |
-
);
|
263 |
-
WC()->session->set('woo_cart_discount', json_encode($discount_log));
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Virtually add Coupon to apply the Discount.
|
268 |
-
*
|
269 |
-
* @param array $unknown_param
|
270 |
-
* @param string $old_coupon_code Existing Coupon
|
271 |
-
* @return array|bool
|
272 |
-
*/
|
273 |
-
public function addVirtualCoupon($unknown_param, $old_coupon_code)
|
274 |
-
{
|
275 |
-
$coupon_code = $this->coupon_code;
|
276 |
-
// Getting Coupon Remove status from Session.
|
277 |
-
$is_removed = WC()->session->get('woo_coupon_removed');
|
278 |
-
// If Both are same, then it won't added.
|
279 |
-
if ($coupon_code == $is_removed) return false;
|
280 |
-
|
281 |
-
if ($old_coupon_code == $coupon_code) {
|
282 |
-
if ($this->postData->get('remove_coupon', false) == $coupon_code) return false;
|
283 |
-
$this->makeLog();
|
284 |
-
$coupon = array(
|
285 |
-
'id' => 321123 . rand(2, 9),
|
286 |
-
'type' => 'fixed_cart',
|
287 |
-
'amount' => $this->discount_total,
|
288 |
-
'individual_use' => false,
|
289 |
-
'product_ids' => array(),
|
290 |
-
'exclude_product_ids' => array(),
|
291 |
-
'usage_limit' => '',
|
292 |
-
'usage_limit_per_user' => '',
|
293 |
-
'limit_usage_to_x_items' => '',
|
294 |
-
'usage_count' => '',
|
295 |
-
'expiry_date' => '',
|
296 |
-
'apply_before_tax' => 'yes',
|
297 |
-
'free_shipping' => false,
|
298 |
-
'product_categories' => array(),
|
299 |
-
'exclude_product_categories' => array(),
|
300 |
-
'exclude_sale_items' => false,
|
301 |
-
'minimum_amount' => '',
|
302 |
-
'maximum_amount' => '',
|
303 |
-
'customer_email' => '',
|
304 |
-
);
|
305 |
-
|
306 |
-
return $coupon;
|
307 |
-
}
|
308 |
-
}
|
309 |
-
|
310 |
-
/**
|
311 |
-
* To Get the Coupon code that already specified.
|
312 |
-
*
|
313 |
-
* @return string
|
314 |
-
*/
|
315 |
-
public function getCouponCode()
|
316 |
-
{
|
317 |
-
$config = new woo_dicount_rules_WooDiscountBase();
|
318 |
-
$config = $config->getBaseConfig();
|
319 |
-
|
320 |
-
if (is_string($config)) $config = json_decode($config, true);
|
321 |
-
|
322 |
-
// Pre-Defined alternative Coupon Code.
|
323 |
-
$coupon = 'Discount';
|
324 |
-
|
325 |
-
// Verify and overwrite the Coupon Code.
|
326 |
-
if (isset($config['coupon_name']) && $config['coupon_name'] != '') $coupon = $config['coupon_name'];
|
327 |
-
return $coupon;
|
328 |
-
}
|
329 |
-
|
330 |
-
/**
|
331 |
-
* Apply fake coupon to cart
|
332 |
-
*
|
333 |
-
* @access public
|
334 |
-
* @return void
|
335 |
-
*/
|
336 |
-
public function applyFakeCoupons()
|
337 |
-
{
|
338 |
-
global $woocommerce;
|
339 |
-
|
340 |
-
// 'newyear' is a temporary coupon for validation.
|
341 |
-
$coupon_code = apply_filters('woocommerce_coupon_code', $this->coupon_code);
|
342 |
-
// Getting New Instance with the Coupon Code.
|
343 |
-
$the_coupon = new WC_Coupon($coupon_code);
|
344 |
-
// Validating the Coupon as Valid and discount status.
|
345 |
-
if ($the_coupon->is_valid() && !$woocommerce->cart->has_discount($coupon_code)) {
|
346 |
-
|
347 |
-
// Do not apply coupon with individual use coupon already applied
|
348 |
-
if ($woocommerce->cart->applied_coupons) {
|
349 |
-
foreach ($woocommerce->cart->applied_coupons as $code) {
|
350 |
-
$coupon = new WC_Coupon($code);
|
351 |
-
if ($coupon->individual_use == true) {
|
352 |
-
return false;
|
353 |
-
}
|
354 |
-
}
|
355 |
-
}
|
356 |
-
|
357 |
-
// Add coupon
|
358 |
-
$woocommerce->cart->applied_coupons[] = $coupon_code;
|
359 |
-
do_action('woocommerce_applied_coupon', $coupon_code);
|
360 |
-
|
361 |
-
return true;
|
362 |
-
}
|
363 |
-
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* Simply remove or reset the virtual coupon by set "empty" as value
|
367 |
-
* to "Woo's" session "woo_coupon_removed".
|
368 |
-
*
|
369 |
-
* @param $coupon
|
370 |
-
*/
|
371 |
-
public function removeWoocommerceCoupon($coupon)
|
372 |
-
{
|
373 |
-
WC()->session->set('woo_coupon_removed', $coupon);
|
374 |
-
}
|
375 |
-
|
376 |
-
/**
|
377 |
-
*
|
378 |
-
*/
|
379 |
-
public function removeCartDiscount()
|
380 |
-
{
|
381 |
-
global $woocommerce;
|
382 |
-
|
383 |
-
// Iterate over applied coupons and check each of them
|
384 |
-
foreach ($woocommerce->cart->applied_coupons as $code) {
|
385 |
-
|
386 |
-
// Check if coupon code matches our fake coupon code
|
387 |
-
if ($this->getCouponCode() === $code) {
|
388 |
-
|
389 |
-
// Get coupon
|
390 |
-
$coupon = new WC_Coupon($code);
|
391 |
-
|
392 |
-
// Remove coupon if it no longer exists
|
393 |
-
if (!$coupon->is_valid()) {
|
394 |
-
|
395 |
-
// Remove the coupon
|
396 |
-
add_filter('woocommerce_coupons_enabled', array($this, 'woocommerceEnableCoupons'));
|
397 |
-
$this->remove_woocommerce_coupon($code);
|
398 |
-
remove_filter('woocommerce_coupons_enabled', array($this, 'woocommerceEnableCoupons'));
|
399 |
-
}
|
400 |
-
}
|
401 |
-
}
|
402 |
-
}
|
403 |
-
|
404 |
-
/**
|
405 |
-
* @return string
|
406 |
-
*/
|
407 |
-
public function woocommerceEnableCoupons()
|
408 |
-
{
|
409 |
-
return 'true';
|
410 |
-
}
|
411 |
-
|
412 |
-
/**
|
413 |
-
*
|
414 |
-
*/
|
415 |
-
public function organizeRules()
|
416 |
-
{
|
417 |
-
// Loads the Rules to Global.
|
418 |
-
$this->getRules();
|
419 |
-
// Validate and Re-Assign the Rules.
|
420 |
-
$this->filterRules();
|
421 |
-
}
|
422 |
-
|
423 |
-
/**
|
424 |
-
* @return bool
|
425 |
-
*/
|
426 |
-
public function applyRules()
|
427 |
-
{
|
428 |
-
global $woocommerce;
|
429 |
-
// If there is no rules, then return false.
|
430 |
-
if (!isset($this->rules)) return false;
|
431 |
-
|
432 |
-
// Check point having list of checklist to apply.
|
433 |
-
if ($this->checkPoint()) return false;
|
434 |
-
|
435 |
-
// To Generate Valid Rule sets.
|
436 |
-
$this->generateRuleSets();
|
437 |
-
}
|
438 |
-
|
439 |
-
/**
|
440 |
-
*
|
441 |
-
*/
|
442 |
-
public function filterRules()
|
443 |
-
{
|
444 |
-
$rules = $this->rules;
|
445 |
-
|
446 |
-
if (is_null($rules) || !isset($rules)) return false;
|
447 |
-
// Start with empty set.
|
448 |
-
$rule_set = array();
|
449 |
-
foreach ($rules as $index => $rule) {
|
450 |
-
$status = (isset($rule->status) ? $rule->status : false);
|
451 |
-
|
452 |
-
// To Check as Plugin Active - InActive.
|
453 |
-
if ($status == 'publish') {
|
454 |
-
$date_from = (isset($rule->date_from) ? strtotime($rule->date_from) : false);
|
455 |
-
$date_to = (isset($rule->date_to) ? strtotime($rule->date_to) : false);
|
456 |
-
$today = strtotime(date('m/d/Y'));
|
457 |
-
|
458 |
-
// Validating Rule with Date of Expiry.
|
459 |
-
if (($date_from <= $today) && (($date_to == '') || ($date_to >= $today))) {
|
460 |
-
// Validating the Rule with its Order ID.
|
461 |
-
if (isset($rule->rule_order)) {
|
462 |
-
// If Order ID is '-', then this rule not going to implement.
|
463 |
-
if ($rule->rule_order !== '-') {
|
464 |
-
$rule_set[] = $rule;
|
465 |
-
}
|
466 |
-
}
|
467 |
-
}
|
468 |
-
}
|
469 |
-
}
|
470 |
-
$this->rules = $rule_set;
|
471 |
-
|
472 |
-
// To Order the Rules, based on its order ID.
|
473 |
-
$this->orderRules();
|
474 |
-
}
|
475 |
-
|
476 |
-
/**
|
477 |
-
* @return bool
|
478 |
-
*/
|
479 |
-
public function orderRules()
|
480 |
-
{
|
481 |
-
if (empty($this->rules)) return false;
|
482 |
-
|
483 |
-
$ordered_rules = array();
|
484 |
-
|
485 |
-
// Make associative array with Order ID.
|
486 |
-
foreach ($this->rules as $index => $rule) {
|
487 |
-
if (isset($rule->rule_order)) {
|
488 |
-
if ($rule->rule_order != '') {
|
489 |
-
$ordered_rules[$rule->rule_order] = $rule;
|
490 |
-
}
|
491 |
-
}
|
492 |
-
}
|
493 |
-
// Order the Rules with it's priority.
|
494 |
-
ksort($ordered_rules);
|
495 |
-
|
496 |
-
$this->rules = $ordered_rules;
|
497 |
-
}
|
498 |
-
|
499 |
-
/**
|
500 |
-
* @return bool
|
501 |
-
*/
|
502 |
-
public function generateRuleSets()
|
503 |
-
{
|
504 |
-
global $woocommerce;
|
505 |
-
$rule_sets = array();
|
506 |
-
|
507 |
-
if (!isset($this->rules)) return false;
|
508 |
-
|
509 |
-
// Loop the Rules set to collect matched rules.
|
510 |
-
foreach ($this->rules as $index => $rule) {
|
511 |
-
// General Rule Info.
|
512 |
-
$rule_sets[$index]['discount_type'] = 'price_discount';
|
513 |
-
$rule_sets[$index]['name'] = (isset($rule->rule_name) ? $rule->rule_name : 'Rule_' . $index);
|
514 |
-
$rule_sets[$index]['descr'] = (isset($rule->rule_descr) ? $rule->rule_descr : '');
|
515 |
-
$rule_sets[$index]['method'] = (isset($rule->rule_method) ? $rule->rule_method : 'qty_based');
|
516 |
-
$rule_sets[$index]['qty_based_on'] = (isset($rule->qty_based_on) ? $rule->qty_based_on : 'each_product');
|
517 |
-
$rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
|
518 |
-
$rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
|
519 |
-
$rule_sets[$index]['discount_rule'] = (isset($rule->discount_rule) ? $rule->discount_rule : false);
|
520 |
-
$rule_sets[$index]['discount_type'] = (isset($rule->discount_type) ? $rule->discount_type : false);
|
521 |
-
$rule_sets[$index]['to_discount'] = (isset($rule->to_discount) ? $rule->to_discount : false);
|
522 |
-
$rule_sets[$index]['enabled'] = $this->validateCart($rule_sets[$index]['discount_rule']);
|
523 |
-
}
|
524 |
-
$this->rule_sets = $rule_sets;
|
525 |
-
}
|
526 |
-
|
527 |
-
/**
|
528 |
-
* Get Overall discount amount across allover the rules that available.
|
529 |
-
*
|
530 |
-
* @return integer Total Discount Amount.
|
531 |
-
*/
|
532 |
-
public function getDiscountAmount()
|
533 |
-
{
|
534 |
-
$discount = 0;
|
535 |
-
$discounts = array();
|
536 |
-
if (!isset($this->rule_sets)) return false;
|
537 |
-
|
538 |
-
// Get settings
|
539 |
-
$config = new woo_dicount_rules_WooDiscountBase();
|
540 |
-
$config = $config->getBaseConfig();
|
541 |
-
if (is_string($config)) $config = json_decode($config, true);
|
542 |
-
if(isset($config['cart_setup'])){
|
543 |
-
$cart_setup = $config['cart_setup'];
|
544 |
-
} else {
|
545 |
-
$cart_setup = 'all';
|
546 |
-
}
|
547 |
-
|
548 |
-
if(count($this->rule_sets)){
|
549 |
-
if(in_array($cart_setup, array('first', 'all'))){
|
550 |
-
if($cart_setup == 'first'){
|
551 |
-
// Processing the Totals.
|
552 |
-
foreach ($this->rule_sets as $index => $rule) {
|
553 |
-
if ($rule['enabled'] == true) {
|
554 |
-
$discounts['name'][$index] = $rule['name'];
|
555 |
-
$discounts['type'][$index] = $rule['discount_type'];
|
556 |
-
if ($rule['discount_type'] == 'price_discount') {
|
557 |
-
// Getting the Flat Rate of Discount.
|
558 |
-
$discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
|
559 |
-
} else {
|
560 |
-
//we will have to re-calculate the sub-total if it has category selected
|
561 |
-
if($this->is_category_specific($rule)) {
|
562 |
-
//re-calculate the sub-total
|
563 |
-
$subtotal = $this->calculate_conditional_subtotal($this->get_discounted_categories_from_json($rule));
|
564 |
-
}else {
|
565 |
-
$subtotal = $this->sub_total;
|
566 |
-
}
|
567 |
-
// Getting the Percentage level of Discount.
|
568 |
-
$discounts['to_discount'][$index] = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
|
569 |
-
}
|
570 |
-
// Sum of Available discount list.
|
571 |
-
$discount += $discounts['to_discount'][$index];
|
572 |
-
// Update the status of the status of the discount rule.
|
573 |
-
$discounts['is_enabled'][$index] = $rule['enabled'];
|
574 |
-
break;
|
575 |
-
}
|
576 |
-
}
|
577 |
-
} else {
|
578 |
-
// Processing the Totals.
|
579 |
-
foreach ($this->rule_sets as $index => $rule) {
|
580 |
-
if ($rule['enabled'] == true) {
|
581 |
-
$discounts['name'][$index] = $rule['name'];
|
582 |
-
$discounts['type'][$index] = $rule['discount_type'];
|
583 |
-
if ($rule['discount_type'] == 'price_discount') {
|
584 |
-
// Getting the Flat Rate of Discount.
|
585 |
-
$discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
|
586 |
-
} else {
|
587 |
-
//we will have to re-calculate the sub-total if it has category selected
|
588 |
-
if($this->is_category_specific($rule)) {
|
589 |
-
//re-calculate the sub-total
|
590 |
-
$subtotal = $this->calculate_conditional_subtotal($this->get_discounted_categories_from_json($rule));
|
591 |
-
}else {
|
592 |
-
$subtotal = $this->sub_total;
|
593 |
-
}
|
594 |
-
// Getting the Percentage level of Discount.
|
595 |
-
$discounts['to_discount'][$index] = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
|
596 |
-
}
|
597 |
-
// Sum of Available discount list.
|
598 |
-
$discount += $discounts['to_discount'][$index];
|
599 |
-
// Update the status of the status of the discount rule.
|
600 |
-
$discounts['is_enabled'][$index] = $rule['enabled'];
|
601 |
-
}
|
602 |
-
}
|
603 |
-
}
|
604 |
-
} else if($cart_setup == 'biggest'){
|
605 |
-
$biggestDiscount = 0;
|
606 |
-
// Processing the Totals.
|
607 |
-
foreach ($this->rule_sets as $index => $rule) {
|
608 |
-
if ($rule['enabled'] == true) {
|
609 |
-
if ($rule['discount_type'] == 'price_discount') {
|
610 |
-
// Getting the Flat Rate of Discount.
|
611 |
-
$newDiscount = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
|
612 |
-
} else {
|
613 |
-
//we will have to re-calculate the sub-total if it has category selected
|
614 |
-
if($this->is_category_specific($rule)) {
|
615 |
-
//re-calculate the sub-total
|
616 |
-
$subtotal = $this->calculate_conditional_subtotal($this->get_discounted_categories_from_json($rule));
|
617 |
-
}else {
|
618 |
-
$subtotal = $this->sub_total;
|
619 |
-
}
|
620 |
-
// Getting the Percentage level of Discount.
|
621 |
-
$newDiscount = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
|
622 |
-
}
|
623 |
-
|
624 |
-
if($newDiscount > $biggestDiscount){
|
625 |
-
$biggestDiscount = $newDiscount;
|
626 |
-
$discounts['name'][1] = $rule['name'];
|
627 |
-
$discounts['type'][1] = $rule['discount_type'];
|
628 |
-
$discounts['to_discount'][1] = $newDiscount;
|
629 |
-
$discount = $newDiscount;
|
630 |
-
// Update the status of the status of the discount rule.
|
631 |
-
$discounts['is_enabled'][1] = $rule['enabled'];
|
632 |
-
}
|
633 |
-
}
|
634 |
-
}
|
635 |
-
}
|
636 |
-
}
|
637 |
-
|
638 |
-
$this->discount_total = $discount;
|
639 |
-
return $discounts;
|
640 |
-
}
|
641 |
-
|
642 |
-
/**
|
643 |
-
* Check is specific to category
|
644 |
-
* */
|
645 |
-
public function is_category_specific($rule) {
|
646 |
-
if(count($this->get_discounted_categories_from_json($rule))) {
|
647 |
-
return true;
|
648 |
-
}
|
649 |
-
return false;
|
650 |
-
}
|
651 |
-
|
652 |
-
/**
|
653 |
-
* get discount categories from rule
|
654 |
-
* */
|
655 |
-
public function get_discounted_categories_from_json($rule)
|
656 |
-
{
|
657 |
-
$categories = array();
|
658 |
-
if ( ! empty( $rule['discount_rule'] ) )
|
659 |
-
{
|
660 |
-
if(!is_object($rule['discount_rule'])) {
|
661 |
-
//assume it is a json string and parse
|
662 |
-
$rules = json_decode($rule['discount_rule'], true);
|
663 |
-
}
|
664 |
-
|
665 |
-
if(count($rules)) {
|
666 |
-
foreach($rules as $rule) {
|
667 |
-
if(array_key_exists('categories_in', $rule)) {
|
668 |
-
$categories = $rule['categories_in'];
|
669 |
-
break;
|
670 |
-
}
|
671 |
-
}
|
672 |
-
}
|
673 |
-
|
674 |
-
|
675 |
-
}
|
676 |
-
return $categories;
|
677 |
-
}
|
678 |
-
|
679 |
-
/**
|
680 |
-
* Comparing the Rules with the each line item to check
|
681 |
-
* and return as, matched or not.
|
682 |
-
*
|
683 |
-
* @param array $rules
|
684 |
-
* @return bool true|false
|
685 |
-
*/
|
686 |
-
public function validateCart($rules)
|
687 |
-
{
|
688 |
-
$this->calculateCartSubtotal();
|
689 |
-
$rules = (is_string($rules) ? json_decode($rules, true) : array());
|
690 |
-
// Simple array helper to re-arrange the structure.
|
691 |
-
woo_dicount_rules_generalHelper::reArrangeArray($rules);
|
692 |
-
foreach ($rules as $index => $rule) {
|
693 |
-
// Validating the Rules one by one.
|
694 |
-
if ($this->applyRule($index, $rule, $rules) == false) {
|
695 |
-
return false;
|
696 |
-
}
|
697 |
-
}
|
698 |
-
return true;
|
699 |
-
}
|
700 |
-
|
701 |
-
/**
|
702 |
-
* Applying bunch amount of rules with the line item.
|
703 |
-
*
|
704 |
-
* @param string $index Index of the Rule
|
705 |
-
* @param array $rule array of rule info.
|
706 |
-
* @return bool true|false as matched or not.
|
707 |
-
*/
|
708 |
-
public function applyRule($index, $rule, $rules)
|
709 |
-
{
|
710 |
-
$skipRuleType = array('categories_in');
|
711 |
-
$availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
|
712 |
-
switch ($index) {
|
713 |
-
|
714 |
-
// Cart Subtotal.
|
715 |
-
case 'subtotal_least':
|
716 |
-
if(!empty($availableRuleToSkip)){
|
717 |
-
} elseif ($this->sub_total < $rule) {
|
718 |
-
return false;
|
719 |
-
}
|
720 |
-
return true;
|
721 |
-
break;
|
722 |
-
case 'subtotal_less':
|
723 |
-
if(!empty($availableRuleToSkip)){
|
724 |
-
} elseif ($this->sub_total >= $rule) {
|
725 |
-
return false;
|
726 |
-
}
|
727 |
-
return true;
|
728 |
-
break;
|
729 |
-
|
730 |
-
// Cart Item Count.
|
731 |
-
case 'item_count_least':
|
732 |
-
if(!empty($availableRuleToSkip)){
|
733 |
-
} elseif (count($this->cart_items) < $rule) {
|
734 |
-
return false;
|
735 |
-
}
|
736 |
-
return true;
|
737 |
-
break;
|
738 |
-
case 'item_count_less':
|
739 |
-
if(!empty($availableRuleToSkip)){
|
740 |
-
} elseif (count($this->cart_items) >= $rule) {
|
741 |
-
return false;
|
742 |
-
}
|
743 |
-
return true;
|
744 |
-
break;
|
745 |
-
|
746 |
-
// Quantity Count.
|
747 |
-
case 'quantity_least':
|
748 |
-
if(!empty($availableRuleToSkip)){
|
749 |
-
} elseif ($this->cartItemQtyTotal() < $rule) {
|
750 |
-
return false;
|
751 |
-
}
|
752 |
-
return true;
|
753 |
-
break;
|
754 |
-
case 'quantity_less':
|
755 |
-
if(!empty($availableRuleToSkip)){
|
756 |
-
} elseif ($this->cartItemQtyTotal() >= $rule) {
|
757 |
-
return false;
|
758 |
-
}
|
759 |
-
return true;
|
760 |
-
break;
|
761 |
-
|
762 |
-
// Logged In Users.
|
763 |
-
case 'users_in':
|
764 |
-
if (get_current_user_id() == 0 || !in_array(get_current_user_id(), $rule)) {
|
765 |
-
return false;
|
766 |
-
}
|
767 |
-
return true;
|
768 |
-
break;
|
769 |
-
case 'shipping_countries_in':
|
770 |
-
// $user_meta = get_user_meta(get_current_user_id());
|
771 |
-
$shippingCountry = WC()->customer->get_shipping_country();
|
772 |
-
// if (!$user_meta || !isset($user_meta['shipping_country']) || empty($user_meta['shipping_country']) || !in_array($user_meta['shipping_country'][0], $rule)) {
|
773 |
-
if (empty($shippingCountry) || !in_array($shippingCountry, $rule)) {
|
774 |
-
return false;
|
775 |
-
}
|
776 |
-
return true;
|
777 |
-
break;
|
778 |
-
case 'roles_in':
|
779 |
-
if (get_current_user_id() == 0 || count(array_intersect(woo_dicount_rules_generalHelper::getCurrentUserRoles(), $rule)) == 0) {
|
780 |
-
return false;
|
781 |
-
}
|
782 |
-
return true;
|
783 |
-
break;
|
784 |
-
case 'customer_email_tld':
|
785 |
-
$rule = explode(',', $rule);
|
786 |
-
foreach($rule as $key => $r){
|
787 |
-
$rule[$key] = trim($r);
|
788 |
-
$rule[$key] = trim($rule[$key], '.');
|
789 |
-
}
|
790 |
-
$postData = $this->postData->get('post_data', '', 'raw');
|
791 |
-
$postDataArray = array();
|
792 |
-
if($postData != ''){
|
793 |
-
parse_str($postData, $postDataArray);
|
794 |
-
}
|
795 |
-
$postBillingEmail = $this->postData->get('billing_email', '', 'raw');
|
796 |
-
if($postBillingEmail != ''){
|
797 |
-
$postDataArray['billing_email'] = $postBillingEmail;
|
798 |
-
}
|
799 |
-
if(!get_current_user_id()){
|
800 |
-
$order_id = $this->postData->get('order-received', 0);
|
801 |
-
if($order_id){
|
802 |
-
$order = new WC_Order( $order_id);
|
803 |
-
$postDataArray['billing_email'] = $order->billing_email;
|
804 |
-
}
|
805 |
-
}
|
806 |
-
if(isset($postDataArray['billing_email']) && $postDataArray['billing_email'] != ''){
|
807 |
-
$user_email = $postDataArray['billing_email'];
|
808 |
-
if(get_current_user_id()){
|
809 |
-
update_user_meta(get_current_user_id(), 'billing_email', $user_email);
|
810 |
-
}
|
811 |
-
$tld = $this->getTLDFromEmail($user_email);
|
812 |
-
if(in_array($tld, $rule)){
|
813 |
-
return true;
|
814 |
-
}
|
815 |
-
} else if(get_current_user_id()){
|
816 |
-
$user_email = get_user_meta( get_current_user_id(), 'billing_email', true );
|
817 |
-
if($user_email != '' && !empty($user_email)){
|
818 |
-
$tld = $this->getTLDFromEmail($user_email);
|
819 |
-
if(in_array($tld, $rule)){
|
820 |
-
return true;
|
821 |
-
}
|
822 |
-
} else {
|
823 |
-
$user_details = get_userdata( get_current_user_id() );
|
824 |
-
if(isset($user_details->data->user_email) && $user_details->data->user_email != ''){
|
825 |
-
$user_email = $user_details->data->user_email;
|
826 |
-
$tld = $this->getTLDFromEmail($user_email);
|
827 |
-
if(in_array($tld, $rule)){
|
828 |
-
return true;
|
829 |
-
}
|
830 |
-
}
|
831 |
-
}
|
832 |
-
}
|
833 |
-
return false;
|
834 |
-
break;
|
835 |
-
|
836 |
-
case 'customer_billing_city':
|
837 |
-
$rule = explode(',', $rule);
|
838 |
-
foreach($rule as $key => $r){
|
839 |
-
$rule[$key] = strtolower(trim($r));
|
840 |
-
}
|
841 |
-
$postData = $this->postData->get('post_data', '', 'raw');
|
842 |
-
$postDataArray = array();
|
843 |
-
if($postData != ''){
|
844 |
-
parse_str($postData, $postDataArray);
|
845 |
-
}
|
846 |
-
$postBillingEmail = $this->postData->get('billing_city', '', 'raw');
|
847 |
-
if($postBillingEmail != ''){
|
848 |
-
$postDataArray['billing_city'] = $postBillingEmail;
|
849 |
-
}
|
850 |
-
if(!get_current_user_id()){
|
851 |
-
$order_id = $this->postData->get('order-received', 0);
|
852 |
-
if($order_id){
|
853 |
-
$order = new WC_Order( $order_id);
|
854 |
-
$postDataArray['billing_city'] = $order->billing_city;
|
855 |
-
}
|
856 |
-
}
|
857 |
-
if(isset($postDataArray['billing_city']) && $postDataArray['billing_city'] != ''){
|
858 |
-
$billingCity = $postDataArray['billing_city'];
|
859 |
-
if(in_array(strtolower($billingCity), $rule)){
|
860 |
-
return true;
|
861 |
-
}
|
862 |
-
} else if(get_current_user_id()){
|
863 |
-
$billingCity = get_user_meta( get_current_user_id(), 'billing_city', true );
|
864 |
-
if($billingCity != '' && !empty($billingCity)){
|
865 |
-
if(in_array(strtolower($billingCity), $rule)){
|
866 |
-
return true;
|
867 |
-
}
|
868 |
-
}
|
869 |
-
}
|
870 |
-
return false;
|
871 |
-
break;
|
872 |
-
case 'categories_in':
|
873 |
-
if(count($rule)){
|
874 |
-
$ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules);
|
875 |
-
if($ruleSuccess){
|
876 |
-
return true;
|
877 |
-
}
|
878 |
-
}
|
879 |
-
return false;
|
880 |
-
break;
|
881 |
-
case 'customer_based_on_purchase_history':
|
882 |
-
if(count($rule)){
|
883 |
-
$ruleSuccess = $this->validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules);
|
884 |
-
if($ruleSuccess){
|
885 |
-
return true;
|
886 |
-
}
|
887 |
-
}
|
888 |
-
return false;
|
889 |
-
break;
|
890 |
-
/*case 'categories_atleast_one':
|
891 |
-
if(count($rule)){
|
892 |
-
$w_categories = $this->getCartProductCaregories();
|
893 |
-
if(count($w_categories)){
|
894 |
-
foreach ($rule as $cat){
|
895 |
-
if(in_array($cat, $w_categories)){
|
896 |
-
return true;
|
897 |
-
}
|
898 |
-
}
|
899 |
-
}
|
900 |
-
}
|
901 |
-
return false;
|
902 |
-
break;*/
|
903 |
-
|
904 |
-
}
|
905 |
-
|
906 |
-
}
|
907 |
-
|
908 |
-
/**
|
909 |
-
* check the cart items satisfies purchase history rule
|
910 |
-
* */
|
911 |
-
protected function validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules){
|
912 |
-
$allowed = 0;
|
913 |
-
$user = get_current_user_id();
|
914 |
-
if($user){
|
915 |
-
if(isset($rule['purchase_history_order_status']) && isset($rule['purchased_history_amount'])){
|
916 |
-
if($rule['purchased_history_amount'] > 0){
|
917 |
-
$purchase_history_status_list = isset($rule['purchase_history_order_status'])? $rule['purchase_history_order_status']: array('wc-completed');
|
918 |
-
$customerOrders = get_posts( array(
|
919 |
-
'numberposts' => -1,
|
920 |
-
'meta_key' => '_customer_user',
|
921 |
-
'meta_value' => $user,
|
922 |
-
'post_type' => wc_get_order_types(),
|
923 |
-
'post_status' => $purchase_history_status_list,
|
924 |
-
) );
|
925 |
-
$totalPurchasedAmount = 0;
|
926 |
-
if(!empty($customerOrders)){
|
927 |
-
foreach ($customerOrders as $customerOrder) {
|
928 |
-
$order = wc_get_order($customerOrder->ID);
|
929 |
-
$total = $order->get_total();
|
930 |
-
$totalPurchasedAmount += $total;
|
931 |
-
}
|
932 |
-
}
|
933 |
-
if($totalPurchasedAmount >= $rule['purchased_history_amount']){
|
934 |
-
$allowed = 1;
|
935 |
-
}
|
936 |
-
}
|
937 |
-
}
|
938 |
-
}
|
939 |
-
|
940 |
-
return $allowed;
|
941 |
-
}
|
942 |
-
|
943 |
-
/**
|
944 |
-
* verify the cart items are from selected category
|
945 |
-
* */
|
946 |
-
protected function validateCartItemsInSelectedCategory($index, $rule, $rules){
|
947 |
-
$ruleSuccess = 0;
|
948 |
-
global $woocommerce;
|
949 |
-
$product_cat_id = array();
|
950 |
-
if(count($woocommerce->cart->cart_contents)){
|
951 |
-
foreach ($woocommerce->cart->cart_contents as $key => $cartItem) {
|
952 |
-
$terms = get_the_terms( $cartItem['product_id'], 'product_cat' );
|
953 |
-
if($terms){
|
954 |
-
foreach ($terms as $term) {
|
955 |
-
$product_id = '';
|
956 |
-
$sub_total = $quantity = $item_count = 0;
|
957 |
-
if(isset($product_cat_id[$term->term_id])){
|
958 |
-
$product_id = $product_cat_id[$term->term_id]->product_id.',';
|
959 |
-
$sub_total = $product_cat_id[$term->term_id]->sub_total;
|
960 |
-
$quantity = $product_cat_id[$term->term_id]->quantity;
|
961 |
-
$item_count = $product_cat_id[$term->term_id]->item_count;
|
962 |
-
}
|
963 |
-
$productDetailObject = new stdClass();
|
964 |
-
$productDetailObject->cat_id = $term->term_id;
|
965 |
-
$productDetailObject->product_id = trim($product_id.$cartItem['product_id'], ',');
|
966 |
-
$productDetailObject->sub_total = $sub_total+$cartItem['line_subtotal'];//+$cartItem['line_subtotal_tax'];
|
967 |
-
$productDetailObject->quantity = $quantity+$cartItem['quantity'];
|
968 |
-
$productDetailObject->item_count = $item_count+1;
|
969 |
-
$product_cat_id[$term->term_id] = $productDetailObject;
|
970 |
-
}
|
971 |
-
}
|
972 |
-
}
|
973 |
-
}
|
974 |
-
$category_ids = array_keys($product_cat_id);
|
975 |
-
$categoryFound = 0;
|
976 |
-
$product_id = $cat_id = '';
|
977 |
-
$sub_total = $quantity = $item_count = 0;
|
978 |
-
$existingProductId = array();
|
979 |
-
foreach ($rule as $catid){
|
980 |
-
if(in_array($catid, $category_ids)){
|
981 |
-
if(isset($product_cat_id[$catid])){
|
982 |
-
$categoryFound = 1;
|
983 |
-
if(isset($existingProductId[$product_cat_id[$catid]->product_id])){
|
984 |
-
$existingProductId[$product_cat_id[$catid]->product_id]['cat_ids'][] = $product_cat_id[$catid]->cat_id;
|
985 |
-
} else {
|
986 |
-
$existingProductId[$product_cat_id[$catid]->product_id]['cat_ids'][] = $product_cat_id[$catid]->cat_id;
|
987 |
-
$cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
|
988 |
-
$product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
|
989 |
-
$sub_total = $sub_total+$product_cat_id[$catid]->sub_total;
|
990 |
-
$quantity = $quantity+$product_cat_id[$catid]->quantity;
|
991 |
-
$item_count = $item_count+$product_cat_id[$catid]->item_count;
|
992 |
-
}
|
993 |
-
}
|
994 |
-
}
|
995 |
-
}
|
996 |
-
if($categoryFound){
|
997 |
-
$ruleSuccess = 1;
|
998 |
-
foreach ($rules as $rule_type => $rule_values){
|
999 |
-
$checkRuleTypes = array('quantity_least', 'quantity_less', 'subtotal_least', 'subtotal_less', 'item_count_least', 'item_count_less');
|
1000 |
-
if(in_array($rule_type, $checkRuleTypes)){
|
1001 |
-
if($rule_type == 'subtotal_least'){
|
1002 |
-
if ($sub_total < $rule_values) {
|
1003 |
-
$ruleSuccess = 0;
|
1004 |
-
}
|
1005 |
-
} elseif ($rule_type == 'subtotal_less'){
|
1006 |
-
|
1007 |
-
if ($sub_total >= $rule_values) {
|
1008 |
-
$ruleSuccess = 0;
|
1009 |
-
}
|
1010 |
-
} elseif ($rule_type == 'item_count_least'){
|
1011 |
-
if ($item_count < $rule_values) {
|
1012 |
-
$ruleSuccess = 0;
|
1013 |
-
}
|
1014 |
-
} elseif ($rule_type == 'item_count_less'){
|
1015 |
-
if ($item_count >= $rule_values) {
|
1016 |
-
$ruleSuccess = 0;
|
1017 |
-
}
|
1018 |
-
} elseif ($rule_type == 'quantity_least'){
|
1019 |
-
if ($quantity < $rule_values) {
|
1020 |
-
$ruleSuccess = 0;
|
1021 |
-
}
|
1022 |
-
} elseif ($rule_type == 'quantity_less'){
|
1023 |
-
if ($quantity >= $rule_values) {
|
1024 |
-
$ruleSuccess = 0;
|
1025 |
-
}
|
1026 |
-
}
|
1027 |
-
}
|
1028 |
-
}
|
1029 |
-
}
|
1030 |
-
|
1031 |
-
return $ruleSuccess;
|
1032 |
-
}
|
1033 |
-
|
1034 |
-
/**
|
1035 |
-
* Get tld from email
|
1036 |
-
* */
|
1037 |
-
protected function getTLDFromEmail($email){
|
1038 |
-
$emailArray = explode('@', $email);
|
1039 |
-
if(isset($emailArray[1])){
|
1040 |
-
$emailDomainArray = explode('.', $emailArray[1]);
|
1041 |
-
if(count($emailDomainArray)>1){
|
1042 |
-
unset($emailDomainArray[0]);
|
1043 |
-
}
|
1044 |
-
return implode('.', $emailDomainArray);
|
1045 |
-
}
|
1046 |
-
return $emailArray[0];
|
1047 |
-
}
|
1048 |
-
|
1049 |
-
/**
|
1050 |
-
* To get product categories
|
1051 |
-
* */
|
1052 |
-
/*public function getCartProductCaregories(){
|
1053 |
-
global $woocommerce;
|
1054 |
-
$product_cat_id = array();
|
1055 |
-
if(count($woocommerce->cart->cart_contents)){
|
1056 |
-
foreach ($woocommerce->cart->cart_contents as $cartItem) {
|
1057 |
-
$terms = get_the_terms( $cartItem['product_id'], 'product_cat' );
|
1058 |
-
if($terms)
|
1059 |
-
foreach ($terms as $term) {
|
1060 |
-
$product_cat_id[] = $term->term_id;
|
1061 |
-
}
|
1062 |
-
}
|
1063 |
-
}
|
1064 |
-
return $product_cat_id;
|
1065 |
-
}*/
|
1066 |
-
|
1067 |
-
/**
|
1068 |
-
* Get cart total amount
|
1069 |
-
*
|
1070 |
-
* @access public
|
1071 |
-
* @return float
|
1072 |
-
*/
|
1073 |
-
public function calculateCartSubtotal()
|
1074 |
-
{
|
1075 |
-
$cart_subtotal = 0;
|
1076 |
-
// Iterate over all cart items and
|
1077 |
-
foreach ($this->cart_items as $cart_item_key => $cart_item) {
|
1078 |
-
$quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1079 |
-
$cart_subtotal += $cart_item['data']->get_price() * $quantity;
|
1080 |
-
}
|
1081 |
-
|
1082 |
-
$this->sub_total = (float)$cart_subtotal;
|
1083 |
-
|
1084 |
-
}
|
1085 |
-
|
1086 |
-
public function calculate_conditional_subtotal($conditions) {
|
1087 |
-
|
1088 |
-
$cart_subtotal = 0;
|
1089 |
-
// Iterate over all cart items and
|
1090 |
-
foreach ($this->cart_items as $cart_item_key => $cart_item) {
|
1091 |
-
|
1092 |
-
if($this->does_item_belong_to_category($conditions, $cart_item['data'])) {
|
1093 |
-
|
1094 |
-
//total should be specific to the products from certan categories
|
1095 |
-
$quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1096 |
-
$cart_subtotal += $cart_item['data']->get_price() * $quantity;
|
1097 |
-
}
|
1098 |
-
|
1099 |
-
}
|
1100 |
-
|
1101 |
-
return (float)$cart_subtotal;
|
1102 |
-
|
1103 |
-
}
|
1104 |
-
|
1105 |
-
public function does_item_belong_to_category($categories, $product) {
|
1106 |
-
|
1107 |
-
$result = array_intersect($categories, $product->get_category_ids());
|
1108 |
-
if(is_array($result) && count($result) > 0) {
|
1109 |
-
return true;
|
1110 |
-
}
|
1111 |
-
return false;
|
1112 |
-
}
|
1113 |
-
|
1114 |
-
|
1115 |
-
/**
|
1116 |
-
* To Sum the Cart Item's Qty.
|
1117 |
-
*
|
1118 |
-
* @return int Total Qty of Cart.
|
1119 |
-
*/
|
1120 |
-
public function cartItemQtyTotal()
|
1121 |
-
{
|
1122 |
-
global $woocommerce;
|
1123 |
-
$cart_items = $woocommerce->cart->cart_contents;
|
1124 |
-
$total_quantity = 0;
|
1125 |
-
|
1126 |
-
foreach ($cart_items as $cart_item) {
|
1127 |
-
$current_quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1128 |
-
$total_quantity += $current_quantity;
|
1129 |
-
}
|
1130 |
-
return $total_quantity;
|
1131 |
-
}
|
1132 |
-
|
1133 |
-
/**
|
1134 |
-
* Overall Discount Calculation based on Percentage or Flat.
|
1135 |
-
*
|
1136 |
-
* @param integer $sub_total Subtotal of the Cart.
|
1137 |
-
* @param integer $adjustment percentage or discount of adjustment.
|
1138 |
-
* @return integer Final Discount Amount.
|
1139 |
-
*/
|
1140 |
-
public function calculateDiscount($sub_total, $adjustment)
|
1141 |
-
{
|
1142 |
-
$sub_total = ($sub_total < 0) ? 0 : $sub_total;
|
1143 |
-
|
1144 |
-
$discount = 0;
|
1145 |
-
|
1146 |
-
if ($adjustment['type'] == 'percentage') {
|
1147 |
-
$discount = $sub_total * ($adjustment['value'] / 100);
|
1148 |
-
} else if ($adjustment['type'] == 'price') {
|
1149 |
-
$discount = $adjustment['value'];
|
1150 |
-
}
|
1151 |
-
|
1152 |
-
return ($discount <= 0) ? 0 : $discount;
|
1153 |
-
}
|
1154 |
-
|
1155 |
-
}
|
1156 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/cart-rules.php
CHANGED
@@ -4,10 +4,10 @@ include_once(WOO_DISCOUNT_DIR . '/helper/general-helper.php');
|
|
4 |
include_once(WOO_DISCOUNT_DIR . '/includes/discount-base.php');
|
5 |
|
6 |
/**
|
7 |
-
* Class
|
8 |
*/
|
9 |
-
if (!class_exists('
|
10 |
-
class
|
11 |
{
|
12 |
/**
|
13 |
* @var string
|
@@ -67,7 +67,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
67 |
public $postData;
|
68 |
|
69 |
/**
|
70 |
-
*
|
71 |
*/
|
72 |
public function __construct()
|
73 |
{
|
@@ -83,8 +83,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
83 |
|
84 |
// Update Coupon Code
|
85 |
$this->coupon_code = strtolower($this->getCouponCode());
|
86 |
-
|
87 |
-
|
88 |
}
|
89 |
|
90 |
/**
|
@@ -97,8 +95,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
97 |
{
|
98 |
foreach ($request as $index => $value) {
|
99 |
if ($index !== 'discount_rule') {
|
100 |
-
|
101 |
-
$request[$index] = woo_dicount_rules_generalHelper::makeString($value);
|
102 |
}
|
103 |
}
|
104 |
|
@@ -150,9 +147,8 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
150 |
$id = wp_insert_post($post);
|
151 |
$request['status'] = 'publish';
|
152 |
}
|
153 |
-
|
154 |
foreach ($request['discount_rule'] as $index => $value) {
|
155 |
-
$request['discount_rule'][$index] =
|
156 |
}
|
157 |
|
158 |
if (isset($request['discount_rule'])) $request['discount_rule'] = json_encode($request['discount_rule']);
|
@@ -239,15 +235,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
239 |
}
|
240 |
}
|
241 |
|
242 |
-
/**
|
243 |
-
*
|
244 |
-
*/
|
245 |
-
public function appliedCoupons()
|
246 |
-
{
|
247 |
-
|
248 |
-
}
|
249 |
-
|
250 |
-
|
251 |
/**
|
252 |
* To Make record of discount changes.
|
253 |
*
|
@@ -286,7 +273,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
286 |
'id' => 321123 . rand(2, 9),
|
287 |
'type' => 'fixed_cart',
|
288 |
'amount' => $this->discount_total,
|
289 |
-
'individual_use' =>
|
290 |
'product_ids' => array(),
|
291 |
'exclude_product_ids' => array(),
|
292 |
'usage_limit' => '',
|
@@ -295,10 +282,10 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
295 |
'usage_count' => '',
|
296 |
'expiry_date' => '',
|
297 |
'apply_before_tax' => 'yes',
|
298 |
-
'free_shipping' =>
|
299 |
'product_categories' => array(),
|
300 |
'exclude_product_categories' => array(),
|
301 |
-
'exclude_sale_items' =>
|
302 |
'minimum_amount' => '',
|
303 |
'maximum_amount' => '',
|
304 |
'customer_email' => '',
|
@@ -315,7 +302,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
315 |
*/
|
316 |
public function getCouponCode()
|
317 |
{
|
318 |
-
$config = new
|
319 |
$config = $config->getBaseConfig();
|
320 |
|
321 |
if (is_string($config)) $config = json_decode($config, true);
|
@@ -341,16 +328,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
341 |
// 'newyear' is a temporary coupon for validation.
|
342 |
$coupon_code = apply_filters('woocommerce_coupon_code', $this->coupon_code);
|
343 |
// Getting New Instance with the Coupon Code.
|
344 |
-
$the_coupon =
|
345 |
// Validating the Coupon as Valid and discount status.
|
346 |
if ($the_coupon->is_valid() && !$woocommerce->cart->has_discount($coupon_code)) {
|
347 |
|
348 |
// Do not apply coupon with individual use coupon already applied
|
349 |
if ($woocommerce->cart->applied_coupons) {
|
350 |
foreach ($woocommerce->cart->applied_coupons as $code) {
|
351 |
-
$coupon =
|
352 |
-
|
353 |
-
if ($coupon->individual_use == 'yes') {
|
354 |
return false;
|
355 |
}
|
356 |
}
|
@@ -375,34 +361,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
375 |
WC()->session->set('woo_coupon_removed', $coupon);
|
376 |
}
|
377 |
|
378 |
-
/**
|
379 |
-
*
|
380 |
-
*/
|
381 |
-
public function removeCartDiscount()
|
382 |
-
{
|
383 |
-
global $woocommerce;
|
384 |
-
|
385 |
-
// Iterate over applied coupons and check each of them
|
386 |
-
foreach ($woocommerce->cart->applied_coupons as $code) {
|
387 |
-
|
388 |
-
// Check if coupon code matches our fake coupon code
|
389 |
-
if ($this->getCouponCode() === $code) {
|
390 |
-
|
391 |
-
// Get coupon
|
392 |
-
$coupon = new WC_Coupon($code);
|
393 |
-
|
394 |
-
// Remove coupon if it no longer exists
|
395 |
-
if (!$coupon->is_valid()) {
|
396 |
-
|
397 |
-
// Remove the coupon
|
398 |
-
add_filter('woocommerce_coupons_enabled', array($this, 'woocommerceEnableCoupons'));
|
399 |
-
$this->remove_woocommerce_coupon($code);
|
400 |
-
remove_filter('woocommerce_coupons_enabled', array($this, 'woocommerceEnableCoupons'));
|
401 |
-
}
|
402 |
-
}
|
403 |
-
}
|
404 |
-
}
|
405 |
-
|
406 |
/**
|
407 |
* @return string
|
408 |
*/
|
@@ -538,7 +496,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
538 |
if (!isset($this->rule_sets)) return false;
|
539 |
|
540 |
// Get settings
|
541 |
-
$config = new
|
542 |
$config = $config->getBaseConfig();
|
543 |
if (is_string($config)) $config = json_decode($config, true);
|
544 |
if(isset($config['cart_setup'])){
|
@@ -672,8 +630,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
672 |
}
|
673 |
}
|
674 |
}
|
675 |
-
|
676 |
-
|
677 |
}
|
678 |
return $categories;
|
679 |
}
|
@@ -690,7 +646,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
690 |
$this->calculateCartSubtotal();
|
691 |
$rules = (is_string($rules) ? json_decode($rules, true) : array());
|
692 |
// Simple array helper to re-arrange the structure.
|
693 |
-
|
694 |
foreach ($rules as $index => $rule) {
|
695 |
// Validating the Rules one by one.
|
696 |
if ($this->applyRule($index, $rule, $rules) == false) {
|
@@ -711,7 +667,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
711 |
{
|
712 |
$skipRuleType = array('categories_in');
|
713 |
$availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
|
714 |
-
|
715 |
switch ($index) {
|
716 |
|
717 |
// Cart Subtotal.
|
@@ -779,7 +734,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
779 |
return true;
|
780 |
break;
|
781 |
case 'roles_in':
|
782 |
-
if (get_current_user_id() == 0 || count(array_intersect(
|
783 |
return false;
|
784 |
}
|
785 |
return true;
|
@@ -802,8 +757,8 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
802 |
if(!get_current_user_id()){
|
803 |
$order_id = $this->postData->get('order-received', 0);
|
804 |
if($order_id){
|
805 |
-
$order =
|
806 |
-
$postDataArray['billing_email'] = $order
|
807 |
}
|
808 |
}
|
809 |
if(isset($postDataArray['billing_email']) && $postDataArray['billing_email'] != ''){
|
@@ -853,8 +808,8 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
853 |
if(!get_current_user_id()){
|
854 |
$order_id = $this->postData->get('order-received', 0);
|
855 |
if($order_id){
|
856 |
-
$order =
|
857 |
-
$postDataArray['billing_city'] = $order
|
858 |
}
|
859 |
}
|
860 |
if(isset($postDataArray['billing_city']) && $postDataArray['billing_city'] != ''){
|
@@ -890,20 +845,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
890 |
}
|
891 |
return false;
|
892 |
break;
|
893 |
-
/*case 'categories_atleast_one':
|
894 |
-
if(count($rule)){
|
895 |
-
$w_categories = $this->getCartProductCaregories();
|
896 |
-
if(count($w_categories)){
|
897 |
-
foreach ($rule as $cat){
|
898 |
-
if(in_array($cat, $w_categories)){
|
899 |
-
return true;
|
900 |
-
}
|
901 |
-
}
|
902 |
-
}
|
903 |
-
}
|
904 |
-
return false;
|
905 |
-
break;*/
|
906 |
-
|
907 |
}
|
908 |
|
909 |
}
|
@@ -928,8 +869,8 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
928 |
$totalPurchasedAmount = 0;
|
929 |
if(!empty($customerOrders)){
|
930 |
foreach ($customerOrders as $customerOrder) {
|
931 |
-
$order = wc_get_order($customerOrder->ID);
|
932 |
-
$total = $order
|
933 |
$totalPurchasedAmount += $total;
|
934 |
}
|
935 |
}
|
@@ -1006,6 +947,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1006 |
$ruleSuccess = 0;
|
1007 |
}
|
1008 |
} elseif ($rule_type == 'subtotal_less'){
|
|
|
1009 |
if ($sub_total >= $rule_values) {
|
1010 |
$ruleSuccess = 0;
|
1011 |
}
|
@@ -1048,24 +990,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1048 |
return $emailArray[0];
|
1049 |
}
|
1050 |
|
1051 |
-
/**
|
1052 |
-
* To get product categories
|
1053 |
-
* */
|
1054 |
-
/*public function getCartProductCaregories(){
|
1055 |
-
global $woocommerce;
|
1056 |
-
$product_cat_id = array();
|
1057 |
-
if(count($woocommerce->cart->cart_contents)){
|
1058 |
-
foreach ($woocommerce->cart->cart_contents as $cartItem) {
|
1059 |
-
$terms = get_the_terms( $cartItem['product_id'], 'product_cat' );
|
1060 |
-
if($terms)
|
1061 |
-
foreach ($terms as $term) {
|
1062 |
-
$product_cat_id[] = $term->term_id;
|
1063 |
-
}
|
1064 |
-
}
|
1065 |
-
}
|
1066 |
-
return $product_cat_id;
|
1067 |
-
}*/
|
1068 |
-
|
1069 |
/**
|
1070 |
* Get cart total amount
|
1071 |
*
|
@@ -1078,10 +1002,11 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1078 |
// Iterate over all cart items and
|
1079 |
foreach ($this->cart_items as $cart_item_key => $cart_item) {
|
1080 |
$quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1081 |
-
$cart_subtotal += $cart_item['data']
|
1082 |
}
|
1083 |
|
1084 |
$this->sub_total = (float)$cart_subtotal;
|
|
|
1085 |
}
|
1086 |
|
1087 |
public function calculate_conditional_subtotal($conditions) {
|
@@ -1094,7 +1019,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1094 |
|
1095 |
//total should be specific to the products from certan categories
|
1096 |
$quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1097 |
-
$cart_subtotal += $cart_item['data']
|
1098 |
}
|
1099 |
|
1100 |
}
|
@@ -1104,12 +1029,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1104 |
}
|
1105 |
|
1106 |
public function does_item_belong_to_category($categories, $product) {
|
1107 |
-
$cat_id =
|
1108 |
-
$terms = get_the_terms ( $product->id, 'product_cat' );
|
1109 |
-
if(!empty($terms))
|
1110 |
-
foreach ( $terms as $term ) {
|
1111 |
-
$cat_id[] = $term->term_id;
|
1112 |
-
}
|
1113 |
$result = array_intersect($categories, $cat_id);
|
1114 |
if(is_array($result) && count($result) > 0) {
|
1115 |
return true;
|
@@ -1117,7 +1037,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1117 |
return false;
|
1118 |
}
|
1119 |
|
1120 |
-
|
1121 |
/**
|
1122 |
* To Sum the Cart Item's Qty.
|
1123 |
*
|
@@ -1159,4 +1078,4 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
1159 |
}
|
1160 |
|
1161 |
}
|
1162 |
-
}
|
4 |
include_once(WOO_DISCOUNT_DIR . '/includes/discount-base.php');
|
5 |
|
6 |
/**
|
7 |
+
* Class FlycartWooDiscountRulesCartRules
|
8 |
*/
|
9 |
+
if (!class_exists('FlycartWooDiscountRulesCartRules')) {
|
10 |
+
class FlycartWooDiscountRulesCartRules
|
11 |
{
|
12 |
/**
|
13 |
* @var string
|
67 |
public $postData;
|
68 |
|
69 |
/**
|
70 |
+
* FlycartWooDiscountRulesCartRules constructor.
|
71 |
*/
|
72 |
public function __construct()
|
73 |
{
|
83 |
|
84 |
// Update Coupon Code
|
85 |
$this->coupon_code = strtolower($this->getCouponCode());
|
|
|
|
|
86 |
}
|
87 |
|
88 |
/**
|
95 |
{
|
96 |
foreach ($request as $index => $value) {
|
97 |
if ($index !== 'discount_rule') {
|
98 |
+
$request[$index] = FlycartWooDiscountRulesGeneralHelper::makeString($value);
|
|
|
99 |
}
|
100 |
}
|
101 |
|
147 |
$id = wp_insert_post($post);
|
148 |
$request['status'] = 'publish';
|
149 |
}
|
|
|
150 |
foreach ($request['discount_rule'] as $index => $value) {
|
151 |
+
$request['discount_rule'][$index] = FlycartWooDiscountRulesGeneralHelper::makeString($value);
|
152 |
}
|
153 |
|
154 |
if (isset($request['discount_rule'])) $request['discount_rule'] = json_encode($request['discount_rule']);
|
235 |
}
|
236 |
}
|
237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
/**
|
239 |
* To Make record of discount changes.
|
240 |
*
|
273 |
'id' => 321123 . rand(2, 9),
|
274 |
'type' => 'fixed_cart',
|
275 |
'amount' => $this->discount_total,
|
276 |
+
'individual_use' => false,
|
277 |
'product_ids' => array(),
|
278 |
'exclude_product_ids' => array(),
|
279 |
'usage_limit' => '',
|
282 |
'usage_count' => '',
|
283 |
'expiry_date' => '',
|
284 |
'apply_before_tax' => 'yes',
|
285 |
+
'free_shipping' => false,
|
286 |
'product_categories' => array(),
|
287 |
'exclude_product_categories' => array(),
|
288 |
+
'exclude_sale_items' => false,
|
289 |
'minimum_amount' => '',
|
290 |
'maximum_amount' => '',
|
291 |
'customer_email' => '',
|
302 |
*/
|
303 |
public function getCouponCode()
|
304 |
{
|
305 |
+
$config = new FlycartWooDiscountBase();
|
306 |
$config = $config->getBaseConfig();
|
307 |
|
308 |
if (is_string($config)) $config = json_decode($config, true);
|
328 |
// 'newyear' is a temporary coupon for validation.
|
329 |
$coupon_code = apply_filters('woocommerce_coupon_code', $this->coupon_code);
|
330 |
// Getting New Instance with the Coupon Code.
|
331 |
+
$the_coupon = FlycartWoocommerceCoupon::wc_get_coupon($coupon_code);
|
332 |
// Validating the Coupon as Valid and discount status.
|
333 |
if ($the_coupon->is_valid() && !$woocommerce->cart->has_discount($coupon_code)) {
|
334 |
|
335 |
// Do not apply coupon with individual use coupon already applied
|
336 |
if ($woocommerce->cart->applied_coupons) {
|
337 |
foreach ($woocommerce->cart->applied_coupons as $code) {
|
338 |
+
$coupon = FlycartWoocommerceCoupon::wc_get_coupon($code);
|
339 |
+
if (FlycartWoocommerceCoupon::get_individual_use($coupon) == true) {
|
|
|
340 |
return false;
|
341 |
}
|
342 |
}
|
361 |
WC()->session->set('woo_coupon_removed', $coupon);
|
362 |
}
|
363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
/**
|
365 |
* @return string
|
366 |
*/
|
496 |
if (!isset($this->rule_sets)) return false;
|
497 |
|
498 |
// Get settings
|
499 |
+
$config = new FlycartWooDiscountBase();
|
500 |
$config = $config->getBaseConfig();
|
501 |
if (is_string($config)) $config = json_decode($config, true);
|
502 |
if(isset($config['cart_setup'])){
|
630 |
}
|
631 |
}
|
632 |
}
|
|
|
|
|
633 |
}
|
634 |
return $categories;
|
635 |
}
|
646 |
$this->calculateCartSubtotal();
|
647 |
$rules = (is_string($rules) ? json_decode($rules, true) : array());
|
648 |
// Simple array helper to re-arrange the structure.
|
649 |
+
FlycartWooDiscountRulesGeneralHelper::reArrangeArray($rules);
|
650 |
foreach ($rules as $index => $rule) {
|
651 |
// Validating the Rules one by one.
|
652 |
if ($this->applyRule($index, $rule, $rules) == false) {
|
667 |
{
|
668 |
$skipRuleType = array('categories_in');
|
669 |
$availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
|
|
|
670 |
switch ($index) {
|
671 |
|
672 |
// Cart Subtotal.
|
734 |
return true;
|
735 |
break;
|
736 |
case 'roles_in':
|
737 |
+
if (get_current_user_id() == 0 || count(array_intersect(FlycartWooDiscountRulesGeneralHelper::getCurrentUserRoles(), $rule)) == 0) {
|
738 |
return false;
|
739 |
}
|
740 |
return true;
|
757 |
if(!get_current_user_id()){
|
758 |
$order_id = $this->postData->get('order-received', 0);
|
759 |
if($order_id){
|
760 |
+
$order = FlycartWoocommerceOrder::wc_get_order($order_id);
|
761 |
+
$postDataArray['billing_email'] = FlycartWoocommerceOrder::get_billing_email($order);
|
762 |
}
|
763 |
}
|
764 |
if(isset($postDataArray['billing_email']) && $postDataArray['billing_email'] != ''){
|
808 |
if(!get_current_user_id()){
|
809 |
$order_id = $this->postData->get('order-received', 0);
|
810 |
if($order_id){
|
811 |
+
$order = FlycartWoocommerceOrder::wc_get_order($order_id);
|
812 |
+
$postDataArray['billing_city'] = FlycartWoocommerceOrder::get_billing_city($order);
|
813 |
}
|
814 |
}
|
815 |
if(isset($postDataArray['billing_city']) && $postDataArray['billing_city'] != ''){
|
845 |
}
|
846 |
return false;
|
847 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
848 |
}
|
849 |
|
850 |
}
|
869 |
$totalPurchasedAmount = 0;
|
870 |
if(!empty($customerOrders)){
|
871 |
foreach ($customerOrders as $customerOrder) {
|
872 |
+
$order = FlycartWoocommerceOrder::wc_get_order($customerOrder->ID);
|
873 |
+
$total = FlycartWoocommerceOrder::get_total($order);
|
874 |
$totalPurchasedAmount += $total;
|
875 |
}
|
876 |
}
|
947 |
$ruleSuccess = 0;
|
948 |
}
|
949 |
} elseif ($rule_type == 'subtotal_less'){
|
950 |
+
|
951 |
if ($sub_total >= $rule_values) {
|
952 |
$ruleSuccess = 0;
|
953 |
}
|
990 |
return $emailArray[0];
|
991 |
}
|
992 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
993 |
/**
|
994 |
* Get cart total amount
|
995 |
*
|
1002 |
// Iterate over all cart items and
|
1003 |
foreach ($this->cart_items as $cart_item_key => $cart_item) {
|
1004 |
$quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1005 |
+
$cart_subtotal += FlycartWoocommerceProduct::get_price($cart_item['data']) * $quantity;
|
1006 |
}
|
1007 |
|
1008 |
$this->sub_total = (float)$cart_subtotal;
|
1009 |
+
|
1010 |
}
|
1011 |
|
1012 |
public function calculate_conditional_subtotal($conditions) {
|
1019 |
|
1020 |
//total should be specific to the products from certan categories
|
1021 |
$quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
|
1022 |
+
$cart_subtotal += FlycartWoocommerceProduct::get_price($cart_item['data']) * $quantity;
|
1023 |
}
|
1024 |
|
1025 |
}
|
1029 |
}
|
1030 |
|
1031 |
public function does_item_belong_to_category($categories, $product) {
|
1032 |
+
$cat_id = FlycartWoocommerceProduct::get_category_ids($product);
|
|
|
|
|
|
|
|
|
|
|
1033 |
$result = array_intersect($categories, $cat_id);
|
1034 |
if(is_array($result) && count($result) > 0) {
|
1035 |
return true;
|
1037 |
return false;
|
1038 |
}
|
1039 |
|
|
|
1040 |
/**
|
1041 |
* To Sum the Cart Item's Qty.
|
1042 |
*
|
1078 |
}
|
1079 |
|
1080 |
}
|
1081 |
+
}
|
includes/discount-base.php
CHANGED
@@ -4,10 +4,10 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
|
4 |
global $woocommerce;
|
5 |
|
6 |
/**
|
7 |
-
* Class
|
8 |
*/
|
9 |
-
if (!class_exists('
|
10 |
-
class
|
11 |
{
|
12 |
/**
|
13 |
* @var string
|
@@ -25,12 +25,9 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
25 |
private $instance = array();
|
26 |
|
27 |
/**
|
28 |
-
*
|
29 |
*/
|
30 |
-
public function __construct()
|
31 |
-
{
|
32 |
-
|
33 |
-
}
|
34 |
|
35 |
/**
|
36 |
* Singleton Instance maker.
|
@@ -60,8 +57,8 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
60 |
{
|
61 |
global $woocommerce;
|
62 |
|
63 |
-
$price_discount = $this->getInstance('
|
64 |
-
$cart_discount = $this->getInstance('
|
65 |
|
66 |
$price_discount->analyse($woocommerce);
|
67 |
$cart_discount->analyse($woocommerce);
|
@@ -185,7 +182,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
185 |
if (!isset($request['data'])) return false;
|
186 |
parse_str($request['data'], $params);
|
187 |
|
188 |
-
$pricing_rule = $this->getInstance('
|
189 |
$pricing_rule->save($params);
|
190 |
die();
|
191 |
}
|
@@ -205,7 +202,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
205 |
if (!isset($request['data'])) return false;
|
206 |
parse_str($request['data'], $params);
|
207 |
$this->parseFormWithRules($params, true);
|
208 |
-
$pricing_rule = $this->getInstance('
|
209 |
$pricing_rule->save($params);
|
210 |
die();
|
211 |
}
|
@@ -301,13 +298,13 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
301 |
$params['show_draft'] = 0;
|
302 |
}
|
303 |
foreach ($params as $index => $item) {
|
304 |
-
// $params[$index] =
|
305 |
$params[$index] = $item;
|
306 |
}
|
307 |
$params = json_encode($params);
|
308 |
}
|
309 |
// else {
|
310 |
-
// $params =
|
311 |
// }
|
312 |
|
313 |
if (get_option($this->default_option)) {
|
@@ -351,11 +348,11 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
351 |
switch ($form) {
|
352 |
case 'pricing_rules':
|
353 |
die(123);
|
354 |
-
$pricing_rule = $this->getInstance('
|
355 |
$pricing_rule->save($request);
|
356 |
break;
|
357 |
case 'cart_rules':
|
358 |
-
$cart_rules = $this->getInstance('
|
359 |
$cart_rules->save($request);
|
360 |
break;
|
361 |
case 'settings':
|
@@ -422,11 +419,10 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
422 |
$this->checkSubmission($request);
|
423 |
|
424 |
// Adding Plugin Page Script
|
425 |
-
|
426 |
-
|
427 |
-
}
|
428 |
// Loading Instance.
|
429 |
-
$generalHelper = $this->getInstance('
|
430 |
// Sanity Check.
|
431 |
if (!$generalHelper) return;
|
432 |
// Getting Active Tab.
|
@@ -474,18 +470,18 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
474 |
$postData = \FlycartInput\FInput::getInstance();
|
475 |
$request = $postData->getArray();
|
476 |
|
477 |
-
$helper = new
|
478 |
$isPro = $helper->checkPluginState();
|
479 |
|
480 |
switch ($type) {
|
481 |
// Managing Price Rules View.
|
482 |
case 'pricing-rules':
|
483 |
-
$pricing_rule = $this->getInstance('
|
484 |
$data = $pricing_rule->getRules();
|
485 |
break;
|
486 |
// Managing Cart Rules View.
|
487 |
case 'cart-rules':
|
488 |
-
$cart_rule = $this->getInstance('
|
489 |
$data = $cart_rule->getRules();
|
490 |
break;
|
491 |
// Managing View of Settings.
|
@@ -498,7 +494,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
498 |
$data = new stdClass();
|
499 |
$data->form = 'pricing_rules_save';
|
500 |
if (!$isPro) {
|
501 |
-
$pricing_rule = $this->getInstance('
|
502 |
$data = $pricing_rule->getRules();
|
503 |
if (count($data) >= 3) die('You are restricted to process this action.');
|
504 |
}
|
@@ -512,7 +508,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
512 |
if (isset($request['view'])) {
|
513 |
$view = $request['view'];
|
514 |
}
|
515 |
-
$html = $this->getInstance('
|
516 |
$out = $html->view($type, $view);
|
517 |
if (isset($out) && !empty($out)) {
|
518 |
$data = $out;
|
@@ -529,13 +525,13 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
529 |
} else {
|
530 |
|
531 |
if (!$isPro) {
|
532 |
-
$cart_rule = $this->getInstance('
|
533 |
$total_record = $cart_rule->getRules(true);
|
534 |
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
535 |
}
|
536 |
}
|
537 |
|
538 |
-
$html = $this->getInstance('
|
539 |
$out = $html->view($type, $view);
|
540 |
if (isset($out) && !empty($out)) {
|
541 |
$data[] = $out;
|
@@ -544,7 +540,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
544 |
// Managing View of Cart Rules.
|
545 |
case 'cart-rules-new':
|
546 |
if (!$isPro) {
|
547 |
-
$cart_rule = $this->getInstance('
|
548 |
$total_record = $cart_rule->getRules(true);
|
549 |
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
550 |
}
|
@@ -586,5 +582,56 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
586 |
|
587 |
}
|
588 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
589 |
}
|
590 |
}
|
4 |
global $woocommerce;
|
5 |
|
6 |
/**
|
7 |
+
* Class FlycartWooDiscountBase
|
8 |
*/
|
9 |
+
if (!class_exists('FlycartWooDiscountBase')) {
|
10 |
+
class FlycartWooDiscountBase
|
11 |
{
|
12 |
/**
|
13 |
* @var string
|
25 |
private $instance = array();
|
26 |
|
27 |
/**
|
28 |
+
* FlycartWooDiscountBase constructor.
|
29 |
*/
|
30 |
+
public function __construct() {}
|
|
|
|
|
|
|
31 |
|
32 |
/**
|
33 |
* Singleton Instance maker.
|
57 |
{
|
58 |
global $woocommerce;
|
59 |
|
60 |
+
$price_discount = $this->getInstance('FlycartWooDiscountRulesPricingRules');
|
61 |
+
$cart_discount = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
62 |
|
63 |
$price_discount->analyse($woocommerce);
|
64 |
$cart_discount->analyse($woocommerce);
|
182 |
if (!isset($request['data'])) return false;
|
183 |
parse_str($request['data'], $params);
|
184 |
|
185 |
+
$pricing_rule = $this->getInstance('FlycartWooDiscountRulesPricingRules');
|
186 |
$pricing_rule->save($params);
|
187 |
die();
|
188 |
}
|
202 |
if (!isset($request['data'])) return false;
|
203 |
parse_str($request['data'], $params);
|
204 |
$this->parseFormWithRules($params, true);
|
205 |
+
$pricing_rule = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
206 |
$pricing_rule->save($params);
|
207 |
die();
|
208 |
}
|
298 |
$params['show_draft'] = 0;
|
299 |
}
|
300 |
foreach ($params as $index => $item) {
|
301 |
+
// $params[$index] = FlycartWooDiscountRulesGeneralHelper::makeString($item);
|
302 |
$params[$index] = $item;
|
303 |
}
|
304 |
$params = json_encode($params);
|
305 |
}
|
306 |
// else {
|
307 |
+
// $params = FlycartWooDiscountRulesGeneralHelper::makeString($params);
|
308 |
// }
|
309 |
|
310 |
if (get_option($this->default_option)) {
|
348 |
switch ($form) {
|
349 |
case 'pricing_rules':
|
350 |
die(123);
|
351 |
+
$pricing_rule = $this->getInstance('FlycartWooDiscountRulesPricingRules');
|
352 |
$pricing_rule->save($request);
|
353 |
break;
|
354 |
case 'cart_rules':
|
355 |
+
$cart_rules = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
356 |
$cart_rules->save($request);
|
357 |
break;
|
358 |
case 'settings':
|
419 |
$this->checkSubmission($request);
|
420 |
|
421 |
// Adding Plugin Page Script
|
422 |
+
$this->woo_discount_adminPageScript();
|
423 |
+
|
|
|
424 |
// Loading Instance.
|
425 |
+
$generalHelper = $this->getInstance('FlycartWooDiscountRulesGeneralHelper');
|
426 |
// Sanity Check.
|
427 |
if (!$generalHelper) return;
|
428 |
// Getting Active Tab.
|
470 |
$postData = \FlycartInput\FInput::getInstance();
|
471 |
$request = $postData->getArray();
|
472 |
|
473 |
+
$helper = new FlycartWooDiscountRulesGeneralHelper();
|
474 |
$isPro = $helper->checkPluginState();
|
475 |
|
476 |
switch ($type) {
|
477 |
// Managing Price Rules View.
|
478 |
case 'pricing-rules':
|
479 |
+
$pricing_rule = $this->getInstance('FlycartWooDiscountRulesPricingRules');
|
480 |
$data = $pricing_rule->getRules();
|
481 |
break;
|
482 |
// Managing Cart Rules View.
|
483 |
case 'cart-rules':
|
484 |
+
$cart_rule = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
485 |
$data = $cart_rule->getRules();
|
486 |
break;
|
487 |
// Managing View of Settings.
|
494 |
$data = new stdClass();
|
495 |
$data->form = 'pricing_rules_save';
|
496 |
if (!$isPro) {
|
497 |
+
$pricing_rule = $this->getInstance('FlycartWooDiscountRulesPricingRules');
|
498 |
$data = $pricing_rule->getRules();
|
499 |
if (count($data) >= 3) die('You are restricted to process this action.');
|
500 |
}
|
508 |
if (isset($request['view'])) {
|
509 |
$view = $request['view'];
|
510 |
}
|
511 |
+
$html = $this->getInstance('FlycartWooDiscountRulesPricingRules');
|
512 |
$out = $html->view($type, $view);
|
513 |
if (isset($out) && !empty($out)) {
|
514 |
$data = $out;
|
525 |
} else {
|
526 |
|
527 |
if (!$isPro) {
|
528 |
+
$cart_rule = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
529 |
$total_record = $cart_rule->getRules(true);
|
530 |
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
531 |
}
|
532 |
}
|
533 |
|
534 |
+
$html = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
535 |
$out = $html->view($type, $view);
|
536 |
if (isset($out) && !empty($out)) {
|
537 |
$data[] = $out;
|
540 |
// Managing View of Cart Rules.
|
541 |
case 'cart-rules-new':
|
542 |
if (!$isPro) {
|
543 |
+
$cart_rule = $this->getInstance('FlycartWooDiscountRulesCartRules');
|
544 |
$total_record = $cart_rule->getRules(true);
|
545 |
if ($total_record >= 3) wp_die('You are restricted to process this action.');
|
546 |
}
|
582 |
|
583 |
}
|
584 |
|
585 |
+
/**
|
586 |
+
* Adding Admin Page Script.
|
587 |
+
*/
|
588 |
+
function woo_discount_adminPageScript()
|
589 |
+
{
|
590 |
+
$status = false;
|
591 |
+
$postData = \FlycartInput\FInput::getInstance();
|
592 |
+
// Plugin scripts should run only in plugin page.
|
593 |
+
if (is_admin()) {
|
594 |
+
if ($postData->get('page', false) == 'woo_discount_rules') {
|
595 |
+
$status = true;
|
596 |
+
}
|
597 |
+
// By Default, the landing page also can use this script.
|
598 |
+
} elseif (!is_admin()) {
|
599 |
+
// $status = true;
|
600 |
+
}
|
601 |
+
|
602 |
+
if ($status) {
|
603 |
+
wp_register_style('woo_discount_style', WOO_DISCOUNT_URI . '/assets/css/style.css', array(), WOO_DISCOUNT_VERSION);
|
604 |
+
wp_enqueue_style('woo_discount_style');
|
605 |
+
|
606 |
+
wp_register_style('woo_discount_style_custom', WOO_DISCOUNT_URI . '/assets/css/custom.css', array(), WOO_DISCOUNT_VERSION);
|
607 |
+
wp_enqueue_style('woo_discount_style_custom');
|
608 |
+
|
609 |
+
wp_register_style('woo_discount_style_tab', WOO_DISCOUNT_URI . '/assets/css/tabbablePanel.css', array(), WOO_DISCOUNT_VERSION);
|
610 |
+
wp_enqueue_style('woo_discount_style_tab');
|
611 |
+
|
612 |
+
// For Implementing Select Picker Library.
|
613 |
+
wp_register_style('woo_discount_style_select', WOO_DISCOUNT_URI . '/assets/css/bootstrap.select.min.css', array(), WOO_DISCOUNT_VERSION);
|
614 |
+
wp_enqueue_style('woo_discount_style_select');
|
615 |
+
|
616 |
+
wp_enqueue_script('woo_discount_script_select', WOO_DISCOUNT_URI . '/assets/js/bootstrap.select.min.js', array(), WOO_DISCOUNT_VERSION);
|
617 |
+
|
618 |
+
wp_register_style('woo_discount_bootstrap', WOO_DISCOUNT_URI . '/assets/css/bootstrap.min.css', array(), WOO_DISCOUNT_VERSION);
|
619 |
+
wp_enqueue_style('woo_discount_bootstrap');
|
620 |
+
|
621 |
+
wp_register_script('woo_discount_jquery_ui_js_2', WOO_DISCOUNT_URI . '/assets/js/bootstrap.min.js', array(), WOO_DISCOUNT_VERSION);
|
622 |
+
wp_enqueue_script('woo_discount_jquery_ui_js_2');
|
623 |
+
|
624 |
+
wp_register_style('woo_discount_jquery_ui_css', WOO_DISCOUNT_URI . '/assets/css/jquery-ui.css', array(), WOO_DISCOUNT_VERSION);
|
625 |
+
wp_enqueue_style('woo_discount_jquery_ui_css');
|
626 |
+
|
627 |
+
wp_enqueue_script('jquery');
|
628 |
+
wp_enqueue_script('jquery-ui-core');
|
629 |
+
wp_enqueue_script('jquery-ui-datepicker');
|
630 |
+
|
631 |
+
wp_enqueue_script('woo_discount_script', WOO_DISCOUNT_URI . '/assets/js/app.js', array(), WOO_DISCOUNT_VERSION);
|
632 |
+
|
633 |
+
}
|
634 |
+
}
|
635 |
+
|
636 |
}
|
637 |
}
|
includes/pricing-productbased.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
/**
|
4 |
-
* Class
|
5 |
*/
|
6 |
-
if (!class_exists('
|
7 |
-
class
|
8 |
{
|
9 |
/**
|
10 |
* Verify Quantity
|
@@ -35,7 +35,7 @@ if (!class_exists('WooDiscountRulesPrice_ProductBased')) {
|
|
35 |
break;
|
36 |
}
|
37 |
|
38 |
-
return
|
39 |
}
|
40 |
|
41 |
/**
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
/**
|
4 |
+
* Class FlycartWooDiscountRulesPriceProductBased
|
5 |
*/
|
6 |
+
if (!class_exists('FlycartWooDiscountRulesPriceProductBased')) {
|
7 |
+
class FlycartWooDiscountRulesPriceProductBased
|
8 |
{
|
9 |
/**
|
10 |
* Verify Quantity
|
35 |
break;
|
36 |
}
|
37 |
|
38 |
+
return FlycartWooDiscountRulesPriceProductBased::verifyBuyTypeWithQuantityMatched($buy_type, $quantityMatched);
|
39 |
}
|
40 |
|
41 |
/**
|
includes/pricing-rules-3.php
DELETED
@@ -1,1810 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
-
include_once(WOO_DISCOUNT_DIR . '/helper/general-helper-3.php');
|
4 |
-
include_once(WOO_DISCOUNT_DIR . '/includes/pricing-productbased.php');
|
5 |
-
|
6 |
-
/**
|
7 |
-
* Class woo_dicount_rules_pricingRules
|
8 |
-
*/
|
9 |
-
if (!class_exists('woo_dicount_rules_pricingRules')) {
|
10 |
-
class woo_dicount_rules_pricingRules
|
11 |
-
{
|
12 |
-
/**
|
13 |
-
* @var string
|
14 |
-
*/
|
15 |
-
private $option_name = 'woo_discount_price_option';
|
16 |
-
|
17 |
-
/**
|
18 |
-
* @var string
|
19 |
-
*/
|
20 |
-
public $post_type = 'woo_discount';
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @var bool
|
24 |
-
*/
|
25 |
-
public $discount_applied = false;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @var
|
29 |
-
*/
|
30 |
-
private $rules;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* @var
|
34 |
-
*/
|
35 |
-
public $rule_sets;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* @var
|
39 |
-
*/
|
40 |
-
public $matched_sets;
|
41 |
-
|
42 |
-
/**
|
43 |
-
* @var
|
44 |
-
*/
|
45 |
-
public $baseConfig;
|
46 |
-
|
47 |
-
/**
|
48 |
-
* @var
|
49 |
-
*/
|
50 |
-
public $apply_to;
|
51 |
-
|
52 |
-
/**
|
53 |
-
* @var string
|
54 |
-
*/
|
55 |
-
public $default_option = 'woo-discount-config';
|
56 |
-
|
57 |
-
public $postData;
|
58 |
-
|
59 |
-
/**
|
60 |
-
* woo_dicount_rules_pricingRules constructor.
|
61 |
-
*/
|
62 |
-
public function __construct()
|
63 |
-
{
|
64 |
-
$this->updateBaseConfig();
|
65 |
-
$this->postData = \FlycartInput\FInput::getInstance();
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Update the Base config with live.
|
70 |
-
*/
|
71 |
-
public function updateBaseConfig()
|
72 |
-
{
|
73 |
-
$base = new woo_dicount_rules_WooDiscountBase();
|
74 |
-
$base = $base->getBaseConfig();
|
75 |
-
if (is_string($base)) $base = json_decode($base, true);
|
76 |
-
$this->baseConfig = $base;
|
77 |
-
$this->apply_to = (isset($base_config['price_setup']) ? $base_config['price_setup'] : 'all');
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Saving the Price Rule Set.
|
82 |
-
*
|
83 |
-
* @param $request
|
84 |
-
* @return bool
|
85 |
-
*/
|
86 |
-
public function save($request)
|
87 |
-
{
|
88 |
-
$id = (isset($request['rule_id']) ? $request['rule_id'] : false);
|
89 |
-
|
90 |
-
$id = intval($id);
|
91 |
-
if (!$id && $id != 0) return false;
|
92 |
-
|
93 |
-
$title = (isset($request['rule_name']) ? $request['rule_name'] : 'New');
|
94 |
-
$slug = str_replace(' ', '-', strtolower($title));
|
95 |
-
|
96 |
-
// To Lowercase.
|
97 |
-
$slug = strtolower($slug);
|
98 |
-
|
99 |
-
// Encoding String with Space.
|
100 |
-
$slug = str_replace(' ', '-', $slug);
|
101 |
-
|
102 |
-
if ($id) {
|
103 |
-
$post = array(
|
104 |
-
'ID' => $id,
|
105 |
-
'post_title' => $title,
|
106 |
-
'post_name' => $slug,
|
107 |
-
'post_content' => 'New Rule',
|
108 |
-
'post_type' => $this->post_type,
|
109 |
-
'post_status' => 'publish'
|
110 |
-
);
|
111 |
-
wp_update_post($post);
|
112 |
-
} else {
|
113 |
-
$post = array(
|
114 |
-
'post_title' => $title,
|
115 |
-
'post_name' => $slug,
|
116 |
-
'post_content' => 'New Rule',
|
117 |
-
'post_type' => $this->post_type,
|
118 |
-
'post_status' => 'publish'
|
119 |
-
);
|
120 |
-
$id = wp_insert_post($post);
|
121 |
-
}
|
122 |
-
|
123 |
-
$form = array(
|
124 |
-
'rule_name',
|
125 |
-
'rule_descr',
|
126 |
-
'rule_method',
|
127 |
-
'qty_based_on',
|
128 |
-
'date_from',
|
129 |
-
'date_to',
|
130 |
-
'apply_to',
|
131 |
-
'customer',
|
132 |
-
'min_qty',
|
133 |
-
'max_qty',
|
134 |
-
'discount_type',
|
135 |
-
'to_discount',
|
136 |
-
'status',
|
137 |
-
'customer',
|
138 |
-
'discount_range',
|
139 |
-
'product_based_condition',
|
140 |
-
'product_based_discount',
|
141 |
-
'rule_order'
|
142 |
-
);
|
143 |
-
|
144 |
-
//----------------------------------------------------------------------------------------------------------
|
145 |
-
// Manage Products with it's ID or Category.
|
146 |
-
$apply_to = 'all_products';
|
147 |
-
|
148 |
-
if (isset($request['apply_to'])) $apply_to = $request['apply_to'];
|
149 |
-
|
150 |
-
if ($apply_to == 'specific_category') {
|
151 |
-
$apply_to = 'category_to_apply';
|
152 |
-
if(isset($request['is_cumulative']) && $request['is_cumulative'] == 1){
|
153 |
-
$request['is_cumulative'] = 1;
|
154 |
-
} else {
|
155 |
-
$request['is_cumulative'] = 0;
|
156 |
-
}
|
157 |
-
$form[] = 'is_cumulative';
|
158 |
-
|
159 |
-
if(isset($request['apply_child_categories']) && $request['apply_child_categories'] == 1){
|
160 |
-
$request['apply_child_categories'] = 1;
|
161 |
-
} else {
|
162 |
-
$request['apply_child_categories'] = 0;
|
163 |
-
}
|
164 |
-
$form[] = 'apply_child_categories';
|
165 |
-
|
166 |
-
} elseif ($apply_to == 'specific_products') {
|
167 |
-
$apply_to = 'product_to_apply';
|
168 |
-
}
|
169 |
-
$form[] = $apply_to;
|
170 |
-
|
171 |
-
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
172 |
-
//----------------------------------------------------------------------------------------------------------
|
173 |
-
|
174 |
-
// Manage Users.
|
175 |
-
$apply_to = 'all';
|
176 |
-
|
177 |
-
if (isset($request['customer'])) $apply_to = $request['customer'];
|
178 |
-
|
179 |
-
if ($apply_to == 'only_given') {
|
180 |
-
$apply_to = 'users_to_apply';
|
181 |
-
}
|
182 |
-
$form[] = $apply_to;
|
183 |
-
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
184 |
-
|
185 |
-
$form[] = 'user_roles_to_apply';
|
186 |
-
if (!isset($request['user_roles_to_apply'])) $request['user_roles_to_apply'] = array();
|
187 |
-
$request['user_roles_to_apply'] = json_encode($request['user_roles_to_apply']);
|
188 |
-
|
189 |
-
$based_on_purchase_history = 0;
|
190 |
-
if (isset($request['based_on_purchase_history'])) $based_on_purchase_history = $request['based_on_purchase_history'];
|
191 |
-
$request['based_on_purchase_history'] = $based_on_purchase_history;
|
192 |
-
$form[] = 'based_on_purchase_history';
|
193 |
-
if($based_on_purchase_history){
|
194 |
-
$form[] = 'purchased_history_amount';
|
195 |
-
$form[] = 'purchase_history_status_list';
|
196 |
-
if (isset($request['purchase_history_status_list'])) $request['purchase_history_status_list'] = json_encode($request['purchase_history_status_list']);
|
197 |
-
else $request['purchase_history_status_list'] = json_encode(array('wc-completed'));
|
198 |
-
}
|
199 |
-
|
200 |
-
//----------------------------------------------------------------------------------------------------------
|
201 |
-
|
202 |
-
// Manage list of Discount Ranges.
|
203 |
-
if (isset($request['discount_range'])) {
|
204 |
-
|
205 |
-
foreach ($request['discount_range'] as $index => $value) {
|
206 |
-
$request['discount_range'][$index] = woo_dicount_rules_generalHelper::makeString($value);
|
207 |
-
$request['discount_range'][$index]['title'] = isset($request['rule_name']) ? $request['rule_name'] : '';
|
208 |
-
|
209 |
-
}
|
210 |
-
|
211 |
-
$request['discount_range'] = json_encode($request['discount_range']);
|
212 |
-
} else {
|
213 |
-
// Reset the Discount Range, if its empty.
|
214 |
-
$request['discount_range'] = '';
|
215 |
-
}
|
216 |
-
if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
|
217 |
-
$request['product_based_condition'] = json_encode($request['product_based_condition']);
|
218 |
-
$request['product_based_discount'] = json_encode($request['product_based_discount']);
|
219 |
-
} else {
|
220 |
-
$request['product_based_condition'] = '{}';
|
221 |
-
$request['product_based_discount'] = '{}';
|
222 |
-
}
|
223 |
-
|
224 |
-
$request['status'] = 'publish';
|
225 |
-
|
226 |
-
if (is_null($id) || !isset($id)) return false;
|
227 |
-
|
228 |
-
foreach ($request as $index => $value) {
|
229 |
-
if (in_array($index, $form)) {
|
230 |
-
if (get_post_meta($id, $index)) {
|
231 |
-
update_post_meta($id, $index, $value);
|
232 |
-
} else {
|
233 |
-
add_post_meta($id, $index, $value);
|
234 |
-
}
|
235 |
-
}
|
236 |
-
}
|
237 |
-
}
|
238 |
-
|
239 |
-
/**
|
240 |
-
* Load View with Specif post id.
|
241 |
-
*
|
242 |
-
* @param $option
|
243 |
-
* @param integer $id Post ID.
|
244 |
-
* @return string mixed response.
|
245 |
-
*/
|
246 |
-
public function view($option, $id)
|
247 |
-
{
|
248 |
-
$id = intval($id);
|
249 |
-
if (!$id) return false;
|
250 |
-
$post = get_post($id, 'OBJECT');
|
251 |
-
if (isset($post)) {
|
252 |
-
if (isset($post->ID)) {
|
253 |
-
$post->meta = get_post_meta($post->ID);
|
254 |
-
}
|
255 |
-
}
|
256 |
-
return $post;
|
257 |
-
}
|
258 |
-
|
259 |
-
// -------------------------------------------------RULE IMPLEMENTATION---------------------------------------------
|
260 |
-
|
261 |
-
/**
|
262 |
-
* To Analyzing the Pricing Rules to Apply the Discount in terms of price.
|
263 |
-
*/
|
264 |
-
public function analyse($woocommerce)
|
265 |
-
{
|
266 |
-
$this->organizeRules();
|
267 |
-
$this->applyRules();
|
268 |
-
$this->initAdjustment();
|
269 |
-
}
|
270 |
-
|
271 |
-
/**
|
272 |
-
* To Organizing the rules to make possible sets.
|
273 |
-
*/
|
274 |
-
public function organizeRules()
|
275 |
-
{
|
276 |
-
// Loads the Rules to Global.
|
277 |
-
$this->getRules();
|
278 |
-
// Validate and Re-Assign the Rules.
|
279 |
-
$this->filterRules();
|
280 |
-
}
|
281 |
-
|
282 |
-
/**
|
283 |
-
* To Get Set of Rules.
|
284 |
-
*
|
285 |
-
* @return mixed
|
286 |
-
*/
|
287 |
-
public function getRules($onlyCount = false)
|
288 |
-
{
|
289 |
-
$posts = get_posts(array('post_type' => $this->post_type, 'numberposts' => '-1'));
|
290 |
-
if ($onlyCount) return count($posts);
|
291 |
-
if (isset($posts) && count($posts) > 0) {
|
292 |
-
foreach ($posts as $index => $item) {
|
293 |
-
$posts[$index]->meta = get_post_meta($posts[$index]->ID);
|
294 |
-
}
|
295 |
-
$this->rules = $posts;
|
296 |
-
}
|
297 |
-
return $posts;
|
298 |
-
}
|
299 |
-
|
300 |
-
/**
|
301 |
-
* To Updating the Log of Implemented Price Discounts.
|
302 |
-
*
|
303 |
-
* @return bool
|
304 |
-
*/
|
305 |
-
public function makeLog()
|
306 |
-
{
|
307 |
-
if (is_null($this->matched_sets)) return false;
|
308 |
-
|
309 |
-
$discount_log = array(
|
310 |
-
'line_discount' => $this->matched_sets,
|
311 |
-
);
|
312 |
-
WC()->session->set('woo_price_discount', json_encode($discount_log));
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* @return array
|
317 |
-
*/
|
318 |
-
public function getBaseConfig()
|
319 |
-
{
|
320 |
-
$option = get_option($this->default_option);
|
321 |
-
if (!$option || is_null($option)) {
|
322 |
-
return array();
|
323 |
-
} else {
|
324 |
-
return $option;
|
325 |
-
}
|
326 |
-
}
|
327 |
-
|
328 |
-
/**
|
329 |
-
* List of Checklist.
|
330 |
-
*/
|
331 |
-
public function checkPoint()
|
332 |
-
{
|
333 |
-
// Apply rules with products.
|
334 |
-
// NOT YET USED.
|
335 |
-
if ($this->discount_applied) return true;
|
336 |
-
}
|
337 |
-
|
338 |
-
/**
|
339 |
-
* Filter the Rules with some validations.
|
340 |
-
*/
|
341 |
-
public function filterRules()
|
342 |
-
{
|
343 |
-
$rules = $this->rules;
|
344 |
-
|
345 |
-
if (is_null($rules) || !isset($rules)) return false;
|
346 |
-
|
347 |
-
// Start with empty set.
|
348 |
-
$rule_set = array();
|
349 |
-
|
350 |
-
foreach ($rules as $index => $rule) {
|
351 |
-
$status = (isset($rule->status) ? $rule->status : false);
|
352 |
-
|
353 |
-
// To Check as Plugin Active - InActive.
|
354 |
-
if ($status == 'publish') {
|
355 |
-
$date_from = (isset($rule->date_from) ? strtotime($rule->date_from) : false);
|
356 |
-
$date_to = (isset($rule->date_to) ? strtotime($rule->date_to) : false);
|
357 |
-
$today = strtotime(date('m/d/Y'));
|
358 |
-
|
359 |
-
// Validating Rule with Date of Expiry.
|
360 |
-
if (($date_from <= $today) && (($date_to == '') || ($date_to >= $today))) {
|
361 |
-
|
362 |
-
// Validating the Rule with its Order ID.
|
363 |
-
if (isset($rule->rule_order)) {
|
364 |
-
// If Order ID is '-', then this rule not going to implement.
|
365 |
-
if ($rule->rule_order !== '-') {
|
366 |
-
$rule_set[] = $rule;
|
367 |
-
}
|
368 |
-
}
|
369 |
-
}
|
370 |
-
}
|
371 |
-
}
|
372 |
-
$this->rules = $rule_set;
|
373 |
-
|
374 |
-
// To Order the Rules, based on its order ID.
|
375 |
-
$this->orderRules();
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
* Ordering the Set of Rules.
|
380 |
-
*
|
381 |
-
* @return bool
|
382 |
-
*/
|
383 |
-
public function orderRules()
|
384 |
-
{
|
385 |
-
if (empty($this->rules)) return false;
|
386 |
-
|
387 |
-
$ordered_rules = array();
|
388 |
-
|
389 |
-
// Make associative array with Order ID.
|
390 |
-
foreach ($this->rules as $index => $rule) {
|
391 |
-
if (isset($rule->rule_order)) {
|
392 |
-
if ($rule->rule_order != '') {
|
393 |
-
$ordered_rules[$rule->rule_order] = $rule;
|
394 |
-
}
|
395 |
-
}
|
396 |
-
}
|
397 |
-
// Order the Rules with it's priority.
|
398 |
-
ksort($ordered_rules);
|
399 |
-
|
400 |
-
$this->rules = $ordered_rules;
|
401 |
-
}
|
402 |
-
|
403 |
-
/**
|
404 |
-
* Apply the Rules to line items.
|
405 |
-
*
|
406 |
-
* @return bool
|
407 |
-
*/
|
408 |
-
public function applyRules()
|
409 |
-
{
|
410 |
-
global $woocommerce;
|
411 |
-
|
412 |
-
// If there is no rules, then return false.
|
413 |
-
if (!isset($this->rules)) return false;
|
414 |
-
|
415 |
-
// Check point having list of checklist to apply.
|
416 |
-
if ($this->checkPoint()) return false;
|
417 |
-
|
418 |
-
// To Generate Valid Rule sets.
|
419 |
-
$this->generateRuleSets($woocommerce);
|
420 |
-
// Sort cart by price ascending
|
421 |
-
|
422 |
-
$cart_contents = $this->sortCartPrice($woocommerce->cart->cart_contents, 'asc');
|
423 |
-
|
424 |
-
//to handle buy one get one
|
425 |
-
$free_products = WC()->session->get('woo_discount_rules_get_free_product', array());
|
426 |
-
|
427 |
-
// Handling Tight update with wooCommerce Changes.
|
428 |
-
$postData = \FlycartInput\FInput::getInstance();
|
429 |
-
$empty_apply_coupon = $postData->get('apply_coupon');
|
430 |
-
$empty_update_cart = $postData->get('update_cart');
|
431 |
-
$empty_proceed = $postData->get('proceed');
|
432 |
-
$runFreeProduct = (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) ? false : true;
|
433 |
-
|
434 |
-
$quantity_exists = array();
|
435 |
-
if(!empty($free_products) && $runFreeProduct){
|
436 |
-
//check if product already in cart
|
437 |
-
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
|
438 |
-
foreach ($free_products as $productId => $free_product_detail) {
|
439 |
-
$found = false;
|
440 |
-
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
441 |
-
$_product = $values['data'];
|
442 |
-
if ($_product->get_id() == $productId){
|
443 |
-
$_quantity = $values['quantity'];
|
444 |
-
$_cart_item_key = $cart_item_key;
|
445 |
-
$found = true;
|
446 |
-
}
|
447 |
-
}
|
448 |
-
// if product found, add it
|
449 |
-
if ($found) {
|
450 |
-
WC()->cart->remove_cart_item( $_cart_item_key );
|
451 |
-
$quantity_exists[$productId] = $_quantity-$free_product_detail['count'];
|
452 |
-
if($quantity_exists[$productId] > 0){
|
453 |
-
WC()->cart->add_to_cart($productId, $quantity_exists[$productId]);
|
454 |
-
}
|
455 |
-
}
|
456 |
-
}
|
457 |
-
}
|
458 |
-
}
|
459 |
-
WC()->session->set('woo_discount_rules_get_free_product', array());
|
460 |
-
|
461 |
-
foreach ($cart_contents as $index => $item) {
|
462 |
-
$this->matchRules($index, $item);
|
463 |
-
}
|
464 |
-
|
465 |
-
//to handle buy one get one
|
466 |
-
$free_products = WC()->session->get('woo_discount_rules_get_free_product', array());
|
467 |
-
if(!empty($free_products) && $runFreeProduct){
|
468 |
-
//check if product already in cart
|
469 |
-
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
|
470 |
-
foreach ($free_products as $productId => $free_product_detail) {
|
471 |
-
$product = wc_get_product($productId);
|
472 |
-
if($product->get_parent_id()){
|
473 |
-
WC()->cart->add_to_cart($product->get_parent_id(), $free_product_detail['count'], $productId, $product->get_attributes());
|
474 |
-
} else {
|
475 |
-
WC()->cart->add_to_cart($productId, $free_product_detail['count']);
|
476 |
-
}
|
477 |
-
$found = false;
|
478 |
-
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
479 |
-
$_product = $values['data'];
|
480 |
-
if ($_product->get_id() == $productId){
|
481 |
-
$freeProductRule[0]['amount'] = array('price_discount' => $_product->get_price());
|
482 |
-
$freeProductRule[0]['name'] = $free_product_detail['rule_name'];
|
483 |
-
$freeProductRule[0]['item'] = $cart_item_key;
|
484 |
-
$freeProductRule[0]['id'] = $_product->get_id();
|
485 |
-
if(isset($quantity_exists[$productId]) && $quantity_exists[$productId] > 0){
|
486 |
-
//discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
|
487 |
-
$discount_price = $_product->get_price() - (($_product->get_price()/($quantity_exists[$productId]+$free_product_detail['count'])) * $quantity_exists[$productId]);
|
488 |
-
$freeProductRule[0]['amount'] = array('price_discount' => $discount_price);
|
489 |
-
}
|
490 |
-
$this->matched_sets[$cart_item_key] = $freeProductRule;
|
491 |
-
}
|
492 |
-
}
|
493 |
-
}
|
494 |
-
|
495 |
-
}
|
496 |
-
}
|
497 |
-
|
498 |
-
$this->makeLog();
|
499 |
-
}
|
500 |
-
|
501 |
-
/**
|
502 |
-
* Generate the Suitable and active rule sets.
|
503 |
-
*
|
504 |
-
* @param $woocommerce
|
505 |
-
* @return bool
|
506 |
-
*/
|
507 |
-
public function generateRuleSets($woocommerce)
|
508 |
-
{
|
509 |
-
$rule_sets = array();
|
510 |
-
|
511 |
-
if (!isset($this->rules)) return false;
|
512 |
-
|
513 |
-
// Loop the Rules set to collect matched rules.
|
514 |
-
foreach ($this->rules as $index => $rule) {
|
515 |
-
// General Rule Info.
|
516 |
-
$rule_sets[$index]['discount_type'] = 'price_discount';
|
517 |
-
$rule_sets[$index]['name'] = (isset($rule->rule_name) ? $rule->rule_name : 'Rule_' . $index);
|
518 |
-
$rule_sets[$index]['descr'] = (isset($rule->rule_descr) ? $rule->rule_descr : '');
|
519 |
-
$rule_sets[$index]['method'] = (isset($rule->rule_method) ? $rule->rule_method : 'qty_based');
|
520 |
-
$rule_sets[$index]['qty_based_on'] = (isset($rule->qty_based_on) ? $rule->qty_based_on : 'each_product');
|
521 |
-
$rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
|
522 |
-
$rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
|
523 |
-
$rule_sets[$index]['allow']['purchase_history'] = 'yes';
|
524 |
-
// Default setup for all customers.
|
525 |
-
$rule_sets[$index]['allow']['users'] = 'all';
|
526 |
-
$rule_sets[$index]['allow']['user_role'] = true;
|
527 |
-
|
528 |
-
// For quantity based discount
|
529 |
-
if($rule_sets[$index]['method'] == 'qty_based'){
|
530 |
-
// List the type of apply, by Product or by Category.
|
531 |
-
if (isset($rule->apply_to)) {
|
532 |
-
// If Rule is processed by Specific Products, then..
|
533 |
-
if ($rule->apply_to == 'specific_products') {
|
534 |
-
if (isset($rule->product_to_apply)) {
|
535 |
-
$rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
|
536 |
-
}
|
537 |
-
} else if ($rule->apply_to == 'specific_category') {
|
538 |
-
if (isset($rule->apply_child_categories) && $rule->apply_child_categories) {
|
539 |
-
$rule_sets[$index]['type']['apply_child_categories'] = 1;
|
540 |
-
} else {
|
541 |
-
$rule_sets[$index]['type']['apply_child_categories'] = 0;
|
542 |
-
}
|
543 |
-
|
544 |
-
if (isset($rule->category_to_apply)) {
|
545 |
-
$rule_sets[$index]['type']['specific_category'] = $this->checkWithCategory($rule, $woocommerce);
|
546 |
-
if($rule_sets[$index]['type']['apply_child_categories']){
|
547 |
-
$cat = $rule_sets[$index]['type']['specific_category'];
|
548 |
-
$rule_sets[$index]['type']['specific_category'] = $this->getAllSubCategories($cat);
|
549 |
-
}
|
550 |
-
}
|
551 |
-
if (isset($rule->is_cumulative) && $rule->is_cumulative) {
|
552 |
-
$rule_sets[$index]['type']['is_cumulative'] = 1;
|
553 |
-
} else {
|
554 |
-
$rule_sets[$index]['type']['is_cumulative'] = 0;
|
555 |
-
}
|
556 |
-
} else {
|
557 |
-
$rule_sets[$index]['type'] = 'all';
|
558 |
-
}
|
559 |
-
|
560 |
-
$rule_sets[$index]['discount'] = 0;
|
561 |
-
if (isset($rule->discount_range)) {
|
562 |
-
if ($rule->discount_range != '') {
|
563 |
-
$rule_sets[$index]['discount'] = $this->getDiscountRangeList($rule);
|
564 |
-
}
|
565 |
-
}
|
566 |
-
|
567 |
-
// If Rule is processed by Specific Customers, then..
|
568 |
-
if ($rule->customer == 'only_given') {
|
569 |
-
if (isset($rule->users_to_apply)) {
|
570 |
-
$rule_sets[$index]['allow']['users'] = $this->checkWithUsers($rule, $woocommerce);
|
571 |
-
}
|
572 |
-
}
|
573 |
-
$rule_sets[$index]['apply_to'] = $rule->apply_to;
|
574 |
-
|
575 |
-
// Default setup for purchase history
|
576 |
-
if(isset($rule->based_on_purchase_history) && $rule->based_on_purchase_history){
|
577 |
-
$rule_sets[$index]['allow']['purchase_history'] = $this->checkWithUsersPurchaseHistory($rule, $woocommerce);
|
578 |
-
}
|
579 |
-
|
580 |
-
// check for user roles
|
581 |
-
if(isset($rule->user_roles_to_apply)){
|
582 |
-
$rule_sets[$index]['allow']['user_role'] = $this->checkWithUserRoles($rule);
|
583 |
-
}
|
584 |
-
}
|
585 |
-
|
586 |
-
// If Current Customer is not Allowed to use this discount, then it's going to be removed.
|
587 |
-
if ($rule_sets[$index]['allow']['users'] == 'no' || !$rule_sets[$index]['allow']['user_role'] || $rule_sets[$index]['allow']['purchase_history'] == 'no') {
|
588 |
-
unset($rule_sets[$index]);
|
589 |
-
}
|
590 |
-
|
591 |
-
} else if($rule_sets[$index]['method'] == 'product_based'){
|
592 |
-
$rule_sets[$index]['product_based_condition'] = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
593 |
-
$rule_sets[$index]['product_based_discount'] = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
|
594 |
-
}
|
595 |
-
}
|
596 |
-
$this->rule_sets = $rule_sets;
|
597 |
-
}
|
598 |
-
|
599 |
-
public function checkWithUserRoles($rule){
|
600 |
-
$user_roles_to_apply = json_decode($rule->user_roles_to_apply, true);
|
601 |
-
if(!empty($user_roles_to_apply)){
|
602 |
-
if (get_current_user_id() == 0 || count(array_intersect(woo_dicount_rules_generalHelper::getCurrentUserRoles(), $user_roles_to_apply)) == 0) {
|
603 |
-
return false;
|
604 |
-
}
|
605 |
-
}
|
606 |
-
return true;
|
607 |
-
}
|
608 |
-
|
609 |
-
/**
|
610 |
-
* Check with users purchase history
|
611 |
-
* */
|
612 |
-
public function checkWithUsersPurchaseHistory($rule, $woocommerce)
|
613 |
-
{
|
614 |
-
$allowed = 'no';
|
615 |
-
$user = get_current_user_id();
|
616 |
-
if($user){
|
617 |
-
if(isset($rule->purchased_history_amount) && isset($rule->purchase_history_status_list)){
|
618 |
-
if($rule->purchased_history_amount > 0){
|
619 |
-
$purchase_history_status_list = json_decode($rule->purchase_history_status_list, true);
|
620 |
-
$customerOrders = get_posts( array(
|
621 |
-
'numberposts' => -1,
|
622 |
-
'meta_key' => '_customer_user',
|
623 |
-
'meta_value' => $user,
|
624 |
-
'post_type' => wc_get_order_types(),
|
625 |
-
'post_status' => $purchase_history_status_list,
|
626 |
-
) );
|
627 |
-
$totalPurchasedAmount = 0;
|
628 |
-
if(!empty($customerOrders)){
|
629 |
-
foreach ($customerOrders as $customerOrder) {
|
630 |
-
$order = wc_get_order($customerOrder->ID);
|
631 |
-
$total = $order->get_total();
|
632 |
-
$totalPurchasedAmount += $total;
|
633 |
-
}
|
634 |
-
}
|
635 |
-
if($totalPurchasedAmount >= $rule->purchased_history_amount){
|
636 |
-
$allowed = 'yes';
|
637 |
-
}
|
638 |
-
}
|
639 |
-
}
|
640 |
-
}
|
641 |
-
|
642 |
-
return $allowed;
|
643 |
-
}
|
644 |
-
|
645 |
-
/**
|
646 |
-
* Get all sub categories
|
647 |
-
* */
|
648 |
-
public function getAllSubCategories($cat){
|
649 |
-
$category_with_sub_cat = $cat;
|
650 |
-
foreach($cat as $c) {
|
651 |
-
$args = array('hierarchical' => 1,
|
652 |
-
'show_option_none' => '',
|
653 |
-
'hide_empty' => 0,
|
654 |
-
'parent' => $c,
|
655 |
-
'taxonomy' => 'product_cat');
|
656 |
-
$categories = get_categories( $args );
|
657 |
-
foreach($categories as $category) {
|
658 |
-
$category_with_sub_cat[] = $category->term_id;
|
659 |
-
}
|
660 |
-
}
|
661 |
-
$category_with_sub_cat = array_unique($category_with_sub_cat);
|
662 |
-
|
663 |
-
return $category_with_sub_cat;
|
664 |
-
}
|
665 |
-
|
666 |
-
/**
|
667 |
-
* Fetch back the Matched rules.
|
668 |
-
*
|
669 |
-
* @param $index
|
670 |
-
* @param array $item line item.
|
671 |
-
*/
|
672 |
-
public function matchRules($index, $item)
|
673 |
-
{
|
674 |
-
$applied_rules = array();
|
675 |
-
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
676 |
-
$i = 0;
|
677 |
-
if(!empty($this->rule_sets))
|
678 |
-
foreach ($this->rule_sets as $id => $rule) {
|
679 |
-
if(isset($rule['method']) && $rule['method'] == 'qty_based'){
|
680 |
-
if (isset($rule['type']) && isset($rule['apply_to'])) {
|
681 |
-
|
682 |
-
// Working with Products and Category.
|
683 |
-
switch ($rule['apply_to']) {
|
684 |
-
|
685 |
-
case 'specific_products':
|
686 |
-
if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
|
687 |
-
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
688 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
689 |
-
$applied_rules[$i]['item'] = $index;
|
690 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
691 |
-
$applied_rules[$i]['rule_order'] = $id;
|
692 |
-
}
|
693 |
-
|
694 |
-
break;
|
695 |
-
|
696 |
-
case 'specific_category':
|
697 |
-
if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
|
698 |
-
$alreadyExists = 0;
|
699 |
-
if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
|
700 |
-
$totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
|
701 |
-
$quantity = $totalQuantityInThisCategory;
|
702 |
-
//Check for product_discount to apply the rule only once
|
703 |
-
if(isset($rule['discount'])){
|
704 |
-
if(!empty($rule['discount'])){
|
705 |
-
foreach($rule['discount'] as $discount_rules){
|
706 |
-
if(isset($discount_rules->discount_type) && $discount_rules->discount_type == 'product_discount'){
|
707 |
-
if(!empty($this->matched_sets)){
|
708 |
-
foreach($this->matched_sets as $machedRules){
|
709 |
-
foreach($machedRules as $machedRule){
|
710 |
-
if(isset($machedRule['rule_order']) && $machedRule['rule_order'] == $id){
|
711 |
-
$alreadyExists = 1;
|
712 |
-
}
|
713 |
-
}
|
714 |
-
}
|
715 |
-
}
|
716 |
-
}
|
717 |
-
}
|
718 |
-
}
|
719 |
-
}
|
720 |
-
}
|
721 |
-
if(!$alreadyExists){
|
722 |
-
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
723 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
724 |
-
$applied_rules[$i]['item'] = $index;
|
725 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
726 |
-
$applied_rules[$i]['rule_order'] = $id;
|
727 |
-
}
|
728 |
-
}
|
729 |
-
|
730 |
-
|
731 |
-
break;
|
732 |
-
|
733 |
-
case 'all_products':
|
734 |
-
default:
|
735 |
-
|
736 |
-
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
737 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
738 |
-
$applied_rules[$i]['item'] = $index;
|
739 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
740 |
-
|
741 |
-
break;
|
742 |
-
}
|
743 |
-
if(isset($applied_rules[$i]['amount']['product_ids'])){
|
744 |
-
if(!empty($applied_rules[$i]['amount']['product_ids'])){
|
745 |
-
$applyToProducts = $applied_rules[$i]['amount']['product_ids'];
|
746 |
-
$applyPercent = $applied_rules[$i]['amount'];
|
747 |
-
$applied_rules = array();
|
748 |
-
foreach ($applyToProducts as $key => $productId) {
|
749 |
-
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
750 |
-
$_product = $values['data'];
|
751 |
-
if ($_product->get_id() == $productId){
|
752 |
-
$applied_rules_new = array();
|
753 |
-
$applied_rules_new['amount'] = $applyPercent;
|
754 |
-
$applied_rules_new['name'] = $rule['name'];
|
755 |
-
$applied_rules_new['item'] = $cart_item_key;
|
756 |
-
$applied_rules_new['id'] = $productId;
|
757 |
-
$applied_rules_new['rule_order'] = $id;
|
758 |
-
$applied_rules_new['apply_from'] = $item['product_id'];
|
759 |
-
$this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
760 |
-
}
|
761 |
-
}
|
762 |
-
}
|
763 |
-
}
|
764 |
-
}
|
765 |
-
}
|
766 |
-
} else if(isset($rule['method']) && $rule['method'] == 'product_based'){
|
767 |
-
$checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
|
768 |
-
if(!empty($checkRuleMatches)){
|
769 |
-
foreach ($checkRuleMatches['apply_to']['products'] as $key => $productId) {
|
770 |
-
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
771 |
-
$_product = $values['data'];
|
772 |
-
if ($_product->get_id() == $productId){
|
773 |
-
$applied_rules_new = array();
|
774 |
-
$applied_rules_new['amount'] = $checkRuleMatches['amount'];
|
775 |
-
$applied_rules_new['name'] = $rule['name'];
|
776 |
-
$applied_rules_new['item'] = $cart_item_key;
|
777 |
-
$applied_rules_new['id'] = $productId;
|
778 |
-
$applied_rules_new['rule_order'] = $id;
|
779 |
-
$applied_rules_new['apply_from'] = $item['product_id'];
|
780 |
-
$alreadyExists = 0;
|
781 |
-
if(!empty($this->matched_sets[$cart_item_key])){
|
782 |
-
foreach($this->matched_sets[$cart_item_key] as $machedRules){
|
783 |
-
if(isset($machedRules['rule_order']) && $machedRules['rule_order'] == $id){
|
784 |
-
$alreadyExists = 1;
|
785 |
-
break;
|
786 |
-
}
|
787 |
-
}
|
788 |
-
}
|
789 |
-
if(!$alreadyExists) $this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
790 |
-
}
|
791 |
-
}
|
792 |
-
}
|
793 |
-
}
|
794 |
-
}
|
795 |
-
|
796 |
-
$i++;
|
797 |
-
}
|
798 |
-
if(isset($this->matched_sets[$index]) && !empty($this->matched_sets[$index])){
|
799 |
-
$this->matched_sets[$index] = array_merge($this->matched_sets[$index], $applied_rules);
|
800 |
-
} else {
|
801 |
-
$this->matched_sets[$index] = $applied_rules;
|
802 |
-
}
|
803 |
-
}
|
804 |
-
|
805 |
-
/**
|
806 |
-
* Check Product based rules matches
|
807 |
-
* */
|
808 |
-
public function checkProductBasedRuleMatches($rule, $item, $quantity){
|
809 |
-
$result = array();
|
810 |
-
if(isset($rule['product_based_condition']) && !empty($rule['product_based_condition'])){
|
811 |
-
$product_based_conditions = $rule['product_based_condition'];
|
812 |
-
$buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
813 |
-
$quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
814 |
-
$quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
815 |
-
$quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
816 |
-
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
817 |
-
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
818 |
-
|
819 |
-
$product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
|
820 |
-
$discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
821 |
-
$discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
822 |
-
$_quantity = array();
|
823 |
-
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
|
824 |
-
foreach ($product_to_buy as $key => $productId) {
|
825 |
-
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
826 |
-
$_product = $values['data'];
|
827 |
-
if ($_product->get_id() == $productId){
|
828 |
-
$_quantity[$productId] = $values['quantity'];
|
829 |
-
}
|
830 |
-
}
|
831 |
-
}
|
832 |
-
}
|
833 |
-
$quantity = WooDiscountRulesPrice_ProductBased::adjustQuantity($buy_type, $_quantity);
|
834 |
-
if(in_array($item['product_id'], $product_to_buy) && !empty($_quantity)){
|
835 |
-
$proceed = 1;
|
836 |
-
if($buy_type == 'each'){
|
837 |
-
$allProductsInCart = array_keys($_quantity);
|
838 |
-
$matchedProducts = array_intersect($allProductsInCart, $product_to_buy);
|
839 |
-
if(count($product_to_buy) != count($matchedProducts)){
|
840 |
-
$proceed = 0;
|
841 |
-
}
|
842 |
-
}
|
843 |
-
if($proceed){
|
844 |
-
$quantityMatched = WooDiscountRulesPrice_ProductBased::verifyQuantity($quantity_rule, $quantity, $quantity_from, $quantity_to, $buy_type);
|
845 |
-
if($quantityMatched){
|
846 |
-
$result['amount'][$discount_type] = $discount_value;
|
847 |
-
$result['apply_to']['products'] = $product_to_apply;
|
848 |
-
}
|
849 |
-
}
|
850 |
-
}
|
851 |
-
}
|
852 |
-
return $result;
|
853 |
-
}
|
854 |
-
|
855 |
-
/**
|
856 |
-
* Get quantity of products in specific category
|
857 |
-
* */
|
858 |
-
public function getProductQuantityInThisCategory($category){
|
859 |
-
global $woocommerce;
|
860 |
-
$quantity = 0;
|
861 |
-
if(count($woocommerce->cart->cart_contents)){
|
862 |
-
foreach ($woocommerce->cart->cart_contents as $cartItem) {
|
863 |
-
$terms = get_the_terms( $cartItem['product_id'], 'product_cat' );
|
864 |
-
if($terms){
|
865 |
-
$has = 0;
|
866 |
-
foreach ($terms as $term) {
|
867 |
-
if(in_array($term->term_id, $category)){
|
868 |
-
$has = 1;
|
869 |
-
}
|
870 |
-
}
|
871 |
-
if($has){
|
872 |
-
$quantity = $quantity + $cartItem['quantity'];
|
873 |
-
}
|
874 |
-
}
|
875 |
-
}
|
876 |
-
}
|
877 |
-
return $quantity;
|
878 |
-
}
|
879 |
-
|
880 |
-
/**
|
881 |
-
* Return the First index.
|
882 |
-
*
|
883 |
-
* @param $array
|
884 |
-
* @return mixed
|
885 |
-
*/
|
886 |
-
public function array_first($array)
|
887 |
-
{
|
888 |
-
if (is_object($array)) $array = (array)$array;
|
889 |
-
if (is_array($array)) return $array;
|
890 |
-
foreach ($array as $first) {
|
891 |
-
return $first;
|
892 |
-
}
|
893 |
-
}
|
894 |
-
|
895 |
-
/**
|
896 |
-
* Return the Adjustment amount.
|
897 |
-
*
|
898 |
-
* @param $quantity
|
899 |
-
* @param $discount_range
|
900 |
-
* @return array|bool
|
901 |
-
*/
|
902 |
-
public function getAdjustmentAmount($quantity, $discount_ranges)
|
903 |
-
{
|
904 |
-
$adjustment = array();
|
905 |
-
foreach($discount_ranges as $discount_range) {
|
906 |
-
|
907 |
-
if (!is_array($discount_range) && !is_object($discount_range)) return false;
|
908 |
-
$range = is_array($discount_range) ? (object) $discount_range : $discount_range;
|
909 |
-
$min = (isset($range->min_qty) ? $range->min_qty : 0);
|
910 |
-
$max = (isset($range->max_qty) ? $range->max_qty : false);
|
911 |
-
if($max == 0 || $max == '' || $max == false) $max = 999;
|
912 |
-
|
913 |
-
$type = (isset($range->discount_type) ? $range->discount_type : 'price_discount');
|
914 |
-
|
915 |
-
if ($max == false) continue;
|
916 |
-
|
917 |
-
if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
|
918 |
-
if($type == 'product_discount'){
|
919 |
-
$discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
|
920 |
-
$productIds = isset($range->discount_product) ? $range->discount_product : array();
|
921 |
-
if($discount_product_option == 'any_cheapest'){
|
922 |
-
$productCheapest = $this->getCheapestProductFromCart($productIds);
|
923 |
-
if(!empty($productCheapest)){
|
924 |
-
$adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
|
925 |
-
}
|
926 |
-
} else {
|
927 |
-
//to handle product discount
|
928 |
-
$free_product = WC()->session->get('woo_discount_rules_get_free_product', array());
|
929 |
-
if(!empty($productIds)){
|
930 |
-
foreach ($productIds as $productId){
|
931 |
-
if(isset($free_product[$productId])){
|
932 |
-
$free_product[$productId]['count'] = $free_product[$productId]['count']+1;
|
933 |
-
} else {
|
934 |
-
$free_product[$productId]['count'] = 1;
|
935 |
-
$free_product[$productId]['rule_name'] = $range->title;
|
936 |
-
}
|
937 |
-
}
|
938 |
-
WC()->session->set('woo_discount_rules_get_free_product', $free_product);
|
939 |
-
}
|
940 |
-
$adjustment[$type] = $productIds;
|
941 |
-
}
|
942 |
-
} else {
|
943 |
-
$adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
|
944 |
-
}
|
945 |
-
}
|
946 |
-
}
|
947 |
-
return $adjustment;
|
948 |
-
}
|
949 |
-
|
950 |
-
/**
|
951 |
-
* Get cheapest product
|
952 |
-
* */
|
953 |
-
public function getCheapestProductFromCart($products){
|
954 |
-
if(empty($products)) return array();
|
955 |
-
$cheapestProductValue = 0;
|
956 |
-
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
957 |
-
$_product = $values['data'];
|
958 |
-
$productId = $this->getProductIdFromCartProduct($_product);
|
959 |
-
if(in_array($productId, $products)){
|
960 |
-
if($cheapestProductValue == 0){
|
961 |
-
$cheapestProductValue = $_product->get_price();
|
962 |
-
$cheapestProduct = $_product->get_id();
|
963 |
-
$quantity = $values['quantity'];
|
964 |
-
} else if($cheapestProductValue > $_product->get_price()){
|
965 |
-
$cheapestProductValue = $_product->get_price();
|
966 |
-
$cheapestProduct = $_product->get_id();
|
967 |
-
$quantity = $values['quantity'];
|
968 |
-
}
|
969 |
-
}
|
970 |
-
}
|
971 |
-
if($cheapestProductValue > 0){
|
972 |
-
//discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
|
973 |
-
$discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-1));
|
974 |
-
return array('product' => $cheapestProduct, 'percent' => $discount_price);
|
975 |
-
}
|
976 |
-
return array();
|
977 |
-
}
|
978 |
-
|
979 |
-
public function getProductIdFromCartProduct($product){
|
980 |
-
$id = $product->get_id();
|
981 |
-
return $id;
|
982 |
-
}
|
983 |
-
|
984 |
-
/**
|
985 |
-
* Validating the Active user with rule sets.
|
986 |
-
*
|
987 |
-
* @param $rule
|
988 |
-
* @return string
|
989 |
-
*/
|
990 |
-
public function manageUserAccess($rule)
|
991 |
-
{
|
992 |
-
$allowed = 'no';
|
993 |
-
if (!isset($rule->users_to_apply)) return $allowed;
|
994 |
-
|
995 |
-
$users = $rule->users_to_apply;
|
996 |
-
|
997 |
-
if (is_string($users)) $users = json_decode($users, True);
|
998 |
-
|
999 |
-
if (!is_array($users)) return $allowed;
|
1000 |
-
|
1001 |
-
$user = get_current_user_id();
|
1002 |
-
|
1003 |
-
if (count(array_intersect($users, array($user))) > 0) {
|
1004 |
-
$allowed = 'yes';
|
1005 |
-
}
|
1006 |
-
|
1007 |
-
return $allowed;
|
1008 |
-
}
|
1009 |
-
|
1010 |
-
/**
|
1011 |
-
* To Check active cart items are in the rules list item.
|
1012 |
-
*
|
1013 |
-
* @param $product_list
|
1014 |
-
* @param $product
|
1015 |
-
* @return bool
|
1016 |
-
*/
|
1017 |
-
public function isItemInProductList($product_list, $product)
|
1018 |
-
{
|
1019 |
-
if (!isset($product['product_id'])) return false;
|
1020 |
-
$product_ids = array($product['product_id']);
|
1021 |
-
if(!empty($product['variation_id'])) $product_ids[] = $product['variation_id'];
|
1022 |
-
if (!is_array($product_list)) $product_list = (array)$product_list;
|
1023 |
-
if (count(array_intersect($product_list, $product_ids)) == 1) {
|
1024 |
-
return true;
|
1025 |
-
} else {
|
1026 |
-
return false;
|
1027 |
-
}
|
1028 |
-
}
|
1029 |
-
|
1030 |
-
/**
|
1031 |
-
* To Check that the items are in specified category.
|
1032 |
-
*
|
1033 |
-
* @param $category_list
|
1034 |
-
* @param $product
|
1035 |
-
* @return bool
|
1036 |
-
*/
|
1037 |
-
public function isItemInCategoryList($category_list, $product)
|
1038 |
-
{
|
1039 |
-
|
1040 |
-
$helper = new woo_dicount_rules_generalHelper();
|
1041 |
-
$all_category = $helper->getCategoryList();
|
1042 |
-
if (!isset($product['product_id'])) return false;
|
1043 |
-
$product_category = woo_dicount_rules_generalHelper::getCategoryByPost($product);
|
1044 |
-
|
1045 |
-
$status = false;
|
1046 |
-
//check any one of category matches
|
1047 |
-
$matching_cats = array_intersect($product_category, $category_list);
|
1048 |
-
$result = !empty( $matching_cats );
|
1049 |
-
if($result){
|
1050 |
-
$status = true;
|
1051 |
-
}
|
1052 |
-
|
1053 |
-
return $status;
|
1054 |
-
}
|
1055 |
-
|
1056 |
-
/**
|
1057 |
-
*
|
1058 |
-
*/
|
1059 |
-
public function isUserInCustomerList()
|
1060 |
-
{
|
1061 |
-
|
1062 |
-
}
|
1063 |
-
|
1064 |
-
/**
|
1065 |
-
* Sort cart by price
|
1066 |
-
*
|
1067 |
-
* @access public
|
1068 |
-
* @param array $cart
|
1069 |
-
* @param string $order
|
1070 |
-
* @return array
|
1071 |
-
*/
|
1072 |
-
public function sortCartPrice($cart, $order)
|
1073 |
-
{
|
1074 |
-
$cart_sorted = array();
|
1075 |
-
|
1076 |
-
foreach ($cart as $cart_item_key => $cart_item) {
|
1077 |
-
$cart_sorted[$cart_item_key] = $cart_item;
|
1078 |
-
}
|
1079 |
-
|
1080 |
-
uasort($cart_sorted, array($this, 'sortCartByPrice_' . $order));
|
1081 |
-
|
1082 |
-
return $cart_sorted;
|
1083 |
-
}
|
1084 |
-
|
1085 |
-
/**
|
1086 |
-
* Sort cart by price uasort collable - ascending
|
1087 |
-
*
|
1088 |
-
* @access public
|
1089 |
-
* @param mixed $first
|
1090 |
-
* @param mixed $second
|
1091 |
-
* @return bool
|
1092 |
-
*/
|
1093 |
-
public function sortCartByPrice_asc($first, $second)
|
1094 |
-
{
|
1095 |
-
if (isset($first['data'])) {
|
1096 |
-
if ($first['data']->get_price() == $second['data']->get_price()) {
|
1097 |
-
return 0;
|
1098 |
-
}
|
1099 |
-
}
|
1100 |
-
return ($first['data']->get_price() < $second['data']->get_price()) ? -1 : 1;
|
1101 |
-
}
|
1102 |
-
|
1103 |
-
/**
|
1104 |
-
* Sort cart by price uasort collable - descending
|
1105 |
-
*
|
1106 |
-
* @access public
|
1107 |
-
* @param mixed $first
|
1108 |
-
* @param mixed $second
|
1109 |
-
* @return bool
|
1110 |
-
*/
|
1111 |
-
public function sortCartByPrice_desc($first, $second)
|
1112 |
-
{
|
1113 |
-
if (isset($first['data'])) {
|
1114 |
-
if ($first['data']->get_price() == $second['data']->get_price()) {
|
1115 |
-
return 0;
|
1116 |
-
}
|
1117 |
-
}
|
1118 |
-
return ($first['data']->get_price() > $second['data']->get_price()) ? -1 : 1;
|
1119 |
-
}
|
1120 |
-
|
1121 |
-
/**
|
1122 |
-
* Return the List of Products to Apply.
|
1123 |
-
*
|
1124 |
-
* @param $woocommerce
|
1125 |
-
* @param $rule
|
1126 |
-
* @return array
|
1127 |
-
*/
|
1128 |
-
public function checkWithProducts($rule, $woocommerce)
|
1129 |
-
{
|
1130 |
-
$specific_product_list = array();
|
1131 |
-
if (is_string($rule->product_to_apply)) {
|
1132 |
-
$specific_product_list = json_decode($rule->product_to_apply, true);
|
1133 |
-
}
|
1134 |
-
return $specific_product_list;
|
1135 |
-
}
|
1136 |
-
|
1137 |
-
/**
|
1138 |
-
* Check with category list.
|
1139 |
-
*
|
1140 |
-
* @param $rule
|
1141 |
-
* @param $woocommerce
|
1142 |
-
* @return array|mixed
|
1143 |
-
*/
|
1144 |
-
public function checkWithCategory($rule, $woocommerce)
|
1145 |
-
{
|
1146 |
-
$specific_category_list = array();
|
1147 |
-
if (is_string($rule->category_to_apply)) {
|
1148 |
-
$specific_category_list = json_decode($rule->category_to_apply, true);
|
1149 |
-
}
|
1150 |
-
return $specific_category_list;
|
1151 |
-
}
|
1152 |
-
|
1153 |
-
/**
|
1154 |
-
* Check with User list.
|
1155 |
-
*
|
1156 |
-
* @param $rule
|
1157 |
-
* @param $woocommerce
|
1158 |
-
* @return array|mixed
|
1159 |
-
*/
|
1160 |
-
public function checkWithUsers($rule, $woocommerce)
|
1161 |
-
{
|
1162 |
-
// Return as , User is allowed to use this discount or not.
|
1163 |
-
// Working Users.
|
1164 |
-
return $this->manageUserAccess($rule);
|
1165 |
-
}
|
1166 |
-
|
1167 |
-
/**
|
1168 |
-
* To Return the Discount Ranges.
|
1169 |
-
*
|
1170 |
-
* @param $rule
|
1171 |
-
* @return array|mixed
|
1172 |
-
*/
|
1173 |
-
public function getDiscountRangeList($rule)
|
1174 |
-
{
|
1175 |
-
$discount_range_list = array();
|
1176 |
-
if (is_string($rule->discount_range)) {
|
1177 |
-
$discount_range_list = json_decode($rule->discount_range);
|
1178 |
-
}
|
1179 |
-
return $discount_range_list;
|
1180 |
-
}
|
1181 |
-
|
1182 |
-
/**
|
1183 |
-
* For Display the price discount of a product.
|
1184 |
-
*/
|
1185 |
-
public function priceTable()
|
1186 |
-
{
|
1187 |
-
global $product;
|
1188 |
-
|
1189 |
-
$config = $this->baseConfig;
|
1190 |
-
$show_discount = true;
|
1191 |
-
// Base Config to Check whether display table or not.
|
1192 |
-
if (isset($config['show_discount_table'])) {
|
1193 |
-
if ($config['show_discount_table'] == 'show') {
|
1194 |
-
$show_discount = true;
|
1195 |
-
} else {
|
1196 |
-
$show_discount = false;
|
1197 |
-
}
|
1198 |
-
}
|
1199 |
-
// If Only allowed to display, then only its display the table.
|
1200 |
-
if ($show_discount) {
|
1201 |
-
$table_data = $this->generateDiscountTableData($product);
|
1202 |
-
$path = WOO_DISCOUNT_DIR . '/view/template/discount-table.php';
|
1203 |
-
echo $this->generateTableHtml($table_data, $path);
|
1204 |
-
}
|
1205 |
-
|
1206 |
-
}
|
1207 |
-
|
1208 |
-
/**
|
1209 |
-
* To generate the Discount table data.
|
1210 |
-
*
|
1211 |
-
* @param $product
|
1212 |
-
* @return array|bool|string
|
1213 |
-
*/
|
1214 |
-
public function generateDiscountTableData($product)
|
1215 |
-
{
|
1216 |
-
global $product;
|
1217 |
-
$id = (($product->get_id() != 0 && $product->get_id() != null) ? $product->get_id() : 0);
|
1218 |
-
if ($id == 0) return false;
|
1219 |
-
|
1220 |
-
$this->organizeRules();
|
1221 |
-
|
1222 |
-
$discount_range = array();
|
1223 |
-
if(is_array($this->rules) && count($this->rules) > 0) {
|
1224 |
-
foreach ($this->rules as $index => $rule) {
|
1225 |
-
$status = false;
|
1226 |
-
if(isset($rule->rule_method) && $rule->rule_method == 'qty_based'){
|
1227 |
-
// Check with Active User Filter.
|
1228 |
-
if (isset($rule->customer)) {
|
1229 |
-
$status = false;
|
1230 |
-
if ($rule->customer == 'all') {
|
1231 |
-
$status = true;
|
1232 |
-
} else {
|
1233 |
-
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
1234 |
-
$user_id = get_current_user_id();
|
1235 |
-
if (count(array_intersect($users, array($user_id))) > 0) {
|
1236 |
-
$status = true;
|
1237 |
-
}
|
1238 |
-
}
|
1239 |
-
}
|
1240 |
-
|
1241 |
-
if ($rule->apply_to == 'specific_products') {
|
1242 |
-
|
1243 |
-
// Check with Product Filter.
|
1244 |
-
$products_to_apply = json_decode($rule->product_to_apply);
|
1245 |
-
|
1246 |
-
if ($rule->product_to_apply == null) $status = true;
|
1247 |
-
|
1248 |
-
if ($rule->product_to_apply != null) {
|
1249 |
-
$status = false;
|
1250 |
-
if (in_array($id, $products_to_apply)) {
|
1251 |
-
$status = true;
|
1252 |
-
}
|
1253 |
-
}
|
1254 |
-
} elseif ($rule->apply_to == 'specific_category') {
|
1255 |
-
|
1256 |
-
// Check with Product Category Filter.
|
1257 |
-
$category = woo_dicount_rules_generalHelper::getCategoryByPost($id, true);
|
1258 |
-
|
1259 |
-
if ($rule->category_to_apply == null) $status = true;
|
1260 |
-
|
1261 |
-
if ($rule->category_to_apply != null) {
|
1262 |
-
$category_to_apply = json_decode($rule->category_to_apply);
|
1263 |
-
if (isset($rule->apply_child_categories) && $rule->apply_child_categories == 1) {
|
1264 |
-
$category_to_apply = $this->getAllSubCategories($category_to_apply);
|
1265 |
-
}
|
1266 |
-
woo_dicount_rules_generalHelper::toInt($category_to_apply);
|
1267 |
-
$status = false;
|
1268 |
-
if (count(array_intersect($category_to_apply, $category)) > 0) {
|
1269 |
-
$status = true;
|
1270 |
-
}
|
1271 |
-
}
|
1272 |
-
|
1273 |
-
} else if ($rule->apply_to == 'all_products') {
|
1274 |
-
$status = true;
|
1275 |
-
}
|
1276 |
-
|
1277 |
-
// check for user roles
|
1278 |
-
if(isset($rule->user_roles_to_apply)){
|
1279 |
-
$status = $this->checkWithUserRoles($rule);
|
1280 |
-
}
|
1281 |
-
|
1282 |
-
if ($status) {
|
1283 |
-
$discount_range[] = (isset($rule->discount_range) ? json_decode($rule->discount_range) : array());
|
1284 |
-
}
|
1285 |
-
} else if(isset($rule->rule_method) && $rule->rule_method == 'product_based'){
|
1286 |
-
$product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
1287 |
-
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
1288 |
-
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
1289 |
-
if (in_array($id, $product_to_buy) || in_array($id, $product_to_apply)) {
|
1290 |
-
$product_based_discounts = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
|
1291 |
-
$product_based_discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
1292 |
-
$product_based_discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
1293 |
-
$newTableContent = new stdClass();
|
1294 |
-
$newTableContent->rule_method = $rule->rule_method;
|
1295 |
-
$newTableContent->discount_type = $product_based_discount_type;
|
1296 |
-
$newTableContent->to_discount = $product_based_discount_value;
|
1297 |
-
$newTableContent->title = $rule->rule_name;
|
1298 |
-
$condition = $this->getTextForProductDiscountCondition($rule);
|
1299 |
-
$newTableContent->condition = $condition;
|
1300 |
-
$discount_range[][] = $newTableContent;
|
1301 |
-
}
|
1302 |
-
}
|
1303 |
-
|
1304 |
-
}
|
1305 |
-
}
|
1306 |
-
|
1307 |
-
return $discount_range;
|
1308 |
-
}
|
1309 |
-
|
1310 |
-
public function getTextForProductDiscountCondition($rule){
|
1311 |
-
$product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
1312 |
-
$product_buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
1313 |
-
$product_quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
1314 |
-
$product_quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
1315 |
-
$product_quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
1316 |
-
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
1317 |
-
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
1318 |
-
$condition = esc_html__('Buy', 'woo-discount-rules');
|
1319 |
-
|
1320 |
-
switch ($product_quantity_rule) {
|
1321 |
-
case 'less':
|
1322 |
-
$quantity_text = esc_html__(' less than or equal to ', 'woo-discount-rules').$product_quantity_from.esc_html__(' Quantity', 'woo-discount-rules');
|
1323 |
-
break;
|
1324 |
-
case 'equal':
|
1325 |
-
$quantity_text = ' '.$product_quantity_from.esc_html__(' Quantity ', 'woo-discount-rules');
|
1326 |
-
break;
|
1327 |
-
case 'from':
|
1328 |
-
$quantity_text = '( '.$product_quantity_from.' - '.$product_quantity_to.' )'.esc_html__(' Quantity', 'woo-discount-rules');
|
1329 |
-
break;
|
1330 |
-
case 'more':
|
1331 |
-
default:
|
1332 |
-
$quantity_text = ' '.$product_quantity_from.esc_html__(' or more Quantity', 'woo-discount-rules');
|
1333 |
-
}
|
1334 |
-
|
1335 |
-
switch ($product_buy_type) {
|
1336 |
-
case 'combine':
|
1337 |
-
case 'any':
|
1338 |
-
if(count($product_to_buy) == 1){
|
1339 |
-
$condition .= $quantity_text;
|
1340 |
-
} else {
|
1341 |
-
$condition .= esc_html__(' any ', 'woo-discount-rules').$quantity_text.esc_html__(' products from ','woo-discount-rules');
|
1342 |
-
}
|
1343 |
-
break;
|
1344 |
-
case 'each':
|
1345 |
-
if(count($product_to_buy) == 1){
|
1346 |
-
$condition .= $quantity_text;
|
1347 |
-
} else {
|
1348 |
-
$condition .= ' '.$quantity_text.esc_html__(' in each products', 'woo-discount-rules');
|
1349 |
-
}
|
1350 |
-
break;
|
1351 |
-
}
|
1352 |
-
if(count($product_to_buy) > 1){
|
1353 |
-
$htmlProduct = '';
|
1354 |
-
foreach ($product_to_buy as $product_id){
|
1355 |
-
$product = wc_get_product( $product_id );
|
1356 |
-
$htmlProduct .= '<a href="'.$product->get_permalink().'">'.$product->get_title().'</a>, ';
|
1357 |
-
}
|
1358 |
-
$condition .= ' '.trim($htmlProduct, ', ').' ';
|
1359 |
-
}
|
1360 |
-
$condition .= esc_html__(' and get discount in ', 'woo-discount-rules');
|
1361 |
-
if(count($product_to_apply)){
|
1362 |
-
$htmlProduct = '';
|
1363 |
-
foreach ($product_to_apply as $product_id){
|
1364 |
-
$product = wc_get_product( $product_id );
|
1365 |
-
$htmlProduct .= '<a href="'.$product->get_permalink().'">'.$product->get_title().'</a>, ';
|
1366 |
-
}
|
1367 |
-
$condition .= trim($htmlProduct, ', ');
|
1368 |
-
}
|
1369 |
-
return $condition;
|
1370 |
-
}
|
1371 |
-
|
1372 |
-
/**
|
1373 |
-
* To Return the HTML table for show available discount ranges.
|
1374 |
-
*
|
1375 |
-
* @param $table_data
|
1376 |
-
* @param $path
|
1377 |
-
* @return bool|string
|
1378 |
-
*/
|
1379 |
-
public function generateTableHtml($table_data, $path)
|
1380 |
-
{
|
1381 |
-
//ob_start();
|
1382 |
-
if (!isset($table_data)) return false;
|
1383 |
-
if (!isset($path) || empty($path) || is_null($path)) return false;
|
1384 |
-
//if (!file_exists($path)) return false;
|
1385 |
-
$data = $this->getBaseConfig();
|
1386 |
-
//include($path);
|
1387 |
-
//$html = ob_get_contents();
|
1388 |
-
// ob_clean();
|
1389 |
-
//ob_get_clean();
|
1390 |
-
$html = $this->getDiscountTableContentInHTML($table_data, $data);
|
1391 |
-
return $html;
|
1392 |
-
}
|
1393 |
-
|
1394 |
-
/**
|
1395 |
-
* get Discount table content in html
|
1396 |
-
* */
|
1397 |
-
private function getDiscountTableContentInHTML($table_data, $data){
|
1398 |
-
$html = '';
|
1399 |
-
if (!isset($table_data) || empty($table_data)) return false;
|
1400 |
-
$base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : array());
|
1401 |
-
$html .= '<table>';
|
1402 |
-
$html .= '<thead>';
|
1403 |
-
$html .= '<tr>';
|
1404 |
-
if (isset($base_config['show_discount_title_table'])) {
|
1405 |
-
if ($base_config['show_discount_title_table'] == 'show') {
|
1406 |
-
$html .= '<td>'.esc_html__('Name', 'woo-discount-rules').'</td>';
|
1407 |
-
}
|
1408 |
-
}
|
1409 |
-
$html .= '<td>'.esc_html__('Range', 'woo-discount-rules').'</td>';
|
1410 |
-
$html .= '<td>'.esc_html__('Discount', 'woo-discount-rules').'</td>';
|
1411 |
-
$html .= '</tr>
|
1412 |
-
</thead>
|
1413 |
-
<tbody>';
|
1414 |
-
$have_discount = false;
|
1415 |
-
$table = $table_data;
|
1416 |
-
foreach ($table as $index => $item) {
|
1417 |
-
if ($item) {
|
1418 |
-
foreach ($item as $id => $value) {
|
1419 |
-
if(isset($value->rule_method) && $value->rule_method == 'product_based'){
|
1420 |
-
$title = $value->title;
|
1421 |
-
$condition = $value->condition;
|
1422 |
-
if ($value->discount_type == 'percentage_discount') {
|
1423 |
-
$discount = $value->to_discount.' %';
|
1424 |
-
} else {
|
1425 |
-
$discount = wc_price($value->to_discount);
|
1426 |
-
}
|
1427 |
-
} else {
|
1428 |
-
$title = isset($value->title) ? $value->title : '';
|
1429 |
-
$min = isset($value->min_qty) ? $value->min_qty : 0;
|
1430 |
-
$max = isset($value->max_qty) ? $value->max_qty : 0;
|
1431 |
-
if($max == 0 || $max == '' || $max == false) $max = 999;
|
1432 |
-
$discount_type = isset($value->discount_type) ? $value->discount_type : 0;
|
1433 |
-
$to_discount = isset($value->to_discount) ? $value->to_discount : 0;
|
1434 |
-
$product_discount = isset($value->discount_product) ? $value->discount_product : array();
|
1435 |
-
if (isset($base_config['show_discount_title_table'])) {
|
1436 |
-
}
|
1437 |
-
$condition = $min .' - ' . $max;
|
1438 |
-
if ($discount_type == 'product_discount') {
|
1439 |
-
$discount = '';
|
1440 |
-
if(count($product_discount)){
|
1441 |
-
$htmlProduct = '';
|
1442 |
-
foreach ($product_discount as $product_id){
|
1443 |
-
$product = wc_get_product( $product_id );
|
1444 |
-
$htmlProduct .= $product->get_title();
|
1445 |
-
$htmlProduct .= ' ('.$product->get_price_html().')<br>';
|
1446 |
-
}
|
1447 |
-
$discount = trim($htmlProduct, '<br>');
|
1448 |
-
}
|
1449 |
-
} else if ($discount_type == 'percentage_discount') {
|
1450 |
-
$discount = $to_discount.' %';
|
1451 |
-
} else {
|
1452 |
-
$discount = wc_price($to_discount);
|
1453 |
-
}
|
1454 |
-
|
1455 |
-
}
|
1456 |
-
$html .= '<tr>';
|
1457 |
-
if ($base_config['show_discount_title_table'] == 'show') {
|
1458 |
-
$html .= '<td>'.$title.'</td>';
|
1459 |
-
}
|
1460 |
-
$html .= '<td>'.$condition.'</td>';
|
1461 |
-
$html .= '<td>'.$discount.'</td>';
|
1462 |
-
$html .= '</tr>';
|
1463 |
-
}
|
1464 |
-
$have_discount = true;
|
1465 |
-
}
|
1466 |
-
}
|
1467 |
-
if (!$have_discount) {
|
1468 |
-
$html .= '<tr><td colspan="2">'.esc_html__('No Active Discounts.', 'woo-discount-rules').'</td></tr>';
|
1469 |
-
}
|
1470 |
-
$html .= '</tbody>';
|
1471 |
-
$html .= '</table>';
|
1472 |
-
|
1473 |
-
return $html;
|
1474 |
-
}
|
1475 |
-
|
1476 |
-
/**
|
1477 |
-
* Start Implementing the adjustments.
|
1478 |
-
*
|
1479 |
-
* @return bool
|
1480 |
-
*/
|
1481 |
-
public function initAdjustment()
|
1482 |
-
{
|
1483 |
-
global $woocommerce;
|
1484 |
-
|
1485 |
-
// Get settings
|
1486 |
-
$config = new woo_dicount_rules_WooDiscountBase();
|
1487 |
-
$config = $config->getBaseConfig();
|
1488 |
-
if (is_string($config)) $config = json_decode($config, true);
|
1489 |
-
if(isset($config['price_setup'])){
|
1490 |
-
$type = $config['price_setup'];
|
1491 |
-
} else {
|
1492 |
-
$type = 'all';
|
1493 |
-
}
|
1494 |
-
|
1495 |
-
$cart_items = $woocommerce->cart->cart_contents;
|
1496 |
-
|
1497 |
-
foreach ($cart_items as $cart_item_key => $cart_item) {
|
1498 |
-
$this->applyAdjustment($cart_item, $cart_item_key, $type);
|
1499 |
-
}
|
1500 |
-
}
|
1501 |
-
|
1502 |
-
/**
|
1503 |
-
* Start Implement adjustment on individual items in the cart.
|
1504 |
-
*
|
1505 |
-
* @param $cart_item
|
1506 |
-
* @param $cart_item_key
|
1507 |
-
* @param $type
|
1508 |
-
* @return bool
|
1509 |
-
*/
|
1510 |
-
public function applyAdjustment($cart_item, $cart_item_key, $type)
|
1511 |
-
{
|
1512 |
-
global $woocommerce;
|
1513 |
-
|
1514 |
-
// All Sets are Collected properly, just process with that.
|
1515 |
-
if (!isset($cart_item)) return false;
|
1516 |
-
|
1517 |
-
// If Product having the rule sets then,
|
1518 |
-
if (!isset($this->matched_sets[$cart_item_key])) return false;
|
1519 |
-
|
1520 |
-
$adjustment_set = $this->matched_sets[$cart_item_key];
|
1521 |
-
|
1522 |
-
$price = $woocommerce->cart->cart_contents[$cart_item_key]['data']->get_price();
|
1523 |
-
|
1524 |
-
if ($type == 'first') {
|
1525 |
-
// For Apply the First Rule.
|
1526 |
-
$discount = $this->getAmount($adjustment_set, $price, 'first');
|
1527 |
-
$amount = $price - $discount;
|
1528 |
-
$log = 'Discount | ' . $discount;
|
1529 |
-
$this->applyDiscount($cart_item_key, $amount, $log);
|
1530 |
-
} else if ($type == 'biggest') {
|
1531 |
-
// For Apply the Biggest Discount.
|
1532 |
-
$discount = $this->getAmount($adjustment_set, $price, 'biggest');
|
1533 |
-
$amount = $price - $discount;
|
1534 |
-
$log = 'Discount | ' . $discount;
|
1535 |
-
$this->applyDiscount($cart_item_key, $amount, $log);
|
1536 |
-
} else {
|
1537 |
-
// For Apply All Rules.
|
1538 |
-
$discount = $this->getAmount($adjustment_set, $price);
|
1539 |
-
$amount = $price - $discount;
|
1540 |
-
$log = 'Discount | ' . $discount;
|
1541 |
-
$this->applyDiscount($cart_item_key, $amount, $log);
|
1542 |
-
}
|
1543 |
-
}
|
1544 |
-
|
1545 |
-
/**
|
1546 |
-
* To Get Amount based on the Setting that specified.
|
1547 |
-
*
|
1548 |
-
* @param $sets
|
1549 |
-
* @param $price
|
1550 |
-
* @param string $by
|
1551 |
-
* @return bool|float|int
|
1552 |
-
*/
|
1553 |
-
public function getAmount($sets, $price, $by = 'all')
|
1554 |
-
{
|
1555 |
-
$discount = 0;
|
1556 |
-
$overall_discount = 0;
|
1557 |
-
|
1558 |
-
if (!isset($sets) || empty($sets)) return false;
|
1559 |
-
|
1560 |
-
if ($price == 0) return $price;
|
1561 |
-
|
1562 |
-
// For the biggest price, it compares the current product's price.
|
1563 |
-
if ($by == 'biggest') {
|
1564 |
-
$discount = $this->getBiggestDiscount($sets, $price);
|
1565 |
-
return $discount;
|
1566 |
-
}
|
1567 |
-
|
1568 |
-
foreach ($sets as $id => $set) {
|
1569 |
-
// For the First price, it will return the amount after get hit.
|
1570 |
-
if ($by == 'first') {
|
1571 |
-
if (isset($set['amount']['percentage_discount'])) {
|
1572 |
-
$discount = ($price / 100) * $set['amount']['percentage_discount'];
|
1573 |
-
} else if (isset($set['amount']['price_discount'])) {
|
1574 |
-
$discount = $set['amount']['price_discount'];
|
1575 |
-
}
|
1576 |
-
return $discount;
|
1577 |
-
} else {
|
1578 |
-
// For All, All rules going to apply.
|
1579 |
-
if (isset($set['amount']['percentage_discount'])) {
|
1580 |
-
$discount = ($price / 100) * $set['amount']['percentage_discount'];
|
1581 |
-
// Append all Discounts.
|
1582 |
-
$overall_discount = $overall_discount + $discount;
|
1583 |
-
} else if (isset($set['amount']['price_discount'])) {
|
1584 |
-
$discount = $set['amount']['price_discount'];
|
1585 |
-
// Append all Discounts.
|
1586 |
-
$overall_discount = $overall_discount + $discount;
|
1587 |
-
}
|
1588 |
-
}
|
1589 |
-
}
|
1590 |
-
return $overall_discount;
|
1591 |
-
}
|
1592 |
-
|
1593 |
-
/**
|
1594 |
-
* To Return the Biggest Discount across the available rule sets.
|
1595 |
-
*
|
1596 |
-
* @param $discount_list
|
1597 |
-
* @param $price
|
1598 |
-
* @return float|int
|
1599 |
-
*/
|
1600 |
-
public function getBiggestDiscount($discount_list, $price)
|
1601 |
-
{
|
1602 |
-
$big = 0;
|
1603 |
-
// $amount = $price;
|
1604 |
-
$amount = 0;
|
1605 |
-
foreach ($discount_list as $id => $discount_item) {
|
1606 |
-
$amount_type = (isset($discount_item['amount']['percentage_discount']) ? 'percentage_discount' : 'price_discount');
|
1607 |
-
if ($amount_type == 'percentage_discount') {
|
1608 |
-
if (isset($discount_item['amount']['percentage_discount'])) {
|
1609 |
-
$amount = (($price / 100) * $discount_item['amount']['percentage_discount']);
|
1610 |
-
}
|
1611 |
-
} else {
|
1612 |
-
if (isset($discount_item['amount']['price_discount'])) {
|
1613 |
-
$amount = $discount_item['amount']['price_discount'];
|
1614 |
-
}
|
1615 |
-
}
|
1616 |
-
|
1617 |
-
if ($big < $amount) {
|
1618 |
-
$big = $amount;
|
1619 |
-
}
|
1620 |
-
}
|
1621 |
-
return $big;
|
1622 |
-
}
|
1623 |
-
|
1624 |
-
/**
|
1625 |
-
* Finally Apply the Discount to the Cart item by update to WooCommerce Instance.
|
1626 |
-
*
|
1627 |
-
* @param $item
|
1628 |
-
* @param $amount
|
1629 |
-
* @param $log
|
1630 |
-
*/
|
1631 |
-
public function applyDiscount($item, $amount, $log)
|
1632 |
-
{
|
1633 |
-
global $woocommerce;
|
1634 |
-
// Make sure item exists in cart
|
1635 |
-
if (!isset($woocommerce->cart->cart_contents[$item])) {
|
1636 |
-
return;
|
1637 |
-
}
|
1638 |
-
// Log changes
|
1639 |
-
$woocommerce->cart->cart_contents[$item]['woo_discount'] = array(
|
1640 |
-
'original_price' => get_option('woocommerce_tax_display_cart') == 'excl' ? wc_get_price_excluding_tax( $woocommerce->cart->cart_contents[$item]['data'] ) : wc_get_price_including_tax( $woocommerce->cart->cart_contents[$item]['data'] ),
|
1641 |
-
'log' => $log,
|
1642 |
-
);
|
1643 |
-
|
1644 |
-
// To handle Woocommerce currency switcher
|
1645 |
-
global $WOOCS;
|
1646 |
-
if(isset($WOOCS)){
|
1647 |
-
if (method_exists($WOOCS, 'get_currencies')){
|
1648 |
-
$currencies = $WOOCS->get_currencies();
|
1649 |
-
$amount = $amount / $currencies[$WOOCS->current_currency]['rate'];
|
1650 |
-
}
|
1651 |
-
}
|
1652 |
-
|
1653 |
-
// Actually adjust price in cart
|
1654 |
-
// $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
|
1655 |
-
$woocommerce->cart->cart_contents[$item]['data']->set_price($amount);
|
1656 |
-
|
1657 |
-
}
|
1658 |
-
|
1659 |
-
/**
|
1660 |
-
* For Show the Actual Discount of a product.
|
1661 |
-
*
|
1662 |
-
* @param integer $item_price Actual Price.
|
1663 |
-
* @param object $cart_item Cart Items.
|
1664 |
-
* @param string $cart_item_key to identify the item from cart.
|
1665 |
-
* @return string processed price of a product.
|
1666 |
-
*/
|
1667 |
-
public function replaceVisiblePricesCart($item_price, $cart_item = array(), $cart_item_key = null)
|
1668 |
-
{
|
1669 |
-
|
1670 |
-
if (!isset($cart_item['woo_discount'])) {
|
1671 |
-
return $item_price;
|
1672 |
-
}
|
1673 |
-
|
1674 |
-
// Get price to display
|
1675 |
-
$price = get_option('woocommerce_tax_display_cart') == 'excl' ? wc_get_price_excluding_tax($cart_item['data']) : wc_get_price_including_tax($cart_item['data']);
|
1676 |
-
|
1677 |
-
// Format price to display
|
1678 |
-
$price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($price) : woocommerce_price($price);
|
1679 |
-
$original_price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($cart_item['woo_discount']['original_price']) : woocommerce_price($cart_item['woo_discount']['original_price']);
|
1680 |
-
|
1681 |
-
if ($cart_item['woo_discount']['original_price'] != $price) {
|
1682 |
-
$item_price = '<span class="cart_price"><del>' . $original_price_to_display . '</del> <ins>' . $price_to_display . '</ins></span>';
|
1683 |
-
} else {
|
1684 |
-
$item_price = $price_to_display;
|
1685 |
-
}
|
1686 |
-
|
1687 |
-
return $item_price;
|
1688 |
-
}
|
1689 |
-
|
1690 |
-
/**
|
1691 |
-
* Replace visible price if rule matches for variants
|
1692 |
-
* */
|
1693 |
-
public function replaceVisiblePricesForVariant($data, $product, $variations)
|
1694 |
-
{
|
1695 |
-
$item_price = $data['price_html'];
|
1696 |
-
|
1697 |
-
$config = new woo_dicount_rules_WooDiscountBase();
|
1698 |
-
$config = $config->getBaseConfig();
|
1699 |
-
if (is_string($config)) $config = json_decode($config, true);
|
1700 |
-
if(isset($config['price_setup'])){
|
1701 |
-
$type = $config['price_setup'];
|
1702 |
-
} else {
|
1703 |
-
$type = 'all';
|
1704 |
-
}
|
1705 |
-
$notAdmin = !is_admin();
|
1706 |
-
if(isset($config['show_price_discount_on_product_page'])){
|
1707 |
-
$show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
|
1708 |
-
} else {
|
1709 |
-
$show_price_discount_on_product_page = 'dont';
|
1710 |
-
}
|
1711 |
-
if($show_price_discount_on_product_page == 'show' && $notAdmin){
|
1712 |
-
$product_id = $product->get_id();
|
1713 |
-
$item['product_id'] = $product_id;
|
1714 |
-
$item['data'] = $product;
|
1715 |
-
$item['quantity'] = 1;
|
1716 |
-
global $woocommerce;
|
1717 |
-
$this->analyse($woocommerce);
|
1718 |
-
$this->matchRules($product_id, $item);
|
1719 |
-
|
1720 |
-
if(isset($this->matched_sets[$product_id])){
|
1721 |
-
$discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type, $variations->get_price());
|
1722 |
-
if($discountPrice > 0){
|
1723 |
-
$price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($discountPrice) : woocommerce_price($discountPrice);
|
1724 |
-
$item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins>';
|
1725 |
-
}
|
1726 |
-
}
|
1727 |
-
}
|
1728 |
-
|
1729 |
-
$data['price_html'] = $item_price;
|
1730 |
-
return $data;
|
1731 |
-
}
|
1732 |
-
|
1733 |
-
/**
|
1734 |
-
* Replace visible price if rule matches
|
1735 |
-
* */
|
1736 |
-
public function replaceVisiblePrices($item_price, $product)
|
1737 |
-
{
|
1738 |
-
// Get settings
|
1739 |
-
$config = new woo_dicount_rules_WooDiscountBase();
|
1740 |
-
$config = $config->getBaseConfig();
|
1741 |
-
if (is_string($config)) $config = json_decode($config, true);
|
1742 |
-
if(isset($config['price_setup'])){
|
1743 |
-
$type = $config['price_setup'];
|
1744 |
-
} else {
|
1745 |
-
$type = 'all';
|
1746 |
-
}
|
1747 |
-
$notAdmin = !is_admin();
|
1748 |
-
if(isset($config['show_price_discount_on_product_page'])){
|
1749 |
-
$show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
|
1750 |
-
} else {
|
1751 |
-
$show_price_discount_on_product_page = 'dont';
|
1752 |
-
}
|
1753 |
-
if($show_price_discount_on_product_page == 'show' && $notAdmin){
|
1754 |
-
$product_id = $product->get_id();
|
1755 |
-
$item['product_id'] = $product_id;
|
1756 |
-
$item['data'] = $product;
|
1757 |
-
$item['quantity'] = 1;
|
1758 |
-
global $woocommerce;
|
1759 |
-
$this->analyse($woocommerce);
|
1760 |
-
$this->matchRules($product_id, $item);
|
1761 |
-
|
1762 |
-
if(isset($this->matched_sets[$product_id])){
|
1763 |
-
$discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type);
|
1764 |
-
if($discountPrice > 0){
|
1765 |
-
$price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($discountPrice) : woocommerce_price($discountPrice);
|
1766 |
-
$item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins></span>';
|
1767 |
-
}
|
1768 |
-
}
|
1769 |
-
}
|
1770 |
-
|
1771 |
-
return $item_price;
|
1772 |
-
}
|
1773 |
-
|
1774 |
-
/**
|
1775 |
-
* get discounted value
|
1776 |
-
* */
|
1777 |
-
public function getAdjustmentDiscountedPrice($cart_item, $cart_item_key, $type, $price = 0)
|
1778 |
-
{
|
1779 |
-
// All Sets are Collected properly, just process with that.
|
1780 |
-
if (!isset($cart_item)) return false;
|
1781 |
-
|
1782 |
-
// If Product having the rule sets then,
|
1783 |
-
if (!isset($this->matched_sets[$cart_item_key])) return false;
|
1784 |
-
|
1785 |
-
$adjustment_set = $this->matched_sets[$cart_item_key];
|
1786 |
-
if(!($price > 0)){
|
1787 |
-
$price = $cart_item->get_price();
|
1788 |
-
}
|
1789 |
-
|
1790 |
-
$amount = 0;
|
1791 |
-
$discount = 0;
|
1792 |
-
if ($type == 'first') {
|
1793 |
-
// For Apply the First Rule.
|
1794 |
-
$discount = $this->getAmount($adjustment_set, $price, 'first');
|
1795 |
-
|
1796 |
-
} else if ($type == 'biggest') {
|
1797 |
-
// For Apply the Biggest Discount.
|
1798 |
-
$discount = $this->getAmount($adjustment_set, $price, 'biggest');
|
1799 |
-
} else {
|
1800 |
-
// For Apply All Rules.
|
1801 |
-
$discount = $this->getAmount($adjustment_set, $price);
|
1802 |
-
}
|
1803 |
-
if($discount > 0){
|
1804 |
-
$amount = $price - $discount;
|
1805 |
-
}
|
1806 |
-
|
1807 |
-
return $amount;
|
1808 |
-
}
|
1809 |
-
}
|
1810 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/pricing-rules.php
CHANGED
@@ -4,10 +4,10 @@ include_once(WOO_DISCOUNT_DIR . '/helper/general-helper.php');
|
|
4 |
include_once(WOO_DISCOUNT_DIR . '/includes/pricing-productbased.php');
|
5 |
|
6 |
/**
|
7 |
-
* Class
|
8 |
*/
|
9 |
-
if (!class_exists('
|
10 |
-
class
|
11 |
{
|
12 |
/**
|
13 |
* @var string
|
@@ -57,7 +57,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
57 |
public $postData;
|
58 |
|
59 |
/**
|
60 |
-
*
|
61 |
*/
|
62 |
public function __construct()
|
63 |
{
|
@@ -70,11 +70,11 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
70 |
*/
|
71 |
public function updateBaseConfig()
|
72 |
{
|
73 |
-
$base = new
|
74 |
$base = $base->getBaseConfig();
|
75 |
if (is_string($base)) $base = json_decode($base, true);
|
76 |
$this->baseConfig = $base;
|
77 |
-
$this->apply_to = (isset($
|
78 |
}
|
79 |
|
80 |
/**
|
@@ -167,6 +167,19 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
167 |
$apply_to = 'product_to_apply';
|
168 |
}
|
169 |
$form[] = $apply_to;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
171 |
|
172 |
$form[] = 'user_roles_to_apply';
|
@@ -186,24 +199,11 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
186 |
|
187 |
//----------------------------------------------------------------------------------------------------------
|
188 |
|
189 |
-
// Manage Users.
|
190 |
-
$apply_to = 'all';
|
191 |
-
|
192 |
-
if (isset($request['customer'])) $apply_to = $request['customer'];
|
193 |
-
|
194 |
-
if ($apply_to == 'only_given') {
|
195 |
-
$apply_to = 'users_to_apply';
|
196 |
-
}
|
197 |
-
$form[] = $apply_to;
|
198 |
-
|
199 |
-
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
200 |
-
//----------------------------------------------------------------------------------------------------------
|
201 |
-
|
202 |
// Manage list of Discount Ranges.
|
203 |
if (isset($request['discount_range'])) {
|
204 |
|
205 |
foreach ($request['discount_range'] as $index => $value) {
|
206 |
-
$request['discount_range'][$index] =
|
207 |
$request['discount_range'][$index]['title'] = isset($request['rule_name']) ? $request['rule_name'] : '';
|
208 |
|
209 |
}
|
@@ -213,7 +213,6 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
213 |
// Reset the Discount Range, if its empty.
|
214 |
$request['discount_range'] = '';
|
215 |
}
|
216 |
-
|
217 |
if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
|
218 |
$request['product_based_condition'] = json_encode($request['product_based_condition']);
|
219 |
$request['product_based_discount'] = json_encode($request['product_based_discount']);
|
@@ -423,79 +422,105 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
423 |
$cart_contents = $this->sortCartPrice($woocommerce->cart->cart_contents, 'asc');
|
424 |
|
425 |
//to handle buy one get one
|
426 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
|
428 |
-
|
|
|
|
|
|
|
429 |
$postData = \FlycartInput\FInput::getInstance();
|
430 |
$empty_apply_coupon = $postData->get('apply_coupon');
|
431 |
$empty_update_cart = $postData->get('update_cart');
|
432 |
$empty_proceed = $postData->get('proceed');
|
433 |
$runFreeProduct = (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) ? false : true;
|
434 |
-
|
435 |
-
$quantity_exists = array();
|
436 |
if(!empty($free_products) && $runFreeProduct){
|
437 |
//check if product already in cart
|
438 |
-
|
|
|
439 |
foreach ($free_products as $productId => $free_product_detail) {
|
440 |
-
$
|
441 |
-
|
442 |
-
|
443 |
-
$
|
444 |
-
|
445 |
-
|
446 |
-
$_quantity = $values['quantity'];
|
447 |
-
$_cart_item_key = $cart_item_key;
|
448 |
-
$found = true;
|
449 |
-
}
|
450 |
}
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
$
|
455 |
-
|
456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
}
|
458 |
}
|
459 |
}
|
460 |
}
|
461 |
}
|
462 |
-
|
463 |
-
|
464 |
-
foreach ($cart_contents as $index => $item) {
|
465 |
-
$this->matchRules($index, $item);
|
466 |
-
}
|
467 |
|
468 |
-
|
|
|
|
|
|
|
469 |
$free_products = WC()->session->get('woo_discount_rules_get_free_product', array());
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
if(!empty($free_products) && $runFreeProduct){
|
471 |
//check if product already in cart
|
472 |
-
|
|
|
473 |
foreach ($free_products as $productId => $free_product_detail) {
|
474 |
-
WC()->cart->add_to_cart($productId, $free_product_detail['count']);
|
475 |
$found = false;
|
476 |
-
foreach (
|
477 |
$_product = $values['data'];
|
478 |
-
$_product_id = $_product
|
479 |
-
if(isset($_product->variation_id)) $_product_id = $_product->variation_id;
|
480 |
if ($_product_id == $productId){
|
481 |
-
$
|
482 |
-
$
|
483 |
-
$
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
}
|
490 |
-
$this->matched_sets[$cart_item_key] = $freeProductRule;
|
491 |
}
|
492 |
}
|
493 |
}
|
494 |
-
|
495 |
}
|
496 |
}
|
497 |
-
|
498 |
-
$
|
499 |
}
|
500 |
|
501 |
/**
|
@@ -564,8 +589,6 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
564 |
}
|
565 |
}
|
566 |
|
567 |
-
// Default setup for all customers.
|
568 |
-
$rule_sets[$index]['allow']['users'] = 'all';
|
569 |
// If Rule is processed by Specific Customers, then..
|
570 |
if ($rule->customer == 'only_given') {
|
571 |
if (isset($rule->users_to_apply)) {
|
@@ -598,10 +621,13 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
598 |
$this->rule_sets = $rule_sets;
|
599 |
}
|
600 |
|
|
|
|
|
|
|
601 |
public function checkWithUserRoles($rule){
|
602 |
$user_roles_to_apply = json_decode($rule->user_roles_to_apply, true);
|
603 |
if(!empty($user_roles_to_apply)){
|
604 |
-
if (get_current_user_id() == 0 || count(array_intersect(
|
605 |
return false;
|
606 |
}
|
607 |
}
|
@@ -629,8 +655,8 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
629 |
$totalPurchasedAmount = 0;
|
630 |
if(!empty($customerOrders)){
|
631 |
foreach ($customerOrders as $customerOrder) {
|
632 |
-
$order = wc_get_order($customerOrder->ID);
|
633 |
-
$total = $order
|
634 |
$totalPurchasedAmount += $total;
|
635 |
}
|
636 |
}
|
@@ -665,13 +691,37 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
665 |
return $category_with_sub_cat;
|
666 |
}
|
667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
668 |
/**
|
669 |
* Fetch back the Matched rules.
|
670 |
*
|
671 |
* @param $index
|
672 |
* @param array $item line item.
|
673 |
*/
|
674 |
-
public function matchRules($index, $item)
|
675 |
{
|
676 |
$applied_rules = array();
|
677 |
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
@@ -685,15 +735,10 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
685 |
switch ($rule['apply_to']) {
|
686 |
|
687 |
case 'specific_products':
|
688 |
-
|
689 |
if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
|
690 |
-
$
|
691 |
-
$applied_rules[$i]['name']
|
692 |
-
$applied_rules[$i]['item'] = $index;
|
693 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
694 |
-
$applied_rules[$i]['rule_order'] = $id;
|
695 |
}
|
696 |
-
|
697 |
break;
|
698 |
|
699 |
case 'specific_category':
|
@@ -722,25 +767,16 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
722 |
}
|
723 |
}
|
724 |
if(!$alreadyExists){
|
725 |
-
$
|
726 |
-
$applied_rules[$i]['name']
|
727 |
-
$applied_rules[$i]['item'] = $index;
|
728 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
729 |
-
$applied_rules[$i]['rule_order'] = $id;
|
730 |
}
|
731 |
}
|
732 |
-
|
733 |
-
|
734 |
break;
|
735 |
|
736 |
case 'all_products':
|
737 |
default:
|
738 |
-
|
739 |
-
$applied_rules[$i]
|
740 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
741 |
-
$applied_rules[$i]['item'] = $index;
|
742 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
743 |
-
|
744 |
break;
|
745 |
}
|
746 |
if(isset($applied_rules[$i]['amount']['product_ids'])){
|
@@ -749,19 +785,12 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
749 |
$applyPercent = $applied_rules[$i]['amount'];
|
750 |
$applied_rules = array();
|
751 |
foreach ($applyToProducts as $key => $productId) {
|
752 |
-
|
|
|
753 |
$_product = $values['data'];
|
754 |
-
$
|
755 |
-
|
756 |
-
|
757 |
-
$applied_rules_new = array();
|
758 |
-
$applied_rules_new['amount'] = $applyPercent;
|
759 |
-
$applied_rules_new['name'] = $rule['name'];
|
760 |
-
$applied_rules_new['item'] = $cart_item_key;
|
761 |
-
$applied_rules_new['id'] = $productId;
|
762 |
-
$applied_rules_new['rule_order'] = $id;
|
763 |
-
$applied_rules_new['apply_from'] = $item['product_id'];
|
764 |
-
$this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
765 |
}
|
766 |
}
|
767 |
}
|
@@ -772,33 +801,34 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
772 |
$checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
|
773 |
if(!empty($checkRuleMatches)){
|
774 |
foreach ($checkRuleMatches['apply_to']['products'] as $key => $productId) {
|
775 |
-
|
776 |
-
$
|
777 |
-
$
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
$
|
783 |
-
$
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
}
|
794 |
}
|
|
|
795 |
}
|
796 |
-
if(!$alreadyExists) $this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
797 |
}
|
798 |
}
|
799 |
}
|
800 |
}
|
801 |
}
|
|
|
802 |
$i++;
|
803 |
}
|
804 |
if(isset($this->matched_sets[$index]) && !empty($this->matched_sets[$index])){
|
@@ -825,38 +855,33 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
825 |
$product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
|
826 |
$discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
827 |
$discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
|
|
828 |
$_quantity = array();
|
829 |
-
if ( sizeof(
|
830 |
foreach ($product_to_buy as $key => $productId) {
|
831 |
-
foreach (
|
832 |
$_product = $values['data'];
|
833 |
-
$
|
834 |
-
if(isset($_product->variation_id)) $_product_id = $_product->variation_id;
|
835 |
-
if ($_product_id == $productId){
|
836 |
$_quantity[$productId] = $values['quantity'];
|
837 |
}
|
838 |
}
|
839 |
}
|
840 |
}
|
841 |
-
|
842 |
-
$
|
843 |
-
if(in_array($item['product_id'], $product_to_buy) && !empty($_quantity)){
|
844 |
$proceed = 1;
|
845 |
if($buy_type == 'each'){
|
846 |
$allProductsInCart = array_keys($_quantity);
|
847 |
$matchedProducts = array_intersect($allProductsInCart, $product_to_buy);
|
848 |
-
if(count($product_to_buy) != count($matchedProducts))
|
849 |
-
$proceed = 0;
|
850 |
-
}
|
851 |
}
|
852 |
if($proceed){
|
853 |
-
$quantityMatched =
|
854 |
if($quantityMatched){
|
855 |
$result['amount'][$discount_type] = $discount_value;
|
856 |
$result['apply_to']['products'] = $product_to_apply;
|
857 |
}
|
858 |
}
|
859 |
-
|
860 |
}
|
861 |
}
|
862 |
return $result;
|
@@ -913,7 +938,6 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
913 |
{
|
914 |
$adjustment = array();
|
915 |
foreach($discount_ranges as $discount_range) {
|
916 |
-
|
917 |
if (!is_array($discount_range) && !is_object($discount_range)) return false;
|
918 |
$range = is_array($discount_range) ? (object) $discount_range : $discount_range;
|
919 |
$min = (isset($range->min_qty) ? $range->min_qty : 0);
|
@@ -953,9 +977,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
953 |
$adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
|
954 |
}
|
955 |
}
|
956 |
-
|
957 |
}
|
958 |
-
|
959 |
return $adjustment;
|
960 |
}
|
961 |
|
@@ -965,17 +987,18 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
965 |
public function getCheapestProductFromCart($products){
|
966 |
if(empty($products)) return array();
|
967 |
$cheapestProductValue = 0;
|
968 |
-
|
|
|
969 |
$_product = $values['data'];
|
970 |
-
$productId =
|
971 |
if(in_array($productId, $products)){
|
972 |
if($cheapestProductValue == 0){
|
973 |
-
$cheapestProductValue = $_product
|
974 |
-
$cheapestProduct = $_product
|
975 |
$quantity = $values['quantity'];
|
976 |
-
} else if($cheapestProductValue > $_product
|
977 |
-
$cheapestProductValue = $_product
|
978 |
-
$cheapestProduct = $_product
|
979 |
$quantity = $values['quantity'];
|
980 |
}
|
981 |
}
|
@@ -988,11 +1011,6 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
988 |
return array();
|
989 |
}
|
990 |
|
991 |
-
public function getProductIdFromCartProduct($product){
|
992 |
-
$id = $product->id;
|
993 |
-
return $id;
|
994 |
-
}
|
995 |
-
|
996 |
/**
|
997 |
* Validating the Active user with rule sets.
|
998 |
*
|
@@ -1049,10 +1067,10 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1049 |
public function isItemInCategoryList($category_list, $product)
|
1050 |
{
|
1051 |
|
1052 |
-
$helper = new
|
1053 |
$all_category = $helper->getCategoryList();
|
1054 |
if (!isset($product['product_id'])) return false;
|
1055 |
-
$product_category =
|
1056 |
|
1057 |
$status = false;
|
1058 |
//check any one of category matches
|
@@ -1105,11 +1123,11 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1105 |
public function sortCartByPrice_asc($first, $second)
|
1106 |
{
|
1107 |
if (isset($first['data'])) {
|
1108 |
-
if ($first['data']
|
1109 |
return 0;
|
1110 |
}
|
1111 |
}
|
1112 |
-
return ($first['data']
|
1113 |
}
|
1114 |
|
1115 |
/**
|
@@ -1123,11 +1141,11 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1123 |
public function sortCartByPrice_desc($first, $second)
|
1124 |
{
|
1125 |
if (isset($first['data'])) {
|
1126 |
-
if ($first['data']
|
1127 |
return 0;
|
1128 |
}
|
1129 |
}
|
1130 |
-
return ($first['data']
|
1131 |
}
|
1132 |
|
1133 |
/**
|
@@ -1211,10 +1229,29 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1211 |
// If Only allowed to display, then only its display the table.
|
1212 |
if ($show_discount) {
|
1213 |
$table_data = $this->generateDiscountTableData($product);
|
|
|
1214 |
$path = WOO_DISCOUNT_DIR . '/view/template/discount-table.php';
|
1215 |
-
|
|
|
|
|
|
|
1216 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1217 |
|
|
|
1218 |
}
|
1219 |
|
1220 |
/**
|
@@ -1226,13 +1263,15 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1226 |
public function generateDiscountTableData($product)
|
1227 |
{
|
1228 |
global $product;
|
1229 |
-
|
|
|
|
|
1230 |
if ($id == 0) return false;
|
1231 |
|
1232 |
$this->organizeRules();
|
1233 |
|
1234 |
$discount_range = array();
|
1235 |
-
if(is_array($this->rules) && count($this->rules) > 0){
|
1236 |
foreach ($this->rules as $index => $rule) {
|
1237 |
$status = false;
|
1238 |
if(isset($rule->rule_method) && $rule->rule_method == 'qty_based'){
|
@@ -1243,6 +1282,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1243 |
$status = true;
|
1244 |
} else {
|
1245 |
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
|
|
1246 |
$user_id = get_current_user_id();
|
1247 |
if (count(array_intersect($users, array($user_id))) > 0) {
|
1248 |
$status = true;
|
@@ -1262,33 +1302,40 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1262 |
if (in_array($id, $products_to_apply)) {
|
1263 |
$status = true;
|
1264 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1265 |
}
|
1266 |
} elseif ($rule->apply_to == 'specific_category') {
|
1267 |
-
|
1268 |
// Check with Product Category Filter.
|
1269 |
-
$category =
|
1270 |
|
1271 |
if ($rule->category_to_apply == null) $status = true;
|
1272 |
|
1273 |
if ($rule->category_to_apply != null) {
|
1274 |
$category_to_apply = json_decode($rule->category_to_apply);
|
1275 |
-
if(isset($rule->apply_child_categories) && $rule->apply_child_categories == 1){
|
1276 |
$category_to_apply = $this->getAllSubCategories($category_to_apply);
|
1277 |
}
|
1278 |
-
|
1279 |
$status = false;
|
1280 |
if (count(array_intersect($category_to_apply, $category)) > 0) {
|
1281 |
$status = true;
|
1282 |
}
|
1283 |
}
|
1284 |
-
|
1285 |
} else if ($rule->apply_to == 'all_products') {
|
1286 |
$status = true;
|
1287 |
}
|
1288 |
|
1289 |
// check for user roles
|
1290 |
if(isset($rule->user_roles_to_apply)){
|
1291 |
-
$
|
|
|
|
|
|
|
1292 |
}
|
1293 |
|
1294 |
if ($status) {
|
@@ -1312,8 +1359,10 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1312 |
$discount_range[][] = $newTableContent;
|
1313 |
}
|
1314 |
}
|
|
|
1315 |
}
|
1316 |
}
|
|
|
1317 |
return $discount_range;
|
1318 |
}
|
1319 |
|
@@ -1339,7 +1388,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1339 |
break;
|
1340 |
case 'more':
|
1341 |
default:
|
1342 |
-
|
1343 |
}
|
1344 |
|
1345 |
switch ($product_buy_type) {
|
@@ -1359,20 +1408,20 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1359 |
}
|
1360 |
break;
|
1361 |
}
|
1362 |
-
if(count($product_to_buy)
|
1363 |
$htmlProduct = '';
|
1364 |
foreach ($product_to_buy as $product_id){
|
1365 |
-
$product = wc_get_product(
|
1366 |
-
$htmlProduct .= '<a href="'
|
1367 |
}
|
1368 |
-
$condition .= ' '.trim($htmlProduct, ',').' ';
|
1369 |
}
|
1370 |
$condition .= esc_html__(' and get discount in ', 'woo-discount-rules');
|
1371 |
if(count($product_to_apply)){
|
1372 |
$htmlProduct = '';
|
1373 |
foreach ($product_to_apply as $product_id){
|
1374 |
-
$product = wc_get_product(
|
1375 |
-
$htmlProduct .= '<a href="'
|
1376 |
}
|
1377 |
$condition .= trim($htmlProduct, ', ');
|
1378 |
}
|
@@ -1391,37 +1440,20 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1391 |
//ob_start();
|
1392 |
if (!isset($table_data)) return false;
|
1393 |
if (!isset($path) || empty($path) || is_null($path)) return false;
|
1394 |
-
|
1395 |
$data = $this->getBaseConfig();
|
1396 |
-
|
|
|
1397 |
//$html = ob_get_contents();
|
1398 |
-
|
1399 |
//ob_get_clean();
|
1400 |
-
$html = $this->getDiscountTableContentInHTML($table_data, $data);
|
1401 |
-
return $html;
|
1402 |
}
|
1403 |
|
1404 |
/**
|
1405 |
* get Discount table content in html
|
1406 |
* */
|
1407 |
private function getDiscountTableContentInHTML($table_data, $data){
|
1408 |
-
$
|
1409 |
-
if (!isset($table_data) || empty($table_data)) return false;
|
1410 |
-
$base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : array());
|
1411 |
-
$html .= '<table>';
|
1412 |
-
$html .= '<thead>';
|
1413 |
-
$html .= '<tr>';
|
1414 |
-
if (isset($base_config['show_discount_title_table'])) {
|
1415 |
-
if ($base_config['show_discount_title_table'] == 'show') {
|
1416 |
-
$html .= '<td>'.esc_html__('Name', 'woo-discount-rules').'</td>';
|
1417 |
-
}
|
1418 |
-
}
|
1419 |
-
$html .= '<td>'.esc_html__('Range', 'woo-discount-rules').'</td>';
|
1420 |
-
$html .= '<td>'.esc_html__('Discount', 'woo-discount-rules').'</td>';
|
1421 |
-
$html .= '</tr>
|
1422 |
-
</thead>
|
1423 |
-
<tbody>';
|
1424 |
-
$have_discount = false;
|
1425 |
$table = $table_data;
|
1426 |
foreach ($table as $index => $item) {
|
1427 |
if ($item) {
|
@@ -1432,7 +1464,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1432 |
if ($value->discount_type == 'percentage_discount') {
|
1433 |
$discount = $value->to_discount.' %';
|
1434 |
} else {
|
1435 |
-
$discount = wc_price($value->to_discount);
|
1436 |
}
|
1437 |
} else {
|
1438 |
$title = isset($value->title) ? $value->title : '';
|
@@ -1450,37 +1482,26 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1450 |
if(count($product_discount)){
|
1451 |
$htmlProduct = '';
|
1452 |
foreach ($product_discount as $product_id){
|
1453 |
-
$product = wc_get_product(
|
1454 |
-
$htmlProduct .= $product
|
1455 |
-
$htmlProduct .= ' ('
|
1456 |
}
|
1457 |
$discount = trim($htmlProduct, '<br>');
|
1458 |
}
|
1459 |
} else if ($discount_type == 'percentage_discount') {
|
1460 |
$discount = $to_discount.' %';
|
1461 |
} else {
|
1462 |
-
$discount = wc_price($to_discount);
|
1463 |
}
|
1464 |
|
1465 |
}
|
1466 |
-
$
|
1467 |
-
|
1468 |
-
|
1469 |
-
}
|
1470 |
-
$html .= '<td>'.$condition.'</td>';
|
1471 |
-
$html .= '<td>'.$discount.'</td>';
|
1472 |
-
$html .= '</tr>';
|
1473 |
}
|
1474 |
-
$have_discount = true;
|
1475 |
}
|
1476 |
}
|
1477 |
-
|
1478 |
-
$html .= '<tr><td colspan="2">'.esc_html__('No Active Discounts.', 'woo-discount-rules').'</td></tr>';
|
1479 |
-
}
|
1480 |
-
$html .= '</tbody>';
|
1481 |
-
$html .= '</table>';
|
1482 |
-
|
1483 |
-
return $html;
|
1484 |
}
|
1485 |
|
1486 |
/**
|
@@ -1493,7 +1514,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1493 |
global $woocommerce;
|
1494 |
|
1495 |
// Get settings
|
1496 |
-
$config = new
|
1497 |
$config = $config->getBaseConfig();
|
1498 |
if (is_string($config)) $config = json_decode($config, true);
|
1499 |
if(isset($config['price_setup'])){
|
@@ -1528,8 +1549,8 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1528 |
if (!isset($this->matched_sets[$cart_item_key])) return false;
|
1529 |
|
1530 |
$adjustment_set = $this->matched_sets[$cart_item_key];
|
1531 |
-
|
1532 |
-
$price = $
|
1533 |
|
1534 |
if ($type == 'first') {
|
1535 |
// For Apply the First Rule.
|
@@ -1645,10 +1666,10 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1645 |
if (!isset($woocommerce->cart->cart_contents[$item])) {
|
1646 |
return;
|
1647 |
}
|
1648 |
-
|
1649 |
// Log changes
|
1650 |
$woocommerce->cart->cart_contents[$item]['woo_discount'] = array(
|
1651 |
-
'original_price' => get_option('woocommerce_tax_display_cart') == 'excl' ?
|
1652 |
'log' => $log,
|
1653 |
);
|
1654 |
|
@@ -1662,7 +1683,8 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1662 |
}
|
1663 |
|
1664 |
// Actually adjust price in cart
|
1665 |
-
$woocommerce->cart->cart_contents[$item]['data']->price = $amount;
|
|
|
1666 |
|
1667 |
}
|
1668 |
|
@@ -1682,13 +1704,13 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1682 |
}
|
1683 |
|
1684 |
// Get price to display
|
1685 |
-
$price = get_option('woocommerce_tax_display_cart') == 'excl' ? $cart_item['data']
|
1686 |
|
1687 |
// Format price to display
|
1688 |
-
$price_to_display =
|
1689 |
-
$original_price_to_display =
|
1690 |
|
1691 |
-
if ($cart_item['woo_discount']['original_price']
|
1692 |
$item_price = '<span class="cart_price"><del>' . $original_price_to_display . '</del> <ins>' . $price_to_display . '</ins></span>';
|
1693 |
} else {
|
1694 |
$item_price = $price_to_display;
|
@@ -1702,9 +1724,11 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1702 |
* */
|
1703 |
public function replaceVisiblePricesForVariant($data, $product, $variations)
|
1704 |
{
|
|
|
|
|
|
|
1705 |
$item_price = $data['price_html'];
|
1706 |
-
|
1707 |
-
$config = new woo_dicount_rules_WooDiscountBase();
|
1708 |
$config = $config->getBaseConfig();
|
1709 |
if (is_string($config)) $config = json_decode($config, true);
|
1710 |
if(isset($config['price_setup'])){
|
@@ -1719,18 +1743,18 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1719 |
$show_price_discount_on_product_page = 'dont';
|
1720 |
}
|
1721 |
if($show_price_discount_on_product_page == 'show' && $notAdmin){
|
1722 |
-
$product_id = $product
|
1723 |
$item['product_id'] = $product_id;
|
1724 |
$item['data'] = $product;
|
1725 |
-
$item['quantity'] = 1;
|
1726 |
global $woocommerce;
|
1727 |
$this->analyse($woocommerce);
|
1728 |
-
$this->matchRules($product_id, $item);
|
1729 |
|
1730 |
if(isset($this->matched_sets[$product_id])){
|
1731 |
-
$discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type, $variations
|
1732 |
if($discountPrice > 0){
|
1733 |
-
$price_to_display =
|
1734 |
$item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins>';
|
1735 |
}
|
1736 |
}
|
@@ -1746,7 +1770,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1746 |
public function replaceVisiblePrices($item_price, $product)
|
1747 |
{
|
1748 |
// Get settings
|
1749 |
-
$config = new
|
1750 |
$config = $config->getBaseConfig();
|
1751 |
if (is_string($config)) $config = json_decode($config, true);
|
1752 |
if(isset($config['price_setup'])){
|
@@ -1761,18 +1785,18 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1761 |
$show_price_discount_on_product_page = 'dont';
|
1762 |
}
|
1763 |
if($show_price_discount_on_product_page == 'show' && $notAdmin){
|
1764 |
-
$product_id = $product
|
1765 |
$item['product_id'] = $product_id;
|
1766 |
$item['data'] = $product;
|
1767 |
-
$item['quantity'] = 1;
|
1768 |
global $woocommerce;
|
1769 |
$this->analyse($woocommerce);
|
1770 |
-
$this->matchRules($product_id, $item);
|
1771 |
|
1772 |
if(isset($this->matched_sets[$product_id])){
|
1773 |
$discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type);
|
1774 |
if($discountPrice > 0){
|
1775 |
-
$price_to_display =
|
1776 |
$item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins></span>';
|
1777 |
}
|
1778 |
}
|
@@ -1781,6 +1805,21 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1781 |
return $item_price;
|
1782 |
}
|
1783 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1784 |
/**
|
1785 |
* get discounted value
|
1786 |
* */
|
@@ -1794,7 +1833,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1794 |
|
1795 |
$adjustment_set = $this->matched_sets[$cart_item_key];
|
1796 |
if(!($price > 0)){
|
1797 |
-
$price = $cart_item
|
1798 |
}
|
1799 |
|
1800 |
$amount = 0;
|
4 |
include_once(WOO_DISCOUNT_DIR . '/includes/pricing-productbased.php');
|
5 |
|
6 |
/**
|
7 |
+
* Class FlycartWooDiscountRulesPricingRules
|
8 |
*/
|
9 |
+
if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
|
10 |
+
class FlycartWooDiscountRulesPricingRules
|
11 |
{
|
12 |
/**
|
13 |
* @var string
|
57 |
public $postData;
|
58 |
|
59 |
/**
|
60 |
+
* FlycartWooDiscountRulesPricingRules constructor.
|
61 |
*/
|
62 |
public function __construct()
|
63 |
{
|
70 |
*/
|
71 |
public function updateBaseConfig()
|
72 |
{
|
73 |
+
$base = new FlycartWooDiscountBase();
|
74 |
$base = $base->getBaseConfig();
|
75 |
if (is_string($base)) $base = json_decode($base, true);
|
76 |
$this->baseConfig = $base;
|
77 |
+
$this->apply_to = (isset($this->baseConfig['price_setup']) ? $this->baseConfig['price_setup'] : 'all');
|
78 |
}
|
79 |
|
80 |
/**
|
167 |
$apply_to = 'product_to_apply';
|
168 |
}
|
169 |
$form[] = $apply_to;
|
170 |
+
|
171 |
+
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
172 |
+
//----------------------------------------------------------------------------------------------------------
|
173 |
+
|
174 |
+
// Manage Users.
|
175 |
+
$apply_to = 'all';
|
176 |
+
|
177 |
+
if (isset($request['customer'])) $apply_to = $request['customer'];
|
178 |
+
|
179 |
+
if ($apply_to == 'only_given') {
|
180 |
+
$apply_to = 'users_to_apply';
|
181 |
+
}
|
182 |
+
$form[] = $apply_to;
|
183 |
if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
|
184 |
|
185 |
$form[] = 'user_roles_to_apply';
|
199 |
|
200 |
//----------------------------------------------------------------------------------------------------------
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
// Manage list of Discount Ranges.
|
203 |
if (isset($request['discount_range'])) {
|
204 |
|
205 |
foreach ($request['discount_range'] as $index => $value) {
|
206 |
+
$request['discount_range'][$index] = FlycartWooDiscountRulesGeneralHelper::makeString($value);
|
207 |
$request['discount_range'][$index]['title'] = isset($request['rule_name']) ? $request['rule_name'] : '';
|
208 |
|
209 |
}
|
213 |
// Reset the Discount Range, if its empty.
|
214 |
$request['discount_range'] = '';
|
215 |
}
|
|
|
216 |
if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
|
217 |
$request['product_based_condition'] = json_encode($request['product_based_condition']);
|
218 |
$request['product_based_discount'] = json_encode($request['product_based_discount']);
|
422 |
$cart_contents = $this->sortCartPrice($woocommerce->cart->cart_contents, 'asc');
|
423 |
|
424 |
//to handle buy one get one
|
425 |
+
$free_product_quantity_exists = $this->reduceCartItemQuantityIfFreeProductExistsAlready();
|
426 |
+
|
427 |
+
foreach ($cart_contents as $index => $item) {
|
428 |
+
$this->matchRules($index, $item);
|
429 |
+
}
|
430 |
+
|
431 |
+
//to handle buy one get one
|
432 |
+
$this->applyDiscountForFreeProduct($free_product_quantity_exists);
|
433 |
+
|
434 |
+
$this->makeLog();
|
435 |
+
}
|
436 |
|
437 |
+
/**
|
438 |
+
* apply the discount for Free product
|
439 |
+
* */
|
440 |
+
public function applyDiscountForFreeProduct($quantity_exists){
|
441 |
$postData = \FlycartInput\FInput::getInstance();
|
442 |
$empty_apply_coupon = $postData->get('apply_coupon');
|
443 |
$empty_update_cart = $postData->get('update_cart');
|
444 |
$empty_proceed = $postData->get('proceed');
|
445 |
$runFreeProduct = (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) ? false : true;
|
446 |
+
$free_products = WC()->session->get('woo_discount_rules_get_free_product', array());
|
|
|
447 |
if(!empty($free_products) && $runFreeProduct){
|
448 |
//check if product already in cart
|
449 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
450 |
+
if ( sizeof( $cart ) > 0 ) {
|
451 |
foreach ($free_products as $productId => $free_product_detail) {
|
452 |
+
$product = FlycartWoocommerceProduct::wc_get_product($productId);
|
453 |
+
$productParentId = FlycartWoocommerceProduct::get_parent_id($product);
|
454 |
+
if($productParentId){
|
455 |
+
FlycartWoocommerceCart::add_to_cart($productParentId, $free_product_detail['count'], $productId, FlycartWoocommerceProduct::get_attributes($product));
|
456 |
+
} else {
|
457 |
+
FlycartWoocommerceCart::add_to_cart($productId, $free_product_detail['count']);
|
|
|
|
|
|
|
|
|
458 |
}
|
459 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
460 |
+
foreach ($cart as $cart_item_key => $values) {
|
461 |
+
$_product = $values['data'];
|
462 |
+
if (FlycartWoocommerceProduct::get_id($_product) == $productId){
|
463 |
+
$discountAmount = array('price_discount' => FlycartWoocommerceProduct::get_price($_product));
|
464 |
+
if(isset($quantity_exists[$productId]) && $quantity_exists[$productId] > 0){
|
465 |
+
$price = FlycartWoocommerceProduct::get_price($_product);
|
466 |
+
//discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
|
467 |
+
$discount_price = $price - (($price/($quantity_exists[$productId]+$free_product_detail['count'])) * $quantity_exists[$productId]);
|
468 |
+
$discountAmount = array('price_discount' => $discount_price);
|
469 |
+
}
|
470 |
+
$freeProductRule[0] = $this->formatRulesToApply($discountAmount, $free_product_detail['rule_name'], $cart_item_key, FlycartWoocommerceProduct::get_id($_product));
|
471 |
+
$this->matched_sets[$cart_item_key] = $freeProductRule;
|
472 |
}
|
473 |
}
|
474 |
}
|
475 |
}
|
476 |
}
|
477 |
+
}
|
|
|
|
|
|
|
|
|
478 |
|
479 |
+
/**
|
480 |
+
* Reduce the Cart item quantity if free product already exists
|
481 |
+
* */
|
482 |
+
public function reduceCartItemQuantityIfFreeProductExistsAlready(){
|
483 |
$free_products = WC()->session->get('woo_discount_rules_get_free_product', array());
|
484 |
+
$postData = \FlycartInput\FInput::getInstance();
|
485 |
+
$empty_apply_coupon = $postData->get('apply_coupon');
|
486 |
+
$empty_update_cart = $postData->get('update_cart');
|
487 |
+
$empty_proceed = $postData->get('proceed');
|
488 |
+
$runFreeProduct = (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) ? false : true;
|
489 |
+
$quantity_exists = array();
|
490 |
if(!empty($free_products) && $runFreeProduct){
|
491 |
//check if product already in cart
|
492 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
493 |
+
if ( sizeof($cart) > 0 ) {
|
494 |
foreach ($free_products as $productId => $free_product_detail) {
|
|
|
495 |
$found = false;
|
496 |
+
foreach ($cart as $cart_item_key => $values) {
|
497 |
$_product = $values['data'];
|
498 |
+
$_product_id = FlycartWoocommerceProduct::get_id($_product);
|
|
|
499 |
if ($_product_id == $productId){
|
500 |
+
$_quantity = $values['quantity'];
|
501 |
+
$_cart_item_key = $cart_item_key;
|
502 |
+
$found = true;
|
503 |
+
}
|
504 |
+
}
|
505 |
+
// if product found, add it
|
506 |
+
if ($found) {
|
507 |
+
FlycartWoocommerceCart::remove_cart_item($_cart_item_key);
|
508 |
+
$quantity_exists[$productId] = $_quantity-$free_product_detail['count'];
|
509 |
+
if($quantity_exists[$productId] > 0){
|
510 |
+
$product = FlycartWoocommerceProduct::wc_get_product($productId);
|
511 |
+
$productParentId = FlycartWoocommerceProduct::get_parent_id($product);
|
512 |
+
if($productParentId){
|
513 |
+
FlycartWoocommerceCart::add_to_cart($productParentId, $quantity_exists[$productId], $productId, FlycartWoocommerceProduct::get_attributes($product));
|
514 |
+
} else {
|
515 |
+
FlycartWoocommerceCart::add_to_cart($productId, $quantity_exists[$productId]);
|
516 |
}
|
|
|
517 |
}
|
518 |
}
|
519 |
}
|
|
|
520 |
}
|
521 |
}
|
522 |
+
WC()->session->set('woo_discount_rules_get_free_product', array());
|
523 |
+
return $quantity_exists;
|
524 |
}
|
525 |
|
526 |
/**
|
589 |
}
|
590 |
}
|
591 |
|
|
|
|
|
592 |
// If Rule is processed by Specific Customers, then..
|
593 |
if ($rule->customer == 'only_given') {
|
594 |
if (isset($rule->users_to_apply)) {
|
621 |
$this->rule_sets = $rule_sets;
|
622 |
}
|
623 |
|
624 |
+
/**
|
625 |
+
* Check with users roles
|
626 |
+
* */
|
627 |
public function checkWithUserRoles($rule){
|
628 |
$user_roles_to_apply = json_decode($rule->user_roles_to_apply, true);
|
629 |
if(!empty($user_roles_to_apply)){
|
630 |
+
if (get_current_user_id() == 0 || count(array_intersect(FlycartWooDiscountRulesGeneralHelper::getCurrentUserRoles(), $user_roles_to_apply)) == 0) {
|
631 |
return false;
|
632 |
}
|
633 |
}
|
655 |
$totalPurchasedAmount = 0;
|
656 |
if(!empty($customerOrders)){
|
657 |
foreach ($customerOrders as $customerOrder) {
|
658 |
+
$order = FlycartWoocommerceOrder::wc_get_order($customerOrder->ID);
|
659 |
+
$total = FlycartWoocommerceOrder::get_total($order);
|
660 |
$totalPurchasedAmount += $total;
|
661 |
}
|
662 |
}
|
691 |
return $category_with_sub_cat;
|
692 |
}
|
693 |
|
694 |
+
/**
|
695 |
+
* To format rules to apply
|
696 |
+
*
|
697 |
+
* @param array $discount_amount
|
698 |
+
* @param string $rule_name
|
699 |
+
* @param string $cart_key
|
700 |
+
* @param int $product_id
|
701 |
+
* @param int $rule_order
|
702 |
+
* @param array $additional_keys
|
703 |
+
* @return array
|
704 |
+
* */
|
705 |
+
public function formatRulesToApply($discount_amount, $rule_name, $cart_key, $product_id, $rule_order = 0, $additional_keys = array()){
|
706 |
+
$toApply = array();
|
707 |
+
$toApply['amount'] = $discount_amount;
|
708 |
+
$toApply['name'] = $rule_name;
|
709 |
+
$toApply['item'] = $cart_key;
|
710 |
+
$toApply['id'] = $product_id;
|
711 |
+
if($rule_order)
|
712 |
+
$toApply['rule_order'] = $rule_order;
|
713 |
+
if(!empty($additional_keys)) foreach ($additional_keys as $key => $additional_key) $toApply[$key] = $additional_key;
|
714 |
+
|
715 |
+
return $toApply;
|
716 |
+
}
|
717 |
+
|
718 |
/**
|
719 |
* Fetch back the Matched rules.
|
720 |
*
|
721 |
* @param $index
|
722 |
* @param array $item line item.
|
723 |
*/
|
724 |
+
public function matchRules($index, $item, $product_page = 0)
|
725 |
{
|
726 |
$applied_rules = array();
|
727 |
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
735 |
switch ($rule['apply_to']) {
|
736 |
|
737 |
case 'specific_products':
|
|
|
738 |
if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
|
739 |
+
$discount_amount = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
740 |
+
$applied_rules[$i] = $this->formatRulesToApply($discount_amount, $rule['name'], $index, $item['product_id'], $id);
|
|
|
|
|
|
|
741 |
}
|
|
|
742 |
break;
|
743 |
|
744 |
case 'specific_category':
|
767 |
}
|
768 |
}
|
769 |
if(!$alreadyExists){
|
770 |
+
$discount_amount = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
771 |
+
$applied_rules[$i] = $this->formatRulesToApply($discount_amount, $rule['name'], $index, $item['product_id'], $id);
|
|
|
|
|
|
|
772 |
}
|
773 |
}
|
|
|
|
|
774 |
break;
|
775 |
|
776 |
case 'all_products':
|
777 |
default:
|
778 |
+
$discount_amount = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
779 |
+
$applied_rules[$i] = $this->formatRulesToApply($discount_amount, $rule['name'], $index, $item['product_id'], $id);
|
|
|
|
|
|
|
|
|
780 |
break;
|
781 |
}
|
782 |
if(isset($applied_rules[$i]['amount']['product_ids'])){
|
785 |
$applyPercent = $applied_rules[$i]['amount'];
|
786 |
$applied_rules = array();
|
787 |
foreach ($applyToProducts as $key => $productId) {
|
788 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
789 |
+
foreach ($cart as $cart_item_key => $values) {
|
790 |
$_product = $values['data'];
|
791 |
+
if (FlycartWoocommerceProduct::get_id($_product) == $productId){
|
792 |
+
$additionalKeys = array('apply_from' => $item['product_id']);
|
793 |
+
$this->matched_sets[$cart_item_key][] = $this->formatRulesToApply($applyPercent, $rule['name'], $cart_item_key, $productId, $id, $additionalKeys);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
794 |
}
|
795 |
}
|
796 |
}
|
801 |
$checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
|
802 |
if(!empty($checkRuleMatches)){
|
803 |
foreach ($checkRuleMatches['apply_to']['products'] as $key => $productId) {
|
804 |
+
if($product_page && $productId == $index){
|
805 |
+
$additionalKeys = array('apply_from' => $item['product_id']);
|
806 |
+
$applied_rules_new = $this->formatRulesToApply($checkRuleMatches['amount'], $rule['name'], $index, $productId, $id, $additionalKeys);
|
807 |
+
$this->matched_sets[$index][] = $applied_rules_new;
|
808 |
+
} else {
|
809 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
810 |
+
foreach ($cart as $cart_item_key => $values) {
|
811 |
+
$_product = $values['data'];
|
812 |
+
if (FlycartWoocommerceProduct::get_id($_product) == $productId){
|
813 |
+
$additionalKeys = array('apply_from' => $item['product_id']);
|
814 |
+
$applied_rules_new = $this->formatRulesToApply($checkRuleMatches['amount'], $rule['name'], $cart_item_key, $productId, $id, $additionalKeys);
|
815 |
+
$alreadyExists = 0;
|
816 |
+
if(!empty($this->matched_sets[$cart_item_key])){
|
817 |
+
foreach($this->matched_sets[$cart_item_key] as $machedRules){
|
818 |
+
if(isset($machedRules['rule_order']) && $machedRules['rule_order'] == $id){
|
819 |
+
$alreadyExists = 1;
|
820 |
+
break;
|
821 |
+
}
|
822 |
}
|
823 |
}
|
824 |
+
if(!$alreadyExists) $this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
825 |
}
|
|
|
826 |
}
|
827 |
}
|
828 |
}
|
829 |
}
|
830 |
}
|
831 |
+
|
832 |
$i++;
|
833 |
}
|
834 |
if(isset($this->matched_sets[$index]) && !empty($this->matched_sets[$index])){
|
855 |
$product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
|
856 |
$discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
857 |
$discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
858 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
859 |
$_quantity = array();
|
860 |
+
if ( sizeof( $cart ) > 0 ) {
|
861 |
foreach ($product_to_buy as $key => $productId) {
|
862 |
+
foreach ($cart as $cart_item_key => $values) {
|
863 |
$_product = $values['data'];
|
864 |
+
if (FlycartWoocommerceProduct::get_id($_product) == $productId){
|
|
|
|
|
865 |
$_quantity[$productId] = $values['quantity'];
|
866 |
}
|
867 |
}
|
868 |
}
|
869 |
}
|
870 |
+
$quantity = FlycartWooDiscountRulesPriceProductBased::adjustQuantity($buy_type, $_quantity);
|
871 |
+
if((in_array($item['product_id'], $product_to_buy) || in_array($item['product_id'], $product_to_apply)) && !empty($_quantity)){
|
|
|
872 |
$proceed = 1;
|
873 |
if($buy_type == 'each'){
|
874 |
$allProductsInCart = array_keys($_quantity);
|
875 |
$matchedProducts = array_intersect($allProductsInCart, $product_to_buy);
|
876 |
+
if(count($product_to_buy) != count($matchedProducts)) $proceed = 0;
|
|
|
|
|
877 |
}
|
878 |
if($proceed){
|
879 |
+
$quantityMatched = FlycartWooDiscountRulesPriceProductBased::verifyQuantity($quantity_rule, $quantity, $quantity_from, $quantity_to, $buy_type);
|
880 |
if($quantityMatched){
|
881 |
$result['amount'][$discount_type] = $discount_value;
|
882 |
$result['apply_to']['products'] = $product_to_apply;
|
883 |
}
|
884 |
}
|
|
|
885 |
}
|
886 |
}
|
887 |
return $result;
|
938 |
{
|
939 |
$adjustment = array();
|
940 |
foreach($discount_ranges as $discount_range) {
|
|
|
941 |
if (!is_array($discount_range) && !is_object($discount_range)) return false;
|
942 |
$range = is_array($discount_range) ? (object) $discount_range : $discount_range;
|
943 |
$min = (isset($range->min_qty) ? $range->min_qty : 0);
|
977 |
$adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
|
978 |
}
|
979 |
}
|
|
|
980 |
}
|
|
|
981 |
return $adjustment;
|
982 |
}
|
983 |
|
987 |
public function getCheapestProductFromCart($products){
|
988 |
if(empty($products)) return array();
|
989 |
$cheapestProductValue = 0;
|
990 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
991 |
+
foreach ($cart as $cart_item_key => $values) {
|
992 |
$_product = $values['data'];
|
993 |
+
$productId = FlycartWoocommerceProduct::get_id($_product);
|
994 |
if(in_array($productId, $products)){
|
995 |
if($cheapestProductValue == 0){
|
996 |
+
$cheapestProductValue = FlycartWoocommerceProduct::get_price($_product);
|
997 |
+
$cheapestProduct = FlycartWoocommerceProduct::get_id($_product);
|
998 |
$quantity = $values['quantity'];
|
999 |
+
} else if($cheapestProductValue > FlycartWoocommerceProduct::get_price($_product)){
|
1000 |
+
$cheapestProductValue = FlycartWoocommerceProduct::get_price($_product);
|
1001 |
+
$cheapestProduct = FlycartWoocommerceProduct::get_id($_product);
|
1002 |
$quantity = $values['quantity'];
|
1003 |
}
|
1004 |
}
|
1011 |
return array();
|
1012 |
}
|
1013 |
|
|
|
|
|
|
|
|
|
|
|
1014 |
/**
|
1015 |
* Validating the Active user with rule sets.
|
1016 |
*
|
1067 |
public function isItemInCategoryList($category_list, $product)
|
1068 |
{
|
1069 |
|
1070 |
+
$helper = new FlycartWooDiscountRulesGeneralHelper();
|
1071 |
$all_category = $helper->getCategoryList();
|
1072 |
if (!isset($product['product_id'])) return false;
|
1073 |
+
$product_category = FlycartWooDiscountRulesGeneralHelper::getCategoryByPost($product);
|
1074 |
|
1075 |
$status = false;
|
1076 |
//check any one of category matches
|
1123 |
public function sortCartByPrice_asc($first, $second)
|
1124 |
{
|
1125 |
if (isset($first['data'])) {
|
1126 |
+
if (FlycartWoocommerceProduct::get_price($first['data']) == FlycartWoocommerceProduct::get_price($second['data'])) {
|
1127 |
return 0;
|
1128 |
}
|
1129 |
}
|
1130 |
+
return (FlycartWoocommerceProduct::get_price($first['data']) < FlycartWoocommerceProduct::get_price($second['data'])) ? -1 : 1;
|
1131 |
}
|
1132 |
|
1133 |
/**
|
1141 |
public function sortCartByPrice_desc($first, $second)
|
1142 |
{
|
1143 |
if (isset($first['data'])) {
|
1144 |
+
if (FlycartWoocommerceProduct::get_price($first['data']) == FlycartWoocommerceProduct::get_price($second['data'])) {
|
1145 |
return 0;
|
1146 |
}
|
1147 |
}
|
1148 |
+
return (FlycartWoocommerceProduct::get_price($first['data']) > FlycartWoocommerceProduct::get_price($second['data'])) ? -1 : 1;
|
1149 |
}
|
1150 |
|
1151 |
/**
|
1229 |
// If Only allowed to display, then only its display the table.
|
1230 |
if ($show_discount) {
|
1231 |
$table_data = $this->generateDiscountTableData($product);
|
1232 |
+
$path_from_template = $this->getTemplateOverride('discount-table.php');
|
1233 |
$path = WOO_DISCOUNT_DIR . '/view/template/discount-table.php';
|
1234 |
+
if($path_from_template){
|
1235 |
+
$path = $path_from_template;
|
1236 |
+
}
|
1237 |
+
$this->generateTableHtml($table_data, $path);
|
1238 |
}
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
/**
|
1242 |
+
* Get template override
|
1243 |
+
* @param string $template_name
|
1244 |
+
* @return string
|
1245 |
+
* */
|
1246 |
+
public function getTemplateOverride($template_name){
|
1247 |
+
$template = locate_template(
|
1248 |
+
array(
|
1249 |
+
trailingslashit( dirname(WOO_DISCOUNT_PLUGIN_BASENAME) ) . $template_name,
|
1250 |
+
$template_name,
|
1251 |
+
)
|
1252 |
+
);
|
1253 |
|
1254 |
+
return $template;
|
1255 |
}
|
1256 |
|
1257 |
/**
|
1263 |
public function generateDiscountTableData($product)
|
1264 |
{
|
1265 |
global $product;
|
1266 |
+
if(empty($product)) return false;
|
1267 |
+
$product_id = FlycartWoocommerceProduct::get_id($product);
|
1268 |
+
$id = (($product_id != 0 && $product_id != null) ? $product_id : 0);
|
1269 |
if ($id == 0) return false;
|
1270 |
|
1271 |
$this->organizeRules();
|
1272 |
|
1273 |
$discount_range = array();
|
1274 |
+
if(is_array($this->rules) && count($this->rules) > 0) {
|
1275 |
foreach ($this->rules as $index => $rule) {
|
1276 |
$status = false;
|
1277 |
if(isset($rule->rule_method) && $rule->rule_method == 'qty_based'){
|
1282 |
$status = true;
|
1283 |
} else {
|
1284 |
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
1285 |
+
if(empty($users)) $users = array();
|
1286 |
$user_id = get_current_user_id();
|
1287 |
if (count(array_intersect($users, array($user_id))) > 0) {
|
1288 |
$status = true;
|
1302 |
if (in_array($id, $products_to_apply)) {
|
1303 |
$status = true;
|
1304 |
}
|
1305 |
+
$variations = FlycartWoocommerceProduct::get_variant_ids($product_id);
|
1306 |
+
if(!empty($variations)){
|
1307 |
+
if (count(array_intersect($variations, $products_to_apply)) > 0) {
|
1308 |
+
$status = true;
|
1309 |
+
}
|
1310 |
+
}
|
1311 |
}
|
1312 |
} elseif ($rule->apply_to == 'specific_category') {
|
|
|
1313 |
// Check with Product Category Filter.
|
1314 |
+
$category = FlycartWooDiscountRulesGeneralHelper::getCategoryByPost($id, true);
|
1315 |
|
1316 |
if ($rule->category_to_apply == null) $status = true;
|
1317 |
|
1318 |
if ($rule->category_to_apply != null) {
|
1319 |
$category_to_apply = json_decode($rule->category_to_apply);
|
1320 |
+
if (isset($rule->apply_child_categories) && $rule->apply_child_categories == 1) {
|
1321 |
$category_to_apply = $this->getAllSubCategories($category_to_apply);
|
1322 |
}
|
1323 |
+
FlycartWooDiscountRulesGeneralHelper::toInt($category_to_apply);
|
1324 |
$status = false;
|
1325 |
if (count(array_intersect($category_to_apply, $category)) > 0) {
|
1326 |
$status = true;
|
1327 |
}
|
1328 |
}
|
|
|
1329 |
} else if ($rule->apply_to == 'all_products') {
|
1330 |
$status = true;
|
1331 |
}
|
1332 |
|
1333 |
// check for user roles
|
1334 |
if(isset($rule->user_roles_to_apply)){
|
1335 |
+
$statusRoles = $this->checkWithUserRoles($rule);
|
1336 |
+
if($statusRoles === false){
|
1337 |
+
$status = false;
|
1338 |
+
}
|
1339 |
}
|
1340 |
|
1341 |
if ($status) {
|
1359 |
$discount_range[][] = $newTableContent;
|
1360 |
}
|
1361 |
}
|
1362 |
+
|
1363 |
}
|
1364 |
}
|
1365 |
+
|
1366 |
return $discount_range;
|
1367 |
}
|
1368 |
|
1388 |
break;
|
1389 |
case 'more':
|
1390 |
default:
|
1391 |
+
$quantity_text = ' '.$product_quantity_from.esc_html__(' or more Quantity', 'woo-discount-rules');
|
1392 |
}
|
1393 |
|
1394 |
switch ($product_buy_type) {
|
1408 |
}
|
1409 |
break;
|
1410 |
}
|
1411 |
+
if(count($product_to_buy)){
|
1412 |
$htmlProduct = '';
|
1413 |
foreach ($product_to_buy as $product_id){
|
1414 |
+
$product = FlycartWoocommerceProduct::wc_get_product($product_id);
|
1415 |
+
$htmlProduct .= '<a href="'.FlycartWoocommerceProduct::get_permalink($product).'">'.FlycartWoocommerceProduct::get_title($product).'</a>, ';
|
1416 |
}
|
1417 |
+
$condition .= ' '.trim($htmlProduct, ', ').' ';
|
1418 |
}
|
1419 |
$condition .= esc_html__(' and get discount in ', 'woo-discount-rules');
|
1420 |
if(count($product_to_apply)){
|
1421 |
$htmlProduct = '';
|
1422 |
foreach ($product_to_apply as $product_id){
|
1423 |
+
$product = FlycartWoocommerceProduct::wc_get_product($product_id);
|
1424 |
+
$htmlProduct .= '<a href="'.FlycartWoocommerceProduct::get_permalink($product).'">'.FlycartWoocommerceProduct::get_title($product).'</a>, ';
|
1425 |
}
|
1426 |
$condition .= trim($htmlProduct, ', ');
|
1427 |
}
|
1440 |
//ob_start();
|
1441 |
if (!isset($table_data)) return false;
|
1442 |
if (!isset($path) || empty($path) || is_null($path)) return false;
|
1443 |
+
if (!file_exists($path)) return false;
|
1444 |
$data = $this->getBaseConfig();
|
1445 |
+
$table_data_content = $this->getDiscountTableContentInHTML($table_data, $data);
|
1446 |
+
include($path);
|
1447 |
//$html = ob_get_contents();
|
1448 |
+
// ob_clean();
|
1449 |
//ob_get_clean();
|
|
|
|
|
1450 |
}
|
1451 |
|
1452 |
/**
|
1453 |
* get Discount table content in html
|
1454 |
* */
|
1455 |
private function getDiscountTableContentInHTML($table_data, $data){
|
1456 |
+
$dataReturn = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1457 |
$table = $table_data;
|
1458 |
foreach ($table as $index => $item) {
|
1459 |
if ($item) {
|
1464 |
if ($value->discount_type == 'percentage_discount') {
|
1465 |
$discount = $value->to_discount.' %';
|
1466 |
} else {
|
1467 |
+
$discount = FlycartWoocommerceProduct::wc_price($value->to_discount);
|
1468 |
}
|
1469 |
} else {
|
1470 |
$title = isset($value->title) ? $value->title : '';
|
1482 |
if(count($product_discount)){
|
1483 |
$htmlProduct = '';
|
1484 |
foreach ($product_discount as $product_id){
|
1485 |
+
$product = FlycartWoocommerceProduct::wc_get_product($product_id);
|
1486 |
+
$htmlProduct .= FlycartWoocommerceProduct::get_title($product);
|
1487 |
+
$htmlProduct .= ' ('.FlycartWoocommerceProduct::get_price_html($product).')<br>';
|
1488 |
}
|
1489 |
$discount = trim($htmlProduct, '<br>');
|
1490 |
}
|
1491 |
} else if ($discount_type == 'percentage_discount') {
|
1492 |
$discount = $to_discount.' %';
|
1493 |
} else {
|
1494 |
+
$discount = FlycartWoocommerceProduct::wc_price($to_discount);
|
1495 |
}
|
1496 |
|
1497 |
}
|
1498 |
+
$dataReturn[$id]['title'] = $title;
|
1499 |
+
$dataReturn[$id]['condition'] = $condition;
|
1500 |
+
$dataReturn[$id]['discount'] = $discount;
|
|
|
|
|
|
|
|
|
1501 |
}
|
|
|
1502 |
}
|
1503 |
}
|
1504 |
+
return $dataReturn;
|
|
|
|
|
|
|
|
|
|
|
|
|
1505 |
}
|
1506 |
|
1507 |
/**
|
1514 |
global $woocommerce;
|
1515 |
|
1516 |
// Get settings
|
1517 |
+
$config = new FlycartWooDiscountBase();
|
1518 |
$config = $config->getBaseConfig();
|
1519 |
if (is_string($config)) $config = json_decode($config, true);
|
1520 |
if(isset($config['price_setup'])){
|
1549 |
if (!isset($this->matched_sets[$cart_item_key])) return false;
|
1550 |
|
1551 |
$adjustment_set = $this->matched_sets[$cart_item_key];
|
1552 |
+
$product = $woocommerce->cart->cart_contents[$cart_item_key]['data'];
|
1553 |
+
$price = FlycartWoocommerceProduct::get_price($product);
|
1554 |
|
1555 |
if ($type == 'first') {
|
1556 |
// For Apply the First Rule.
|
1666 |
if (!isset($woocommerce->cart->cart_contents[$item])) {
|
1667 |
return;
|
1668 |
}
|
1669 |
+
$product = $woocommerce->cart->cart_contents[$item]['data'];
|
1670 |
// Log changes
|
1671 |
$woocommerce->cart->cart_contents[$item]['woo_discount'] = array(
|
1672 |
+
'original_price' => get_option('woocommerce_tax_display_cart') == 'excl' ? FlycartWoocommerceProduct::get_price_excluding_tax($product) : FlycartWoocommerceProduct::get_price_including_tax($product),
|
1673 |
'log' => $log,
|
1674 |
);
|
1675 |
|
1683 |
}
|
1684 |
|
1685 |
// Actually adjust price in cart
|
1686 |
+
// $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
|
1687 |
+
FlycartWoocommerceProduct::set_price($product, $amount);
|
1688 |
|
1689 |
}
|
1690 |
|
1704 |
}
|
1705 |
|
1706 |
// Get price to display
|
1707 |
+
$price = get_option('woocommerce_tax_display_cart') == 'excl' ? FlycartWoocommerceProduct::get_price_excluding_tax($cart_item['data']) : FlycartWoocommerceProduct::get_price_including_tax($cart_item['data']);
|
1708 |
|
1709 |
// Format price to display
|
1710 |
+
$price_to_display = FlycartWoocommerceProduct::wc_price($price);
|
1711 |
+
$original_price_to_display = FlycartWoocommerceProduct::wc_price($cart_item['woo_discount']['original_price']);;
|
1712 |
|
1713 |
+
if ($cart_item['woo_discount']['original_price'] != $price) {
|
1714 |
$item_price = '<span class="cart_price"><del>' . $original_price_to_display . '</del> <ins>' . $price_to_display . '</ins></span>';
|
1715 |
} else {
|
1716 |
$item_price = $price_to_display;
|
1724 |
* */
|
1725 |
public function replaceVisiblePricesForVariant($data, $product, $variations)
|
1726 |
{
|
1727 |
+
if(FlycartWoocommerceVersion::wcVersion('3.0')){
|
1728 |
+
return $data;
|
1729 |
+
}
|
1730 |
$item_price = $data['price_html'];
|
1731 |
+
$config = new FlycartWooDiscountBase();
|
|
|
1732 |
$config = $config->getBaseConfig();
|
1733 |
if (is_string($config)) $config = json_decode($config, true);
|
1734 |
if(isset($config['price_setup'])){
|
1743 |
$show_price_discount_on_product_page = 'dont';
|
1744 |
}
|
1745 |
if($show_price_discount_on_product_page == 'show' && $notAdmin){
|
1746 |
+
$product_id = FlycartWoocommerceProduct::get_id($product);
|
1747 |
$item['product_id'] = $product_id;
|
1748 |
$item['data'] = $product;
|
1749 |
+
$item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
|
1750 |
global $woocommerce;
|
1751 |
$this->analyse($woocommerce);
|
1752 |
+
$this->matchRules($product_id, $item, 1);
|
1753 |
|
1754 |
if(isset($this->matched_sets[$product_id])){
|
1755 |
+
$discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type, FlycartWoocommerceProduct::get_price($variations));
|
1756 |
if($discountPrice > 0){
|
1757 |
+
$price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
|
1758 |
$item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins>';
|
1759 |
}
|
1760 |
}
|
1770 |
public function replaceVisiblePrices($item_price, $product)
|
1771 |
{
|
1772 |
// Get settings
|
1773 |
+
$config = new FlycartWooDiscountBase();
|
1774 |
$config = $config->getBaseConfig();
|
1775 |
if (is_string($config)) $config = json_decode($config, true);
|
1776 |
if(isset($config['price_setup'])){
|
1785 |
$show_price_discount_on_product_page = 'dont';
|
1786 |
}
|
1787 |
if($show_price_discount_on_product_page == 'show' && $notAdmin){
|
1788 |
+
$product_id = FlycartWoocommerceProduct::get_id($product);
|
1789 |
$item['product_id'] = $product_id;
|
1790 |
$item['data'] = $product;
|
1791 |
+
$item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
|
1792 |
global $woocommerce;
|
1793 |
$this->analyse($woocommerce);
|
1794 |
+
$this->matchRules($product_id, $item, 1);
|
1795 |
|
1796 |
if(isset($this->matched_sets[$product_id])){
|
1797 |
$discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type);
|
1798 |
if($discountPrice > 0){
|
1799 |
+
$price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
|
1800 |
$item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins></span>';
|
1801 |
}
|
1802 |
}
|
1805 |
return $item_price;
|
1806 |
}
|
1807 |
|
1808 |
+
/**
|
1809 |
+
* Get Quantity of product in cart
|
1810 |
+
* */
|
1811 |
+
protected function getQuantityOfProductInCart($productId){
|
1812 |
+
$qty = 0;
|
1813 |
+
$cart = FlycartWoocommerceCart::get_cart();
|
1814 |
+
foreach ( $cart as $cart_item ) {
|
1815 |
+
if($cart_item['product_id'] == $productId ){
|
1816 |
+
$qty = $cart_item['quantity'];
|
1817 |
+
break; // stop the loop if product is found
|
1818 |
+
}
|
1819 |
+
}
|
1820 |
+
return $qty;
|
1821 |
+
}
|
1822 |
+
|
1823 |
/**
|
1824 |
* get discounted value
|
1825 |
* */
|
1833 |
|
1834 |
$adjustment_set = $this->matched_sets[$cart_item_key];
|
1835 |
if(!($price > 0)){
|
1836 |
+
$price = FlycartWoocommerceProduct::get_price($cart_item);
|
1837 |
}
|
1838 |
|
1839 |
$amount = 0;
|
loader.php
CHANGED
@@ -1,18 +1,16 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
|
4 |
-
/**
|
5 |
-
* Required Version of WooCommerce to Run.
|
6 |
-
*/
|
7 |
-
define('WOO_DISCOUNT_REQUIRED_WOOCOMMERCE_VERSION', '3.5');
|
8 |
/**
|
9 |
* Plugin Directory.
|
10 |
*/
|
11 |
define('WOO_DISCOUNT_DIR', untrailingslashit(plugin_dir_path(__FILE__)));
|
|
|
12 |
/**
|
13 |
* Plugin Directory URI.
|
14 |
*/
|
15 |
define('WOO_DISCOUNT_URI', untrailingslashit(plugin_dir_url(__FILE__)));
|
|
|
16 |
/**
|
17 |
* Plugin Base Name.
|
18 |
*/
|
@@ -21,230 +19,144 @@ define('WOO_DISCOUNT_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
|
21 |
if(!function_exists('get_plugin_data')){
|
22 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
23 |
}
|
|
|
24 |
/**
|
25 |
* Version of Woo Discount Rules.
|
26 |
*/
|
27 |
$pluginDetails = get_plugin_data(plugin_dir_path(__FILE__).'woo-discount-rules.php');
|
28 |
define('WOO_DISCOUNT_VERSION', $pluginDetails['Version']);
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
*/
|
33 |
-
if (!function_exists('woo_discount_checkWooCommerceVersion3')) {
|
34 |
-
function woo_discount_checkWooCommerceVersion3($version = "3.0")
|
35 |
-
{
|
36 |
-
// If get_plugins() isn't available, require it
|
37 |
-
if ( ! function_exists( 'get_plugins' ) )
|
38 |
-
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
39 |
-
|
40 |
-
// Create the plugins folder and file variables
|
41 |
-
$plugin_folder = get_plugins( '/' . 'woocommerce' );
|
42 |
-
$plugin_file = 'woocommerce.php';
|
43 |
-
|
44 |
-
// If the plugin version number is set, return it
|
45 |
-
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
|
46 |
-
$woocommerce_version = $plugin_folder[$plugin_file]['Version'];
|
47 |
-
|
48 |
-
} else {
|
49 |
-
// Otherwise return null
|
50 |
-
$woocommerce_version = null;
|
51 |
-
}
|
52 |
-
|
53 |
-
if( version_compare( $woocommerce_version, $version, ">=" ) ) {
|
54 |
-
return true;
|
55 |
-
}
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
$woocommerce_v3 = woo_discount_checkWooCommerceVersion3();
|
61 |
-
if($woocommerce_v3){
|
62 |
-
include_once('includes/pricing-rules-3.php');
|
63 |
-
include_once('helper/general-helper-3.php');
|
64 |
-
include_once('includes/cart-rules-3.php');
|
65 |
-
} else {
|
66 |
-
include_once('includes/pricing-rules.php');
|
67 |
-
include_once('helper/general-helper.php');
|
68 |
-
include_once('includes/cart-rules.php');
|
69 |
-
}
|
70 |
-
include_once('includes/discount-base.php');
|
71 |
-
include_once('helper/purchase.php');
|
72 |
-
require_once __DIR__ . '/vendor/autoload.php';
|
73 |
-
|
74 |
-
// -------------------------- updater -----------------------------------------------------
|
75 |
-
try{
|
76 |
-
require plugin_dir_path( __FILE__ ).'/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
|
77 |
-
|
78 |
-
$purchase_helper = new woo_dicount_rules_purchase();
|
79 |
-
$purchase_helper->init();
|
80 |
-
$update_url = $purchase_helper->getUpdateURL();
|
81 |
-
|
82 |
-
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
83 |
-
$update_url,
|
84 |
-
plugin_dir_path( __FILE__ ).'woo-discount-rules.php',
|
85 |
-
'woo-discount-rules'
|
86 |
-
);
|
87 |
-
add_action( 'after_plugin_row', array($purchase_helper, 'woodisc_after_plugin_row'),10,3 );
|
88 |
-
|
89 |
-
add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey'));
|
90 |
-
|
91 |
-
add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages'));
|
92 |
-
} catch (Exception $e){}
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
// -------------------------- end updater -------------------------------------------------
|
97 |
-
|
98 |
-
|
99 |
-
// --------------------------------------------------GENERAL HOOK-------------------------------------------------------
|
100 |
-
|
101 |
-
/** Initiating Plugin */
|
102 |
-
$discountBase = new woo_dicount_rules_WooDiscountBase();
|
103 |
-
$pricingRules = new woo_dicount_rules_pricingRules();
|
104 |
-
|
105 |
-
// Enqueue Scripts/Styles - in head of admin page
|
106 |
-
add_action('admin_enqueue_scripts', 'woo_discount_addHeadScript');
|
107 |
-
// Init in Admin Menu
|
108 |
-
add_action('admin_menu', array($discountBase, 'adminMenu'));
|
109 |
-
|
110 |
-
$postData = \FlycartInput\FInput::getInstance();
|
111 |
-
// ---------------------------------------------------------------------------------------------------------------------
|
112 |
-
|
113 |
-
|
114 |
-
// --------------------------------------------------WOO DISCOUNT HOOK--------------------------------------------------
|
115 |
-
|
116 |
-
|
117 |
-
// ---------------------------------------------------------------------------------------------------------------------
|
118 |
|
|
|
|
|
|
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
} else if (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) {
|
130 |
-
// add_action('woocommerce_before_cart_item_quantity_zero', array($discountBase, 'handleDiscount'), 100);
|
131 |
-
add_action('woocommerce_after_cart_item_quantity_update', array($discountBase, 'handleDiscount'), 100);
|
132 |
-
|
133 |
-
// add_action('woocommerce_update_cart_action_cart_updated', array($discountBase, 'handleDiscount'));
|
134 |
-
} else {
|
135 |
-
add_action('woocommerce_cart_loaded_from_session', array($discountBase, 'handleDiscount'), 100);
|
136 |
-
}
|
137 |
-
|
138 |
-
// Manually Update Line Item Name.
|
139 |
-
add_filter('woocommerce_cart_item_name', array($discountBase, 'modifyName'));
|
140 |
-
|
141 |
-
// Remove Filter to make the previous one as last filter.
|
142 |
-
remove_filter('woocommerce_cart_item_name', 'filter_woocommerce_cart_item_name', 10, 3);
|
143 |
-
|
144 |
-
// Alter the Display Price HTML.
|
145 |
-
add_filter('woocommerce_cart_item_price', array($pricingRules, 'replaceVisiblePricesCart'), 100, 3);
|
146 |
-
|
147 |
-
//replace visible price in product page
|
148 |
-
add_filter('woocommerce_get_price_html', array($pricingRules, 'replaceVisiblePrices'), 100, 3);
|
149 |
-
//replace visible price in product page for variant
|
150 |
-
add_filter('woocommerce_available_variation', array($pricingRules, 'replaceVisiblePricesForVariant'), 100, 3);
|
151 |
-
|
152 |
-
|
153 |
-
// Older Version support this hook.
|
154 |
-
add_filter('woocommerce_cart_item_price_html', array($pricingRules, 'replaceVisiblePricesCart'), 100, 3);
|
155 |
-
|
156 |
-
// Pricing Table of Individual Product.
|
157 |
-
add_filter('woocommerce_before_add_to_cart_form', array($pricingRules, 'priceTable'));
|
158 |
-
|
159 |
-
// Updating Log After Creating Order
|
160 |
-
add_action('woocommerce_thankyou', array($discountBase, 'storeLog'));
|
161 |
-
// ---------------------------------------------------------------------------------------------------------------------
|
162 |
-
|
163 |
-
// --------------------------------------------------AJAX REQUEST-------------------------------------------------------
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
-
|
|
|
|
|
175 |
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
-
|
179 |
-
* To Append Script Wordpress.
|
180 |
-
*/
|
181 |
-
if (!function_exists('woo_discount_addHeadScript')) {
|
182 |
-
function woo_discount_addHeadScript()
|
183 |
-
{
|
184 |
-
//
|
185 |
-
}
|
186 |
-
}
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
*/
|
191 |
-
if (!function_exists('woo_discount_adminPageScript')) {
|
192 |
-
function woo_discount_adminPageScript()
|
193 |
-
{
|
194 |
-
$status = false;
|
195 |
-
$postData = \FlycartInput\FInput::getInstance();
|
196 |
-
// Plugin scripts should run only in plugin page.
|
197 |
-
if (is_admin()) {
|
198 |
-
if ($postData->get('page', false) == 'woo_discount_rules') {
|
199 |
-
$status = true;
|
200 |
-
}
|
201 |
-
// By Default, the landing page also can use this script.
|
202 |
-
} elseif (!is_admin()) {
|
203 |
-
// $status = true;
|
204 |
}
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
|
|
|
|
222 |
|
223 |
-
//
|
|
|
224 |
|
225 |
-
|
226 |
-
|
227 |
|
228 |
-
|
229 |
-
|
|
|
|
|
230 |
|
231 |
-
wp_register_style('woo_discount_jquery_ui_css', WOO_DISCOUNT_URI . '/assets/css/jquery-ui.css', array(), WOO_DISCOUNT_VERSION);
|
232 |
-
wp_enqueue_style('woo_discount_jquery_ui_css');
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
wp_enqueue_script('jquery-ui-datepicker');
|
237 |
|
238 |
-
//
|
239 |
-
|
240 |
-
//
|
241 |
-
// wp_register_script('woo_discount_select2_js', WOO_DISCOUNT_URI . '/assets/js/select2.min.js');
|
242 |
-
// wp_enqueue_script('woo_discount_select2_js');
|
243 |
|
244 |
-
|
|
|
245 |
|
|
|
246 |
}
|
247 |
}
|
248 |
}
|
249 |
|
250 |
-
|
|
|
|
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
|
|
|
|
|
|
|
|
|
4 |
/**
|
5 |
* Plugin Directory.
|
6 |
*/
|
7 |
define('WOO_DISCOUNT_DIR', untrailingslashit(plugin_dir_path(__FILE__)));
|
8 |
+
|
9 |
/**
|
10 |
* Plugin Directory URI.
|
11 |
*/
|
12 |
define('WOO_DISCOUNT_URI', untrailingslashit(plugin_dir_url(__FILE__)));
|
13 |
+
|
14 |
/**
|
15 |
* Plugin Base Name.
|
16 |
*/
|
19 |
if(!function_exists('get_plugin_data')){
|
20 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
21 |
}
|
22 |
+
|
23 |
/**
|
24 |
* Version of Woo Discount Rules.
|
25 |
*/
|
26 |
$pluginDetails = get_plugin_data(plugin_dir_path(__FILE__).'woo-discount-rules.php');
|
27 |
define('WOO_DISCOUNT_VERSION', $pluginDetails['Version']);
|
28 |
|
29 |
+
if(!class_exists('FlycartWooDiscountRules')){
|
30 |
+
class FlycartWooDiscountRules{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
private static $instance;
|
33 |
+
public $discountBase;
|
34 |
+
public $pricingRules;
|
35 |
|
36 |
+
/**
|
37 |
+
* To run the plugin
|
38 |
+
* */
|
39 |
+
public static function init() {
|
40 |
+
if ( self::$instance == null ) {
|
41 |
+
self::$instance = new FlycartWooDiscountRules();
|
42 |
+
}
|
43 |
+
return self::$instance;
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
/**
|
47 |
+
* FlycartWooDiscountRules constructor
|
48 |
+
* */
|
49 |
+
public function __construct() {
|
50 |
+
$this->includeFiles();
|
51 |
+
$this->runUpdater();
|
52 |
+
$this->discountBase = new FlycartWooDiscountBase();
|
53 |
+
$this->pricingRules = new FlycartWooDiscountRulesPricingRules();
|
54 |
+
if (is_admin()) {
|
55 |
+
$this->loadAdminScripts();
|
56 |
+
} else {
|
57 |
+
$this->loadSiteScripts();
|
58 |
+
}
|
59 |
+
}
|
60 |
|
61 |
+
/**
|
62 |
+
* To include Files
|
63 |
+
* */
|
64 |
+
protected function includeFiles(){
|
65 |
+
include_once('helper/woo-function.php');
|
66 |
+
include_once('includes/pricing-rules.php');
|
67 |
+
include_once('helper/general-helper.php');
|
68 |
+
include_once('includes/cart-rules.php');
|
69 |
+
include_once('includes/discount-base.php');
|
70 |
+
include_once('helper/purchase.php');
|
71 |
+
require_once __DIR__ . '/vendor/autoload.php';
|
72 |
+
}
|
73 |
|
74 |
+
/**
|
75 |
+
* Run Plugin updater
|
76 |
+
* */
|
77 |
+
protected function runUpdater(){
|
78 |
+
try{
|
79 |
+
require plugin_dir_path( __FILE__ ).'/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
|
80 |
|
81 |
+
$purchase_helper = new FlycartWooDiscountRulesPurchase();
|
82 |
+
$purchase_helper->init();
|
83 |
+
$update_url = $purchase_helper->getUpdateURL();
|
84 |
|
85 |
+
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
86 |
+
$update_url,
|
87 |
+
plugin_dir_path( __FILE__ ).'woo-discount-rules.php',
|
88 |
+
'woo-discount-rules'
|
89 |
+
);
|
90 |
+
add_action( 'after_plugin_row', array($purchase_helper, 'woodisc_after_plugin_row'),10,3 );
|
91 |
|
92 |
+
add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
+
add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages'));
|
95 |
+
} catch (Exception $e){}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
|
98 |
+
/**
|
99 |
+
* Load Admin scripts
|
100 |
+
* */
|
101 |
+
protected function loadAdminScripts(){
|
102 |
+
// Init in Admin Menu
|
103 |
+
add_action('admin_menu', array($this->discountBase, 'adminMenu'));
|
104 |
+
add_action('wp_ajax_savePriceRule', array($this->discountBase, 'savePriceRule'));
|
105 |
+
add_action('wp_ajax_saveCartRule', array($this->discountBase, 'saveCartRule'));
|
106 |
+
add_action('wp_ajax_saveConfig', array($this->discountBase, 'saveConfig'));
|
107 |
+
|
108 |
+
add_action('wp_ajax_UpdateStatus', array($this->discountBase, 'updateStatus'));
|
109 |
+
add_action('wp_ajax_RemoveRule', array($this->discountBase, 'removeRule'));
|
110 |
+
}
|
111 |
|
112 |
+
/**
|
113 |
+
* Load Admin scripts
|
114 |
+
* */
|
115 |
+
protected function loadSiteScripts(){
|
116 |
+
$postData = \FlycartInput\FInput::getInstance();
|
117 |
+
// Handling Tight update with wooCommerce Changes.
|
118 |
+
$empty_add_to_cart = $postData->get('add-to-cart');
|
119 |
+
$empty_apply_coupon = $postData->get('apply_coupon');
|
120 |
+
$empty_update_cart = $postData->get('update_cart');
|
121 |
+
$empty_proceed = $postData->get('proceed');
|
122 |
+
if ((!empty($empty_add_to_cart) && is_numeric($postData->get('add-to-cart'))) || $postData->get('action', false) == 'woocommerce_add_to_cart') {
|
123 |
+
|
124 |
+
} else if (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) {
|
125 |
+
add_action('woocommerce_after_cart_item_quantity_update', array($this->discountBase, 'handleDiscount'), 100);
|
126 |
+
} else {
|
127 |
+
add_action('woocommerce_cart_loaded_from_session', array($this->discountBase, 'handleDiscount'), 100);
|
128 |
+
}
|
129 |
|
130 |
+
// Manually Update Line Item Name.
|
131 |
+
add_filter('woocommerce_cart_item_name', array($this->discountBase, 'modifyName'));
|
132 |
|
133 |
+
// Remove Filter to make the previous one as last filter.
|
134 |
+
remove_filter('woocommerce_cart_item_name', 'filter_woocommerce_cart_item_name', 10, 3);
|
135 |
|
136 |
+
// Alter the Display Price HTML.
|
137 |
+
add_filter('woocommerce_cart_item_price', array($this->pricingRules, 'replaceVisiblePricesCart'), 100, 3);
|
138 |
|
139 |
+
//replace visible price in product page
|
140 |
+
add_filter('woocommerce_get_price_html', array($this->pricingRules, 'replaceVisiblePrices'), 100, 3);
|
141 |
+
//replace visible price in product page for variant
|
142 |
+
add_filter('woocommerce_available_variation', array($this->pricingRules, 'replaceVisiblePricesForVariant'), 100, 3);
|
143 |
|
|
|
|
|
144 |
|
145 |
+
// Older Version support this hook.
|
146 |
+
add_filter('woocommerce_cart_item_price_html', array($this->pricingRules, 'replaceVisiblePricesCart'), 100, 3);
|
|
|
147 |
|
148 |
+
// Pricing Table of Individual Product.
|
149 |
+
add_filter('woocommerce_before_add_to_cart_form', array($this->pricingRules, 'priceTable'));
|
|
|
|
|
|
|
150 |
|
151 |
+
// Updating Log After Creating Order
|
152 |
+
add_action('woocommerce_thankyou', array($this->discountBase, 'storeLog'));
|
153 |
|
154 |
+
add_action( 'woocommerce_after_checkout_form', array($this->discountBase, 'addScriptInCheckoutPage'));
|
155 |
}
|
156 |
}
|
157 |
}
|
158 |
|
159 |
+
/**
|
160 |
+
* init Woo Discount Rules
|
161 |
+
*/
|
162 |
+
FlycartWooDiscountRules::init();
|
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.9
|
7 |
-
Stable tag: 1.4.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -238,6 +238,10 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
|
|
238 |
|
239 |
== Changelog ==
|
240 |
|
|
|
|
|
|
|
|
|
241 |
= 1.4.32 - 11/12/17 =
|
242 |
* Feature - Based on user role for Price rules(Pro)
|
243 |
* Fix - Product based: display the rule table for get product too
|
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.9
|
7 |
+
Stable tag: 1.4.33
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
238 |
|
239 |
== Changelog ==
|
240 |
|
241 |
+
= 1.4.33 - 19/12/17 =
|
242 |
+
* Fix - error message while update check
|
243 |
+
* Fix - Product category based, not worked for variant product
|
244 |
+
|
245 |
= 1.4.32 - 11/12/17 =
|
246 |
* Feature - Based on user role for Price rules(Pro)
|
247 |
* Fix - Product based: display the rule table for get product too
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/Info.php
CHANGED
@@ -69,6 +69,7 @@ if ( !class_exists('Puc_v4_Plugin_Info', false) ):
|
|
69 |
|| empty($apiResponse->name)
|
70 |
|| empty($apiResponse->version)
|
71 |
) {
|
|
|
72 |
return new WP_Error(
|
73 |
'puc-invalid-metadata',
|
74 |
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
69 |
|| empty($apiResponse->name)
|
70 |
|| empty($apiResponse->version)
|
71 |
) {
|
72 |
+
return false;//Added by ashlin due to displaying error message while check update by Wordpress
|
73 |
return new WP_Error(
|
74 |
'puc-invalid-metadata',
|
75 |
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
view/cart-rules.php
CHANGED
@@ -9,14 +9,7 @@ $config = (isset($config)) ? $config : '{}';
|
|
9 |
|
10 |
$data = array();
|
11 |
$rule_list = $config;
|
12 |
-
|
13 |
-
//for ( WC()->cart->get_coupons as $code => $coupon){
|
14 |
global $woocommerce;
|
15 |
-
// var_dump($woocommerce);
|
16 |
-
// if ( ! $valid ){
|
17 |
-
// WC()->cart->remove_coupon( $code );
|
18 |
-
// }
|
19 |
-
//}
|
20 |
?>
|
21 |
<div class="" id="cart_rule">
|
22 |
<div class="row-fluid">
|
9 |
|
10 |
$data = array();
|
11 |
$rule_list = $config;
|
|
|
|
|
12 |
global $woocommerce;
|
|
|
|
|
|
|
|
|
|
|
13 |
?>
|
14 |
<div class="" id="cart_rule">
|
15 |
<div class="row-fluid">
|
view/settings.php
CHANGED
@@ -15,7 +15,7 @@ if (is_string($data)) $data = json_decode($data, true);
|
|
15 |
<div class="col-md-8">
|
16 |
<form method="post" id="discount_config">
|
17 |
<div class="col-md-12" align="right">
|
18 |
-
<input type="submit" id="saveConfig" value="Save
|
19 |
</div>
|
20 |
<div class="">
|
21 |
<div class="">
|
@@ -111,7 +111,7 @@ if (is_string($data)) $data = json_decode($data, true);
|
|
111 |
<div class="row form-group">
|
112 |
<div class="col-md-2">
|
113 |
<label>
|
114 |
-
<?php esc_html_e('
|
115 |
</label>
|
116 |
</div>
|
117 |
<div class="col-md-6">
|
15 |
<div class="col-md-8">
|
16 |
<form method="post" id="discount_config">
|
17 |
<div class="col-md-12" align="right">
|
18 |
+
<input type="submit" id="saveConfig" value="Save" class="button button-primary">
|
19 |
</div>
|
20 |
<div class="">
|
21 |
<div class="">
|
111 |
<div class="row form-group">
|
112 |
<div class="col-md-2">
|
113 |
<label>
|
114 |
+
<?php esc_html_e('Coupon Name to be displayed :', 'woo-discount-rules'); ?>
|
115 |
</label>
|
116 |
</div>
|
117 |
<div class="col-md-6">
|
view/template/discount-table.php
CHANGED
@@ -9,11 +9,11 @@ $base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data)
|
|
9 |
<?php if (isset($base_config['show_discount_title_table'])) {
|
10 |
if ($base_config['show_discount_title_table'] == 'show') {
|
11 |
?>
|
12 |
-
<td
|
13 |
<?php }
|
14 |
} ?>
|
15 |
-
<td
|
16 |
-
<td
|
17 |
</tr>
|
18 |
</thead>
|
19 |
<tbody>
|
@@ -23,34 +23,29 @@ $base_config = (is_string($data)) ? json_decode($data, true) : (is_array($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 $
|
42 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
?>
|
56 |
</tbody>
|
9 |
<?php if (isset($base_config['show_discount_title_table'])) {
|
10 |
if ($base_config['show_discount_title_table'] == 'show') {
|
11 |
?>
|
12 |
+
<td><?php esc_html_e('Name', 'woo-discount-rules'); ?></td>
|
13 |
<?php }
|
14 |
} ?>
|
15 |
+
<td><?php esc_html_e('Range', 'woo-discount-rules'); ?></td>
|
16 |
+
<td><?php esc_html_e('Discount', 'woo-discount-rules'); ?></td>
|
17 |
</tr>
|
18 |
</thead>
|
19 |
<tbody>
|
23 |
foreach ($table as $index => $item) {
|
24 |
if ($item) {
|
25 |
foreach ($item as $id => $value) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
?>
|
27 |
<tr>
|
28 |
<?php if (isset($base_config['show_discount_title_table'])) {
|
29 |
if ($base_config['show_discount_title_table'] == 'show') {
|
30 |
?>
|
31 |
+
<td><?php echo $table_data_content[$id]['title']; ?></td>
|
32 |
<?php }
|
33 |
} ?>
|
34 |
+
<td><?php echo $table_data_content[$id]['condition']; ?></td>
|
35 |
+
<td><?php echo $table_data_content[$id]['discount']; ?></td>
|
|
|
|
|
|
|
|
|
36 |
</tr>
|
37 |
<?php }
|
38 |
$have_discount = true;
|
39 |
}
|
40 |
}
|
41 |
if (!$have_discount) {
|
42 |
+
?>
|
43 |
+
<tr>
|
44 |
+
<td colspan="2">
|
45 |
+
<?php esc_html_e('No Active Discounts.', 'woo-discount-rules'); ?>
|
46 |
+
</td>
|
47 |
+
</tr>
|
48 |
+
<?php
|
49 |
}
|
50 |
?>
|
51 |
</tbody>
|
view/template/sidebar.php
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
</div>
|
12 |
<div class="woo-side-panel">
|
13 |
<?php
|
14 |
-
echo
|
15 |
?>
|
16 |
</div>
|
17 |
</div>
|
11 |
</div>
|
12 |
<div class="woo-side-panel">
|
13 |
<?php
|
14 |
+
echo FlycartWooDiscountRulesGeneralHelper::getSideBarContent();
|
15 |
?>
|
16 |
</div>
|
17 |
</div>
|
view/view-cart-rules.php
CHANGED
@@ -192,46 +192,7 @@ if (empty($discount_rules)) {
|
|
192 |
<?php } ?>
|
193 |
</option>
|
194 |
</optgroup>
|
195 |
-
<!-- <optgroup label="Products In Cart">-->
|
196 |
-
<!---->
|
197 |
-
<!-- <!-- At least one of these should present in the cart to apply. -->
|
198 |
-
|
199 |
-
<!-- <option-->
|
200 |
-
<!-- value="products_atleast_one"-->
|
201 |
-
<?php //if ($type == 'products_atleast_one') { ?><!-- selected=selected -->
|
202 |
-
<?php //} ?><!-->
|
203 |
-
<!-- At least one product in-->
|
204 |
-
<!-- cart-->
|
205 |
-
<!-- </option>-->
|
206 |
-
<!-- <!-- These products should not present in the cart to apply. -->
|
207 |
-
|
208 |
-
<!-- <option-->
|
209 |
-
<!-- value="products_not_in"-->
|
210 |
-
<?php //if ($type == 'products_not_in') { ?><!-- selected=selected -->
|
211 |
-
<?php //} ?><!-->
|
212 |
-
<!-- None of selected products in-->
|
213 |
-
<!-- cart-->
|
214 |
-
<!-- </option>-->
|
215 |
-
<!-- </optgroup>-->
|
216 |
<optgroup label="Categories In Cart">
|
217 |
-
<!-- At least one of these should present in the cart to apply. -->
|
218 |
-
|
219 |
-
<!-- <option-->
|
220 |
-
<!-- --><?php //if (!$pro) { ?><!-- disabled --><?php //} else { ?><!-- value="categories_atleast_one" --><?php
|
221 |
-
// } ?>
|
222 |
-
<!-- --><?php //if ($type == 'categories_atleast_one') { ?><!-- selected="selected"-->
|
223 |
-
<!-- --><?php //} ?><!-->
|
224 |
-
<!-- At least one category in-->
|
225 |
-
<!-- cart-->
|
226 |
-
<!-- </option>-->
|
227 |
-
<!-- These Category should not present in the cart to apply.
|
228 |
-
<option
|
229 |
-
value="categories_not_in"
|
230 |
-
<?php //if ($type == 'categories_not_in') { ?><!-- selected=selected -->
|
231 |
-
<?php //} ?>
|
232 |
-
<!-- None of selected categories in-->
|
233 |
-
<!-- cart-->
|
234 |
-
<!-- </option>-->
|
235 |
<option
|
236 |
<?php if (!$pro) { ?> disabled <?php } else { ?> value="categories_in" <?php
|
237 |
} ?>
|
@@ -540,7 +501,6 @@ if (empty($discount_rules)) {
|
|
540 |
<input type="hidden" id="admin_path" value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
|
541 |
<input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
|
542 |
<input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
|
543 |
-
<!-- <input type="hidden" name="status" value="--><?php //echo $status; ?><!--">-->
|
544 |
</form>
|
545 |
</div>
|
546 |
|
192 |
<?php } ?>
|
193 |
</option>
|
194 |
</optgroup>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
<optgroup label="Categories In Cart">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
<option
|
197 |
<?php if (!$pro) { ?> disabled <?php } else { ?> value="categories_in" <?php
|
198 |
} ?>
|
501 |
<input type="hidden" id="admin_path" value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
|
502 |
<input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
|
503 |
<input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
|
|
|
504 |
</form>
|
505 |
</div>
|
506 |
|
view/view-pricing-rules.php
CHANGED
@@ -101,25 +101,6 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
101 |
</select></div>
|
102 |
</div>
|
103 |
</div>
|
104 |
-
<!-- <div class="form-group">-->
|
105 |
-
<!-- <div class="row">-->
|
106 |
-
<!-- <div class="col-md-3"><label> Quantity Based On </label></div>-->
|
107 |
-
<!-- --><?php //$opt = (isset($data->qty_based_on) ? $data->qty_based_on : ''); ?>
|
108 |
-
<!-- <div class="col-md-6"><select class="form-control"-->
|
109 |
-
<!-- name="qty_based_on">-->
|
110 |
-
<!-- <option-->
|
111 |
-
<!-- value="each_product" -->
|
112 |
-
<?php //if ($opt == 'each_product') { ?><!-- selected=selected --><?php //} ?><!-->
|
113 |
-
<!-- Qty Of Each Product Individually-->
|
114 |
-
<!-- </option>-->
|
115 |
-
<!-- <option-->
|
116 |
-
<!-- value="each_variation" -->
|
117 |
-
<?php //if ($opt == 'each_variation') { ?><!-- selected=selected --><?php //} ?><!-->
|
118 |
-
<!-- Qty Of Each Variation Individually-->
|
119 |
-
<!-- </option>-->
|
120 |
-
<!-- </select></div>-->
|
121 |
-
<!-- </div>-->
|
122 |
-
<!-- </div>-->
|
123 |
<div class="form-group">
|
124 |
<div class="row">
|
125 |
<div class="col-md-3"><label> Validity <i
|
@@ -200,6 +181,7 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
200 |
</div>
|
201 |
</div>
|
202 |
</div>
|
|
|
203 |
<div class="form-group">
|
204 |
<div class="row">
|
205 |
<div class="col-md-3"><label> Customers </label></div>
|
@@ -239,12 +221,9 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
239 |
<?php
|
240 |
if($pro){
|
241 |
$roles_list = json_decode((isset($data->user_roles_to_apply) ? $data->user_roles_to_apply : '{}'), true); ?>
|
242 |
-
<select class="roles_list selectpicker"
|
243 |
-
id="product_roles_list" multiple
|
244 |
-
name="user_roles_to_apply[]">
|
245 |
<?php foreach ($userRoles as $index => $user) { ?>
|
246 |
-
<option
|
247 |
-
value="<?php echo $index; ?>"<?php if (in_array($index, $roles_list)) { ?> selected=selected <?php } ?>><?php echo $user; ?></option>
|
248 |
<?php } ?>
|
249 |
</select>
|
250 |
<?php
|
@@ -255,7 +234,7 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
255 |
esc_html_e('Supported in PRO version', 'woo-discount-rules');
|
256 |
?>
|
257 |
</div>
|
258 |
-
|
259 |
}
|
260 |
?>
|
261 |
</div>
|
@@ -268,7 +247,7 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
268 |
<div class="col-md-6">
|
269 |
<?php
|
270 |
if($pro){
|
271 |
-
|
272 |
<input type="checkbox" class="" id="based_on_purchase_history" name="based_on_purchase_history"
|
273 |
value="1" <?php if($based_on_purchase_history){ echo 'checked'; } ?>>
|
274 |
<label class="checkbox_label" for="based_on_purchase_history"><?php esc_html_e('Yes, based on Purchase history.', 'woo-discount-rules'); ?></label>
|
@@ -283,7 +262,6 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
283 |
<?php
|
284 |
}
|
285 |
?>
|
286 |
-
|
287 |
<div class="form-group" id="based_on_purchase_history_fields">
|
288 |
<?php $purchased_history_amount = (isset($data->purchased_history_amount) ? $data->purchased_history_amount : 0); ?>
|
289 |
<label><?php esc_html_e('Total purchased amount at least', 'woo-discount-rules'); ?></label>
|
@@ -493,7 +471,6 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
493 |
value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
|
494 |
<input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
|
495 |
<input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
|
496 |
-
<!-- <input type="hidden" name="status" value="--><?php //echo $status; ?><!--">-->
|
497 |
</form>
|
498 |
</div>
|
499 |
|
101 |
</select></div>
|
102 |
</div>
|
103 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
<div class="form-group">
|
105 |
<div class="row">
|
106 |
<div class="col-md-3"><label> Validity <i
|
181 |
</div>
|
182 |
</div>
|
183 |
</div>
|
184 |
+
|
185 |
<div class="form-group">
|
186 |
<div class="row">
|
187 |
<div class="col-md-3"><label> Customers </label></div>
|
221 |
<?php
|
222 |
if($pro){
|
223 |
$roles_list = json_decode((isset($data->user_roles_to_apply) ? $data->user_roles_to_apply : '{}'), true); ?>
|
224 |
+
<select class="roles_list selectpicker" id="product_roles_list" multiple name="user_roles_to_apply[]">
|
|
|
|
|
225 |
<?php foreach ($userRoles as $index => $user) { ?>
|
226 |
+
<option value="<?php echo $index; ?>"<?php if (in_array($index, $roles_list)) { ?> selected=selected <?php } ?>><?php echo $user; ?></option>
|
|
|
227 |
<?php } ?>
|
228 |
</select>
|
229 |
<?php
|
234 |
esc_html_e('Supported in PRO version', 'woo-discount-rules');
|
235 |
?>
|
236 |
</div>
|
237 |
+
<?php
|
238 |
}
|
239 |
?>
|
240 |
</div>
|
247 |
<div class="col-md-6">
|
248 |
<?php
|
249 |
if($pro){
|
250 |
+
?>
|
251 |
<input type="checkbox" class="" id="based_on_purchase_history" name="based_on_purchase_history"
|
252 |
value="1" <?php if($based_on_purchase_history){ echo 'checked'; } ?>>
|
253 |
<label class="checkbox_label" for="based_on_purchase_history"><?php esc_html_e('Yes, based on Purchase history.', 'woo-discount-rules'); ?></label>
|
262 |
<?php
|
263 |
}
|
264 |
?>
|
|
|
265 |
<div class="form-group" id="based_on_purchase_history_fields">
|
266 |
<?php $purchased_history_amount = (isset($data->purchased_history_amount) ? $data->purchased_history_amount : 0); ?>
|
267 |
<label><?php esc_html_e('Total purchased amount at least', 'woo-discount-rules'); ?></label>
|
471 |
value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
|
472 |
<input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
|
473 |
<input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
|
|
|
474 |
</form>
|
475 |
</div>
|
476 |
|
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.4.
|
9 |
* Slug: woo-discount-rules
|
10 |
* Text Domain: woo-discount-rules
|
11 |
* Requires at least: 4.6.1
|
5 |
* Description: Simple Discount Rules for WooCommerce.
|
6 |
* Author: Flycart Technologies LLP
|
7 |
* Author URI: https://www.flycart.org
|
8 |
+
* Version: 1.4.33
|
9 |
* Slug: woo-discount-rules
|
10 |
* Text Domain: woo-discount-rules
|
11 |
* Requires at least: 4.6.1
|