Version Description
- 13/10/17 =
- Feature Based on category in cart rules for pro version
Download this release
Release Info
Developer | flycart |
Plugin | Discount Rules for WooCommerce |
Version | 1.4.20 |
Comparing to | |
See all releases |
Code changes from version 1.4.19 to 1.4.20
- assets/js/app.js +9 -3
- includes/cart-rules-3.php +110 -8
- includes/cart-rules.php +110 -8
- includes/discount-base.php +1 -0
- readme.txt +4 -1
- view/view-cart-rules.php +9 -3
- woo-discount-rules.php +1 -1
assets/js/app.js
CHANGED
@@ -313,7 +313,10 @@ function validateFields(){
|
|
313 |
'<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>' +
|
314 |
'<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. -->' +
|
315 |
//'<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>' +
|
316 |
-
|
|
|
|
|
|
|
317 |
'<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>' +
|
318 |
'<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup>' +
|
319 |
'<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup></select></label></div>' +
|
@@ -330,7 +333,10 @@ function validateFields(){
|
|
330 |
'<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>' +
|
331 |
'<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. -->' +
|
332 |
//'<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>' +
|
333 |
-
|
|
|
|
|
|
|
334 |
'<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 Email Domain (Eg: edu)"><option disabled>Email ends with <b>' + pro_suffix + '</b></option></optgroup>' +
|
336 |
'<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
|
@@ -563,7 +569,7 @@ function validateFields(){
|
|
563 |
$('#general_' + id).css('display', 'none');
|
564 |
$('#roles_div_' + id).css('display', 'none');
|
565 |
$('#countries_div_' + id).css('display', 'none');
|
566 |
-
} else if (option == 'categories_atleast_one' || option == 'categories_not_in') {
|
567 |
$('#user_div_' + id).css('display', 'none');
|
568 |
$('#product_div_' + id).css('display', 'none');
|
569 |
$('#category_div_' + id).css('display', 'block');
|
313 |
'<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>' +
|
314 |
'<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. -->' +
|
315 |
//'<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>' +
|
316 |
+
'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. -->' +
|
317 |
+
//'<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>-->' +
|
318 |
+
'<option value="categories_in">Categories in cart</option>' +
|
319 |
+
'</optgroup>' +
|
320 |
'<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>' +
|
321 |
'<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup>' +
|
322 |
'<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup></select></label></div>' +
|
333 |
'<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>' +
|
334 |
'<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. -->' +
|
335 |
//'<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>' +
|
336 |
+
'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. -->' +
|
337 |
+
//'<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>' +
|
338 |
+
'<option disabled>Categories in cart <b>' + pro_suffix + '</b></option>' +
|
339 |
+
'</optgroup>' +
|
340 |
'<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>' +
|
341 |
'<optgroup label="Customer Email Domain (Eg: edu)"><option disabled>Email ends with <b>' + pro_suffix + '</b></option></optgroup>' +
|
342 |
'<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
|
569 |
$('#general_' + id).css('display', 'none');
|
570 |
$('#roles_div_' + id).css('display', 'none');
|
571 |
$('#countries_div_' + id).css('display', 'none');
|
572 |
+
} else if (option == 'categories_atleast_one' || option == 'categories_not_in' || option == 'categories_in') {
|
573 |
$('#user_div_' + id).css('display', 'none');
|
574 |
$('#product_div_' + id).css('display', 'none');
|
575 |
$('#category_div_' + id).css('display', 'block');
|
includes/cart-rules-3.php
CHANGED
@@ -634,7 +634,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
634 |
woo_dicount_rules_generalHelper::reArrangeArray($rules);
|
635 |
foreach ($rules as $index => $rule) {
|
636 |
// Validating the Rules one by one.
|
637 |
-
if ($this->applyRule($index, $rule) == false) {
|
638 |
return false;
|
639 |
}
|
640 |
}
|
@@ -648,19 +648,24 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
648 |
* @param array $rule array of rule info.
|
649 |
* @return bool true|false as matched or not.
|
650 |
*/
|
651 |
-
public function applyRule($index, $rule)
|
652 |
{
|
|
|
|
|
|
|
653 |
switch ($index) {
|
654 |
|
655 |
// Cart Subtotal.
|
656 |
case 'subtotal_least':
|
657 |
-
if
|
|
|
658 |
return false;
|
659 |
}
|
660 |
return true;
|
661 |
break;
|
662 |
case 'subtotal_less':
|
663 |
-
if
|
|
|
664 |
return false;
|
665 |
}
|
666 |
return true;
|
@@ -668,13 +673,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
668 |
|
669 |
// Cart Item Count.
|
670 |
case 'item_count_least':
|
671 |
-
if
|
|
|
672 |
return false;
|
673 |
}
|
674 |
return true;
|
675 |
break;
|
676 |
case 'item_count_less':
|
677 |
-
if
|
|
|
678 |
return false;
|
679 |
}
|
680 |
return true;
|
@@ -682,13 +689,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
682 |
|
683 |
// Quantity Count.
|
684 |
case 'quantity_least':
|
685 |
-
if
|
|
|
686 |
return false;
|
687 |
}
|
688 |
return true;
|
689 |
break;
|
690 |
case 'quantity_less':
|
691 |
-
if
|
|
|
692 |
return false;
|
693 |
}
|
694 |
return true;
|
@@ -804,6 +813,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
804 |
}
|
805 |
return false;
|
806 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
807 |
/*case 'categories_atleast_one':
|
808 |
if(count($rule)){
|
809 |
$w_categories = $this->getCartProductCaregories();
|
@@ -822,6 +840,90 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
822 |
|
823 |
}
|
824 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
/**
|
826 |
* Get tld from email
|
827 |
* */
|
634 |
woo_dicount_rules_generalHelper::reArrangeArray($rules);
|
635 |
foreach ($rules as $index => $rule) {
|
636 |
// Validating the Rules one by one.
|
637 |
+
if ($this->applyRule($index, $rule, $rules) == false) {
|
638 |
return false;
|
639 |
}
|
640 |
}
|
648 |
* @param array $rule array of rule info.
|
649 |
* @return bool true|false as matched or not.
|
650 |
*/
|
651 |
+
public function applyRule($index, $rule, $rules)
|
652 |
{
|
653 |
+
$skipRuleType = array('categories_in');
|
654 |
+
$availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
|
655 |
+
|
656 |
switch ($index) {
|
657 |
|
658 |
// Cart Subtotal.
|
659 |
case 'subtotal_least':
|
660 |
+
if(!empty($availableRuleToSkip)){
|
661 |
+
} elseif ($this->sub_total < $rule) {
|
662 |
return false;
|
663 |
}
|
664 |
return true;
|
665 |
break;
|
666 |
case 'subtotal_less':
|
667 |
+
if(!empty($availableRuleToSkip)){
|
668 |
+
} elseif ($this->sub_total >= $rule) {
|
669 |
return false;
|
670 |
}
|
671 |
return true;
|
673 |
|
674 |
// Cart Item Count.
|
675 |
case 'item_count_least':
|
676 |
+
if(!empty($availableRuleToSkip)){
|
677 |
+
} elseif (count($this->cart_items) < $rule) {
|
678 |
return false;
|
679 |
}
|
680 |
return true;
|
681 |
break;
|
682 |
case 'item_count_less':
|
683 |
+
if(!empty($availableRuleToSkip)){
|
684 |
+
} elseif (count($this->cart_items) >= $rule) {
|
685 |
return false;
|
686 |
}
|
687 |
return true;
|
689 |
|
690 |
// Quantity Count.
|
691 |
case 'quantity_least':
|
692 |
+
if(!empty($availableRuleToSkip)){
|
693 |
+
} elseif ($this->cartItemQtyTotal() < $rule) {
|
694 |
return false;
|
695 |
}
|
696 |
return true;
|
697 |
break;
|
698 |
case 'quantity_less':
|
699 |
+
if(!empty($availableRuleToSkip)){
|
700 |
+
} elseif ($this->cartItemQtyTotal() >= $rule) {
|
701 |
return false;
|
702 |
}
|
703 |
return true;
|
813 |
}
|
814 |
return false;
|
815 |
break;
|
816 |
+
case 'categories_in':
|
817 |
+
if(count($rule)){
|
818 |
+
$ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules);
|
819 |
+
if($ruleSuccess){
|
820 |
+
return true;
|
821 |
+
}
|
822 |
+
}
|
823 |
+
return false;
|
824 |
+
break;
|
825 |
/*case 'categories_atleast_one':
|
826 |
if(count($rule)){
|
827 |
$w_categories = $this->getCartProductCaregories();
|
840 |
|
841 |
}
|
842 |
|
843 |
+
/**
|
844 |
+
* verify the cart items are from selected category
|
845 |
+
* */
|
846 |
+
protected function validateCartItemsInSelectedCategory($index, $rule, $rules){
|
847 |
+
$ruleSuccess = 0;
|
848 |
+
global $woocommerce;
|
849 |
+
$product_cat_id = array();
|
850 |
+
if(count($woocommerce->cart->cart_contents)){
|
851 |
+
foreach ($woocommerce->cart->cart_contents as $key => $cartItem) {
|
852 |
+
$terms = get_the_terms( $cartItem['product_id'], 'product_cat' );
|
853 |
+
if($terms){
|
854 |
+
foreach ($terms as $term) {
|
855 |
+
$product_id = '';
|
856 |
+
$sub_total_with_tax = $quantity = $item_count = 0;
|
857 |
+
if(isset($product_cat_id[$term->term_id])){
|
858 |
+
$product_id = $product_cat_id[$term->term_id]->product_id.',';
|
859 |
+
$sub_total_with_tax = $product_cat_id[$term->term_id]->sub_total_with_tax;
|
860 |
+
$quantity = $product_cat_id[$term->term_id]->quantity;
|
861 |
+
$item_count = $product_cat_id[$term->term_id]->item_count;
|
862 |
+
}
|
863 |
+
$productDetailObject = new stdClass();
|
864 |
+
$productDetailObject->cat_id = $term->term_id;
|
865 |
+
$productDetailObject->product_id = trim($product_id.$cartItem['product_id'], ',');
|
866 |
+
$productDetailObject->sub_total_with_tax = $sub_total_with_tax+$cartItem['line_subtotal']+$cartItem['line_subtotal_tax'];
|
867 |
+
$productDetailObject->quantity = $quantity+$cartItem['quantity'];
|
868 |
+
$productDetailObject->item_count = $item_count+1;
|
869 |
+
$product_cat_id[$term->term_id] = $productDetailObject;
|
870 |
+
}
|
871 |
+
}
|
872 |
+
}
|
873 |
+
}
|
874 |
+
$category_ids = array_keys($product_cat_id);
|
875 |
+
$categoryFound = 0;
|
876 |
+
$product_id = $cat_id = '';
|
877 |
+
$sub_total_with_tax = $quantity = $item_count = 0;
|
878 |
+
foreach ($rule as $catid){
|
879 |
+
if(in_array($catid, $category_ids)){
|
880 |
+
if(isset($product_cat_id[$catid])){
|
881 |
+
$categoryFound = 1;
|
882 |
+
$cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
|
883 |
+
$product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
|
884 |
+
$sub_total_with_tax = $sub_total_with_tax+$product_cat_id[$catid]->sub_total_with_tax;
|
885 |
+
$quantity = $quantity+$product_cat_id[$catid]->quantity;
|
886 |
+
$item_count = $item_count+$product_cat_id[$catid]->item_count;
|
887 |
+
}
|
888 |
+
}
|
889 |
+
}
|
890 |
+
if($categoryFound){
|
891 |
+
$ruleSuccess = 1;
|
892 |
+
foreach ($rules as $rule_type => $rule_values){
|
893 |
+
$checkRuleTypes = array('quantity_least', 'quantity_less', 'subtotal_least', 'subtotal_less', 'item_count_least', 'item_count_less');
|
894 |
+
if(in_array($rule_type, $checkRuleTypes)){
|
895 |
+
if($rule_type == 'subtotal_least'){
|
896 |
+
if ($sub_total_with_tax < $rule_values) {
|
897 |
+
$ruleSuccess = 0;
|
898 |
+
}
|
899 |
+
} elseif ($rule_type == 'subtotal_less'){
|
900 |
+
if ($sub_total_with_tax >= $rule_values) {
|
901 |
+
$ruleSuccess = 0;
|
902 |
+
}
|
903 |
+
} elseif ($rule_type == 'item_count_least'){
|
904 |
+
if ($item_count < $rule_values) {
|
905 |
+
$ruleSuccess = 0;
|
906 |
+
}
|
907 |
+
} elseif ($rule_type == 'item_count_less'){
|
908 |
+
if ($item_count >= $rule_values) {
|
909 |
+
$ruleSuccess = 0;
|
910 |
+
}
|
911 |
+
} elseif ($rule_type == 'quantity_least'){
|
912 |
+
if ($quantity < $rule_values) {
|
913 |
+
$ruleSuccess = 0;
|
914 |
+
}
|
915 |
+
} elseif ($rule_type == 'quantity_less'){
|
916 |
+
if ($quantity >= $rule_values) {
|
917 |
+
$ruleSuccess = 0;
|
918 |
+
}
|
919 |
+
}
|
920 |
+
}
|
921 |
+
}
|
922 |
+
}
|
923 |
+
|
924 |
+
return $ruleSuccess;
|
925 |
+
}
|
926 |
+
|
927 |
/**
|
928 |
* Get tld from email
|
929 |
* */
|
includes/cart-rules.php
CHANGED
@@ -635,7 +635,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
635 |
woo_dicount_rules_generalHelper::reArrangeArray($rules);
|
636 |
foreach ($rules as $index => $rule) {
|
637 |
// Validating the Rules one by one.
|
638 |
-
if ($this->applyRule($index, $rule) == false) {
|
639 |
return false;
|
640 |
}
|
641 |
}
|
@@ -649,19 +649,24 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
649 |
* @param array $rule array of rule info.
|
650 |
* @return bool true|false as matched or not.
|
651 |
*/
|
652 |
-
public function applyRule($index, $rule)
|
653 |
{
|
|
|
|
|
|
|
654 |
switch ($index) {
|
655 |
|
656 |
// Cart Subtotal.
|
657 |
case 'subtotal_least':
|
658 |
-
if
|
|
|
659 |
return false;
|
660 |
}
|
661 |
return true;
|
662 |
break;
|
663 |
case 'subtotal_less':
|
664 |
-
if
|
|
|
665 |
return false;
|
666 |
}
|
667 |
return true;
|
@@ -669,13 +674,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
669 |
|
670 |
// Cart Item Count.
|
671 |
case 'item_count_least':
|
672 |
-
if
|
|
|
673 |
return false;
|
674 |
}
|
675 |
return true;
|
676 |
break;
|
677 |
case 'item_count_less':
|
678 |
-
if
|
|
|
679 |
return false;
|
680 |
}
|
681 |
return true;
|
@@ -683,13 +690,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
683 |
|
684 |
// Quantity Count.
|
685 |
case 'quantity_least':
|
686 |
-
if
|
|
|
687 |
return false;
|
688 |
}
|
689 |
return true;
|
690 |
break;
|
691 |
case 'quantity_less':
|
692 |
-
if
|
|
|
693 |
return false;
|
694 |
}
|
695 |
return true;
|
@@ -805,6 +814,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
805 |
}
|
806 |
return false;
|
807 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
/*case 'categories_atleast_one':
|
809 |
if(count($rule)){
|
810 |
$w_categories = $this->getCartProductCaregories();
|
@@ -823,6 +841,90 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
|
|
823 |
|
824 |
}
|
825 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
826 |
/**
|
827 |
* Get tld from email
|
828 |
* */
|
635 |
woo_dicount_rules_generalHelper::reArrangeArray($rules);
|
636 |
foreach ($rules as $index => $rule) {
|
637 |
// Validating the Rules one by one.
|
638 |
+
if ($this->applyRule($index, $rule, $rules) == false) {
|
639 |
return false;
|
640 |
}
|
641 |
}
|
649 |
* @param array $rule array of rule info.
|
650 |
* @return bool true|false as matched or not.
|
651 |
*/
|
652 |
+
public function applyRule($index, $rule, $rules)
|
653 |
{
|
654 |
+
$skipRuleType = array('categories_in');
|
655 |
+
$availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
|
656 |
+
|
657 |
switch ($index) {
|
658 |
|
659 |
// Cart Subtotal.
|
660 |
case 'subtotal_least':
|
661 |
+
if(!empty($availableRuleToSkip)){
|
662 |
+
} elseif ($this->sub_total < $rule) {
|
663 |
return false;
|
664 |
}
|
665 |
return true;
|
666 |
break;
|
667 |
case 'subtotal_less':
|
668 |
+
if(!empty($availableRuleToSkip)){
|
669 |
+
} elseif ($this->sub_total >= $rule) {
|
670 |
return false;
|
671 |
}
|
672 |
return true;
|
674 |
|
675 |
// Cart Item Count.
|
676 |
case 'item_count_least':
|
677 |
+
if(!empty($availableRuleToSkip)){
|
678 |
+
} elseif (count($this->cart_items) < $rule) {
|
679 |
return false;
|
680 |
}
|
681 |
return true;
|
682 |
break;
|
683 |
case 'item_count_less':
|
684 |
+
if(!empty($availableRuleToSkip)){
|
685 |
+
} elseif (count($this->cart_items) >= $rule) {
|
686 |
return false;
|
687 |
}
|
688 |
return true;
|
690 |
|
691 |
// Quantity Count.
|
692 |
case 'quantity_least':
|
693 |
+
if(!empty($availableRuleToSkip)){
|
694 |
+
} elseif ($this->cartItemQtyTotal() < $rule) {
|
695 |
return false;
|
696 |
}
|
697 |
return true;
|
698 |
break;
|
699 |
case 'quantity_less':
|
700 |
+
if(!empty($availableRuleToSkip)){
|
701 |
+
} elseif ($this->cartItemQtyTotal() >= $rule) {
|
702 |
return false;
|
703 |
}
|
704 |
return true;
|
814 |
}
|
815 |
return false;
|
816 |
break;
|
817 |
+
case 'categories_in':
|
818 |
+
if(count($rule)){
|
819 |
+
$ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules);
|
820 |
+
if($ruleSuccess){
|
821 |
+
return true;
|
822 |
+
}
|
823 |
+
}
|
824 |
+
return false;
|
825 |
+
break;
|
826 |
/*case 'categories_atleast_one':
|
827 |
if(count($rule)){
|
828 |
$w_categories = $this->getCartProductCaregories();
|
841 |
|
842 |
}
|
843 |
|
844 |
+
/**
|
845 |
+
* verify the cart items are from selected category
|
846 |
+
* */
|
847 |
+
protected function validateCartItemsInSelectedCategory($index, $rule, $rules){
|
848 |
+
$ruleSuccess = 0;
|
849 |
+
global $woocommerce;
|
850 |
+
$product_cat_id = array();
|
851 |
+
if(count($woocommerce->cart->cart_contents)){
|
852 |
+
foreach ($woocommerce->cart->cart_contents as $key => $cartItem) {
|
853 |
+
$terms = get_the_terms( $cartItem['product_id'], 'product_cat' );
|
854 |
+
if($terms){
|
855 |
+
foreach ($terms as $term) {
|
856 |
+
$product_id = '';
|
857 |
+
$sub_total_with_tax = $quantity = $item_count = 0;
|
858 |
+
if(isset($product_cat_id[$term->term_id])){
|
859 |
+
$product_id = $product_cat_id[$term->term_id]->product_id.',';
|
860 |
+
$sub_total_with_tax = $product_cat_id[$term->term_id]->sub_total_with_tax;
|
861 |
+
$quantity = $product_cat_id[$term->term_id]->quantity;
|
862 |
+
$item_count = $product_cat_id[$term->term_id]->item_count;
|
863 |
+
}
|
864 |
+
$productDetailObject = new stdClass();
|
865 |
+
$productDetailObject->cat_id = $term->term_id;
|
866 |
+
$productDetailObject->product_id = trim($product_id.$cartItem['product_id'], ',');
|
867 |
+
$productDetailObject->sub_total_with_tax = $sub_total_with_tax+$cartItem['line_subtotal']+$cartItem['line_subtotal_tax'];
|
868 |
+
$productDetailObject->quantity = $quantity+$cartItem['quantity'];
|
869 |
+
$productDetailObject->item_count = $item_count+1;
|
870 |
+
$product_cat_id[$term->term_id] = $productDetailObject;
|
871 |
+
}
|
872 |
+
}
|
873 |
+
}
|
874 |
+
}
|
875 |
+
$category_ids = array_keys($product_cat_id);
|
876 |
+
$categoryFound = 0;
|
877 |
+
$product_id = $cat_id = '';
|
878 |
+
$sub_total_with_tax = $quantity = $item_count = 0;
|
879 |
+
foreach ($rule as $catid){
|
880 |
+
if(in_array($catid, $category_ids)){
|
881 |
+
if(isset($product_cat_id[$catid])){
|
882 |
+
$categoryFound = 1;
|
883 |
+
$cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
|
884 |
+
$product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
|
885 |
+
$sub_total_with_tax = $sub_total_with_tax+$product_cat_id[$catid]->sub_total_with_tax;
|
886 |
+
$quantity = $quantity+$product_cat_id[$catid]->quantity;
|
887 |
+
$item_count = $item_count+$product_cat_id[$catid]->item_count;
|
888 |
+
}
|
889 |
+
}
|
890 |
+
}
|
891 |
+
if($categoryFound){
|
892 |
+
$ruleSuccess = 1;
|
893 |
+
foreach ($rules as $rule_type => $rule_values){
|
894 |
+
$checkRuleTypes = array('quantity_least', 'quantity_less', 'subtotal_least', 'subtotal_less', 'item_count_least', 'item_count_less');
|
895 |
+
if(in_array($rule_type, $checkRuleTypes)){
|
896 |
+
if($rule_type == 'subtotal_least'){
|
897 |
+
if ($sub_total_with_tax < $rule_values) {
|
898 |
+
$ruleSuccess = 0;
|
899 |
+
}
|
900 |
+
} elseif ($rule_type == 'subtotal_less'){
|
901 |
+
if ($sub_total_with_tax >= $rule_values) {
|
902 |
+
$ruleSuccess = 0;
|
903 |
+
}
|
904 |
+
} elseif ($rule_type == 'item_count_least'){
|
905 |
+
if ($item_count < $rule_values) {
|
906 |
+
$ruleSuccess = 0;
|
907 |
+
}
|
908 |
+
} elseif ($rule_type == 'item_count_less'){
|
909 |
+
if ($item_count >= $rule_values) {
|
910 |
+
$ruleSuccess = 0;
|
911 |
+
}
|
912 |
+
} elseif ($rule_type == 'quantity_least'){
|
913 |
+
if ($quantity < $rule_values) {
|
914 |
+
$ruleSuccess = 0;
|
915 |
+
}
|
916 |
+
} elseif ($rule_type == 'quantity_less'){
|
917 |
+
if ($quantity >= $rule_values) {
|
918 |
+
$ruleSuccess = 0;
|
919 |
+
}
|
920 |
+
}
|
921 |
+
}
|
922 |
+
}
|
923 |
+
}
|
924 |
+
|
925 |
+
return $ruleSuccess;
|
926 |
+
}
|
927 |
+
|
928 |
/**
|
929 |
* Get tld from email
|
930 |
* */
|
includes/discount-base.php
CHANGED
@@ -264,6 +264,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
264 |
|
265 |
'categories_atleast_one' => 'category_to_apply',
|
266 |
'categories_not_in' => 'category_to_apply',
|
|
|
267 |
|
268 |
'users_in' => 'users_to_apply',
|
269 |
'roles_in' => 'user_roles_to_apply',
|
264 |
|
265 |
'categories_atleast_one' => 'category_to_apply',
|
266 |
'categories_not_in' => 'category_to_apply',
|
267 |
+
'categories_in' => 'category_to_apply',
|
268 |
|
269 |
'users_in' => 'users_to_apply',
|
270 |
'roles_in' => 'user_roles_to_apply',
|
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.8.1
|
7 |
-
Stable tag: 1.4.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -109,6 +109,9 @@ More information could be found in the documentation
|
|
109 |
|
110 |
== Changelog ==
|
111 |
|
|
|
|
|
|
|
112 |
= 1.4.19 - 04/10/17 =
|
113 |
* Feature – Buy one/more and get one/more free product for pro version
|
114 |
|
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.8.1
|
7 |
+
Stable tag: 1.4.20
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
109 |
|
110 |
== Changelog ==
|
111 |
|
112 |
+
= 1.4.20 - 13/10/17 =
|
113 |
+
* Feature – Based on category in cart rules for pro version
|
114 |
+
|
115 |
= 1.4.19 - 04/10/17 =
|
116 |
* Feature – Buy one/more and get one/more free product for pro version
|
117 |
|
view/view-cart-rules.php
CHANGED
@@ -213,7 +213,7 @@ if (empty($discount_rules)) {
|
|
213 |
<!-- cart-->
|
214 |
<!-- </option>-->
|
215 |
<!-- </optgroup>-->
|
216 |
-
|
217 |
<!-- At least one of these should present in the cart to apply. -->
|
218 |
|
219 |
<!-- <option-->
|
@@ -232,7 +232,13 @@ if (empty($discount_rules)) {
|
|
232 |
<!-- None of selected categories in-->
|
233 |
<!-- cart-->
|
234 |
<!-- </option>-->
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
<optgroup label="Customer Details (must be logged in)">
|
237 |
<option
|
238 |
<?php if (!$pro) { ?> disabled <?php } else { ?> value="users_in" <?php
|
@@ -339,7 +345,7 @@ if (empty($discount_rules)) {
|
|
339 |
<?php
|
340 |
$category_list = array();
|
341 |
$class = 'style="display:none"';
|
342 |
-
if ($type == 'categories_atleast_one' || $type == 'categories_not_in') {
|
343 |
$category_list = $discount_rules[$type];;
|
344 |
|
345 |
$class = 'style="display:block"';
|
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-->
|
232 |
<!-- None of selected categories in-->
|
233 |
<!-- cart-->
|
234 |
<!-- </option>-->
|
235 |
+
<option
|
236 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="categories_in" <?php
|
237 |
+
} ?>
|
238 |
+
<?php if ($type == 'categories_in') { ?> selected="selected"
|
239 |
+
<?php } ?>>Categories in cart
|
240 |
+
</option>
|
241 |
+
</optgroup>
|
242 |
<optgroup label="Customer Details (must be logged in)">
|
243 |
<option
|
244 |
<?php if (!$pro) { ?> disabled <?php } else { ?> value="users_in" <?php
|
345 |
<?php
|
346 |
$category_list = array();
|
347 |
$class = 'style="display:none"';
|
348 |
+
if ($type == 'categories_atleast_one' || $type == 'categories_not_in' || $type == 'categories_in') {
|
349 |
$category_list = $discount_rules[$type];;
|
350 |
|
351 |
$class = 'style="display:block"';
|
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.20
|
9 |
* Slug: woo-discount-rules
|
10 |
* Text Domain: woo-discount-rules
|
11 |
* Requires at least: 4.6.1
|