Version Description
- 24/11/17 =
- Fix Category based rule not applying rule for variant product in cart
- Feature Search option in Select box for product and categories
- Feature Product based rule for pro version
Download this release
Release Info
Developer | flycart |
Plugin | Discount Rules for WooCommerce |
Version | 1.4.27 |
Comparing to | |
See all releases |
Code changes from version 1.4.26 to 1.4.27
- assets/css/style.css +6 -0
- assets/js/app.js +18 -1
- assets/js/bootstrap.select.min.js +1 -1
- helper/general-helper-3.php +5 -2
- helper/general-helper.php +5 -1
- includes/pricing-productbased.php +85 -0
- includes/pricing-rules-3.php +331 -149
- includes/pricing-rules.php +331 -145
- loader.php +15 -12
- readme.txt +6 -1
- view/view-pricing-rules.php +263 -188
- woo-discount-rules.php +1 -1
assets/css/style.css
CHANGED
@@ -31,4 +31,10 @@
|
|
31 |
#based_on_purchase_history_fields{
|
32 |
margin-top: 10px;
|
33 |
display: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
31 |
#based_on_purchase_history_fields{
|
32 |
margin-top: 10px;
|
33 |
display: none;
|
34 |
+
}
|
35 |
+
.product_based_condition_cont button,
|
36 |
+
.product_based_condition_cont select,
|
37 |
+
.product_based_condition_cont input,
|
38 |
+
.product_based_condition_cont label{
|
39 |
+
margin: 10px 0;
|
40 |
}
|
assets/js/app.js
CHANGED
@@ -171,7 +171,7 @@ function validateFields(){
|
|
171 |
} else {
|
172 |
var form = '<div class="discount_rule_list"> <div class="form-group"><label>Min Quantity <input type="text" name="discount_range[' + count + '][min_qty]" class="form-control" value="" placeholder="ex. 1"></label>' +
|
173 |
'<label>Max Quantity <input type="text" name="discount_range[' + count + '][max_qty]" class="form-control" value="" placeholder="ex. 50"> </label> <label>Adjustment Type<select class="form-control price_discount_type" name="discount_range[' + count + '][discount_type]"> ' +
|
174 |
-
'<option value="percentage_discount"> Percentage Discount </option> <option disabled>Price Discount <b>' + pro_suffix + '</b> </option> <option disabled>Product Discount <b
|
175 |
'<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
|
176 |
form += '<div class="price_discount_product_list_con hide"><select class="product_list selectpicker price_discount_product_list" multiple name="discount_range[' + count + '][discount_product][]">';
|
177 |
form += '<option>none</option>';
|
@@ -529,6 +529,23 @@ function validateFields(){
|
|
529 |
}
|
530 |
});
|
531 |
$('#based_on_purchase_history').trigger('change');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
//--------------------------------------------------------------------------------------------------------------
|
533 |
//-----------------------------------------------SETTINGS-------------------------------------------------------
|
534 |
//--------------------------------------------------------------------------------------------------------------
|
171 |
} else {
|
172 |
var form = '<div class="discount_rule_list"> <div class="form-group"><label>Min Quantity <input type="text" name="discount_range[' + count + '][min_qty]" class="form-control" value="" placeholder="ex. 1"></label>' +
|
173 |
'<label>Max Quantity <input type="text" name="discount_range[' + count + '][max_qty]" class="form-control" value="" placeholder="ex. 50"> </label> <label>Adjustment Type<select class="form-control price_discount_type" name="discount_range[' + count + '][discount_type]"> ' +
|
174 |
+
'<option value="percentage_discount"> Percentage Discount </option> <option disabled>Price Discount <b>' + pro_suffix + '</b> </option> <option disabled>Product Discount <b>' + pro_suffix + '</b> </option> </select></label> <label>Value ' +
|
175 |
'<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
|
176 |
form += '<div class="price_discount_product_list_con hide"><select class="product_list selectpicker price_discount_product_list" multiple name="discount_range[' + count + '][discount_product][]">';
|
177 |
form += '<option>none</option>';
|
529 |
}
|
530 |
});
|
531 |
$('#based_on_purchase_history').trigger('change');
|
532 |
+
|
533 |
+
$('#price_rule_method').on('change', function () {
|
534 |
+
var rule_method = $(this).val();
|
535 |
+
$('.price_discounts_con, .price_discount_condition_con').hide();
|
536 |
+
$('.'+rule_method+'_discount_cont, .'+rule_method+'_condition_cont').show();
|
537 |
+
});
|
538 |
+
$('#price_rule_method').trigger('change');
|
539 |
+
|
540 |
+
$('#product_based_condition_quantity_rule').on('change', function () {
|
541 |
+
var quantity_values = $(this).val();
|
542 |
+
if(quantity_values == 'from'){
|
543 |
+
$('.product_based_condition_to').css({"display": "inline-block"})
|
544 |
+
} else {
|
545 |
+
$('.product_based_condition_to').css({"display": "none"})
|
546 |
+
}
|
547 |
+
});
|
548 |
+
$('#product_based_condition_quantity_rule').trigger('change');
|
549 |
//--------------------------------------------------------------------------------------------------------------
|
550 |
//-----------------------------------------------SETTINGS-------------------------------------------------------
|
551 |
//--------------------------------------------------------------------------------------------------------------
|
assets/js/bootstrap.select.min.js
CHANGED
@@ -4,5 +4,5 @@
|
|
4 |
* Copyright 2013-2016 bootstrap-select
|
5 |
* Licensed under MIT (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE)
|
6 |
*/
|
7 |
-
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof exports?module.exports=b(require("jquery")):b(jQuery)}(this,function(a){!function(a){"use strict";function b(b){var c=[{re:/[\xC0-\xC6]/g,ch:"A"},{re:/[\xE0-\xE6]/g,ch:"a"},{re:/[\xC8-\xCB]/g,ch:"E"},{re:/[\xE8-\xEB]/g,ch:"e"},{re:/[\xCC-\xCF]/g,ch:"I"},{re:/[\xEC-\xEF]/g,ch:"i"},{re:/[\xD2-\xD6]/g,ch:"O"},{re:/[\xF2-\xF6]/g,ch:"o"},{re:/[\xD9-\xDC]/g,ch:"U"},{re:/[\xF9-\xFC]/g,ch:"u"},{re:/[\xC7-\xE7]/g,ch:"c"},{re:/[\xD1]/g,ch:"N"},{re:/[\xF1]/g,ch:"n"}];return a.each(c,function(){b=b.replace(this.re,this.ch)}),b}function c(a){var b={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},c="(?:"+Object.keys(b).join("|")+")",d=new RegExp(c),e=new RegExp(c,"g"),f=null==a?"":""+a;return d.test(f)?f.replace(e,function(a){return b[a]}):f}function d(b,c){var d=arguments,f=b,g=c;[].shift.apply(d);var h,i=this.each(function(){var b=a(this);if(b.is("select")){var c=b.data("selectpicker"),i="object"==typeof f&&f;if(c){if(i)for(var j in i)i.hasOwnProperty(j)&&(c.options[j]=i[j])}else{var k=a.extend({},e.DEFAULTS,a.fn.selectpicker.defaults||{},b.data(),i);k.template=a.extend({},e.DEFAULTS.template,a.fn.selectpicker.defaults?a.fn.selectpicker.defaults.template:{},b.data().template,i.template),b.data("selectpicker",c=new e(this,k,g))}"string"==typeof f&&(h=c[f]instanceof Function?c[f].apply(c,d):c.options[f])}});return"undefined"!=typeof h?h:i}String.prototype.includes||!function(){var a={}.toString,b=function(){try{var a={},b=Object.defineProperty,c=b(a,a,a)&&b}catch(d){}return c}(),c="".indexOf,d=function(b){if(null==this)throw new TypeError;var d=String(this);if(b&&"[object RegExp]"==a.call(b))throw new TypeError;var e=d.length,f=String(b),g=f.length,h=arguments.length>1?arguments[1]:void 0,i=h?Number(h):0;i!=i&&(i=0);var j=Math.min(Math.max(i,0),e);return g+j>e?!1:-1!=c.call(d,f,i)};b?b(String.prototype,"includes",{value:d,configurable:!0,writable:!0}):String.prototype.includes=d}(),String.prototype.startsWith||!function(){var a=function(){try{var a={},b=Object.defineProperty,c=b(a,a,a)&&b}catch(d){}return c}(),b={}.toString,c=function(a){if(null==this)throw new TypeError;var c=String(this);if(a&&"[object RegExp]"==b.call(a))throw new TypeError;var d=c.length,e=String(a),f=e.length,g=arguments.length>1?arguments[1]:void 0,h=g?Number(g):0;h!=h&&(h=0);var i=Math.min(Math.max(h,0),d);if(f+i>d)return!1;for(var j=-1;++j<f;)if(c.charCodeAt(i+j)!=e.charCodeAt(j))return!1;return!0};a?a(String.prototype,"startsWith",{value:c,configurable:!0,writable:!0}):String.prototype.startsWith=c}(),Object.keys||(Object.keys=function(a,b,c){c=[];for(b in a)c.hasOwnProperty.call(a,b)&&c.push(b);return c}),a.fn.triggerNative=function(a){var b,c=this[0];c.dispatchEvent?("function"==typeof Event?b=new Event(a,{bubbles:!0}):(b=document.createEvent("Event"),b.initEvent(a,!0,!1)),c.dispatchEvent(b)):(c.fireEvent&&(b=document.createEventObject(),b.eventType=a,c.fireEvent("on"+a,b)),this.trigger(a))},a.expr[":"].icontains=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.text()).toUpperCase();return f.includes(d[3].toUpperCase())},a.expr[":"].ibegins=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.text()).toUpperCase();return f.startsWith(d[3].toUpperCase())},a.expr[":"].aicontains=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.data("normalizedText")||e.text()).toUpperCase();return f.includes(d[3].toUpperCase())},a.expr[":"].aibegins=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.data("normalizedText")||e.text()).toUpperCase();return f.startsWith(d[3].toUpperCase())};var e=function(b,c,d){d&&(d.stopPropagation(),d.preventDefault()),this.$element=a(b),this.$newElement=null,this.$button=null,this.$menu=null,this.$lis=null,this.options=c,null===this.options.title&&(this.options.title=this.$element.attr("title")),this.val=e.prototype.val,this.render=e.prototype.render,this.refresh=e.prototype.refresh,this.setStyle=e.prototype.setStyle,this.selectAll=e.prototype.selectAll,this.deselectAll=e.prototype.deselectAll,this.destroy=e.prototype.destroy,this.remove=e.prototype.remove,this.show=e.prototype.show,this.hide=e.prototype.hide,this.init()};e.VERSION="1.10.0",e.DEFAULTS={noneSelectedText:"None selected",noneResultsText:"No results matched {0}",countSelectedText:function(a,b){return 1==a?"{0} item selected":"{0} items selected"},maxOptionsText:function(a,b){return[1==a?"Limit reached ({n} item max)":"Limit reached ({n} items max)",1==b?"Group limit reached ({n} item max)":"Group limit reached ({n} items max)"]},selectAllText:"Select All",deselectAllText:"Deselect All",doneButton:!1,doneButtonText:"Close",multipleSeparator:", ",styleBase:"btn",style:"btn-default",size:"auto",title:null,selectedTextFormat:"values",width:!1,container:!1,hideDisabled:!1,showSubtext:!1,showIcon:!0,showContent:!0,dropupAuto:!0,header:!1,liveSearch:!1,liveSearchPlaceholder:null,liveSearchNormalize:!1,liveSearchStyle:"contains",actionsBox:!1,iconBase:"glyphicon",tickIcon:"glyphicon-ok",showTick:!1,template:{caret:'<span class="caret"></span>'},maxOptions:!1,mobile:!1,selectOnTab:!1,dropdownAlignRight:!1},e.prototype={constructor:e,init:function(){var b=this,c=this.$element.attr("id");this.$element.addClass("bs-select-hidden"),this.liObj={},this.multiple=this.$element.prop("multiple"),this.autofocus=this.$element.prop("autofocus"),this.$newElement=this.createView(),this.$element.after(this.$newElement).appendTo(this.$newElement),this.$button=this.$newElement.children("button"),this.$menu=this.$newElement.children(".dropdown-menu"),this.$menuInner=this.$menu.children(".inner"),this.$searchbox=this.$menu.find("input"),this.$element.removeClass("bs-select-hidden"),this.options.dropdownAlignRight&&this.$menu.addClass("dropdown-menu-right"),"undefined"!=typeof c&&(this.$button.attr("data-id",c),a('label[for="'+c+'"]').click(function(a){a.preventDefault(),b.$button.focus()})),this.checkDisabled(),this.clickListener(),this.options.liveSearch&&this.liveSearchListener(),this.render(),this.setStyle(),this.setWidth(),this.options.container&&this.selectPosition(),this.$menu.data("this",this),this.$newElement.data("this",this),this.options.mobile&&this.mobile(),this.$newElement.on({"hide.bs.dropdown":function(a){b.$element.trigger("hide.bs.select",a)},"hidden.bs.dropdown":function(a){b.$element.trigger("hidden.bs.select",a)},"show.bs.dropdown":function(a){b.$element.trigger("show.bs.select",a)},"shown.bs.dropdown":function(a){b.$element.trigger("shown.bs.select",a)}}),b.$element[0].hasAttribute("required")&&this.$element.on("invalid",function(){b.$button.addClass("bs-invalid").focus(),b.$element.on({"focus.bs.select":function(){b.$button.focus(),b.$element.off("focus.bs.select")},"shown.bs.select":function(){b.$element.val(b.$element.val()).off("shown.bs.select")},"rendered.bs.select":function(){this.validity.valid&&b.$button.removeClass("bs-invalid"),b.$element.off("rendered.bs.select")}})}),setTimeout(function(){b.$element.trigger("loaded.bs.select")})},createDropdown:function(){var b=this.multiple||this.options.showTick?" show-tick":"",d=this.$element.parent().hasClass("input-group")?" input-group-btn":"",e=this.autofocus?" autofocus":"",f=this.options.header?'<div class="popover-title"><button type="button" class="close" aria-hidden="true">×</button>'+this.options.header+"</div>":"",g=this.options.liveSearch?'<div class="bs-searchbox"><input type="text" class="form-control" autocomplete="off"'+(null===this.options.liveSearchPlaceholder?"":' placeholder="'+c(this.options.liveSearchPlaceholder)+'"')+"></div>":"",h=this.multiple&&this.options.actionsBox?'<div class="bs-actionsbox"><div class="btn-group btn-group-sm btn-block"><button type="button" class="actions-btn bs-select-all btn btn-default">'+this.options.selectAllText+'</button><button type="button" class="actions-btn bs-deselect-all btn btn-default">'+this.options.deselectAllText+"</button></div></div>":"",i=this.multiple&&this.options.doneButton?'<div class="bs-donebutton"><div class="btn-group btn-block"><button type="button" class="btn btn-sm btn-default">'+this.options.doneButtonText+"</button></div></div>":"",j='<div class="btn-group bootstrap-select'+b+d+'"><button type="button" class="'+this.options.styleBase+' dropdown-toggle" data-toggle="dropdown"'+e+'><span class="filter-option pull-left"></span> <span class="bs-caret">'+this.options.template.caret+'</span></button><div class="dropdown-menu open">'+f+g+h+'<ul class="dropdown-menu inner" role="menu"></ul>'+i+"</div></div>";return a(j)},createView:function(){var a=this.createDropdown(),b=this.createLi();return a.find("ul")[0].innerHTML=b,a},reloadLi:function(){this.destroyLi();var a=this.createLi();this.$menuInner[0].innerHTML=a},destroyLi:function(){this.$menu.find("li").remove()},createLi:function(){var d=this,e=[],f=0,g=document.createElement("option"),h=-1,i=function(a,b,c,d){return"<li"+("undefined"!=typeof c&""!==c?' class="'+c+'"':"")+("undefined"!=typeof b&null!==b?' data-original-index="'+b+'"':"")+("undefined"!=typeof d&null!==d?'data-optgroup="'+d+'"':"")+">"+a+"</li>"},j=function(a,e,f,g){return'<a tabindex="0"'+("undefined"!=typeof e?' class="'+e+'"':"")+("undefined"!=typeof f?' style="'+f+'"':"")+(d.options.liveSearchNormalize?' data-normalized-text="'+b(c(a))+'"':"")+("undefined"!=typeof g||null!==g?' data-tokens="'+g+'"':"")+">"+a+'<span class="'+d.options.iconBase+" "+d.options.tickIcon+' check-mark"></span></a>'};if(this.options.title&&!this.multiple&&(h--,!this.$element.find(".bs-title-option").length)){var k=this.$element[0];g.className="bs-title-option",g.appendChild(document.createTextNode(this.options.title)),g.value="",k.insertBefore(g,k.firstChild),void 0===a(k.options[k.selectedIndex]).attr("selected")&&(g.selected=!0)}return this.$element.find("option").each(function(b){var c=a(this);if(h++,!c.hasClass("bs-title-option")){var g=this.className||"",k=this.style.cssText,l=c.data("content")?c.data("content"):c.html(),m=c.data("tokens")?c.data("tokens"):null,n="undefined"!=typeof c.data("subtext")?'<small class="text-muted">'+c.data("subtext")+"</small>":"",o="undefined"!=typeof c.data("icon")?'<span class="'+d.options.iconBase+" "+c.data("icon")+'"></span> ':"",p="OPTGROUP"===this.parentNode.tagName,q=this.disabled||p&&this.parentNode.disabled;if(""!==o&&q&&(o="<span>"+o+"</span>"),d.options.hideDisabled&&q&&!p)return void h--;if(c.data("content")||(l=o+'<span class="text">'+l+n+"</span>"),p&&c.data("divider")!==!0){var r=" "+this.parentNode.className||"";if(0===c.index()){f+=1;var s=this.parentNode.label,t="undefined"!=typeof c.parent().data("subtext")?'<small class="text-muted">'+c.parent().data("subtext")+"</small>":"",u=c.parent().data("icon")?'<span class="'+d.options.iconBase+" "+c.parent().data("icon")+'"></span> ':"";s=u+'<span class="text">'+s+t+"</span>",0!==b&&e.length>0&&(h++,e.push(i("",null,"divider",f+"div"))),h++,e.push(i(s,null,"dropdown-header"+r,f))}if(d.options.hideDisabled&&q)return void h--;e.push(i(j(l,"opt "+g+r,k,m),b,"",f))}else c.data("divider")===!0?e.push(i("",b,"divider")):c.data("hidden")===!0?e.push(i(j(l,g,k,m),b,"hidden is-hidden")):(this.previousElementSibling&&"OPTGROUP"===this.previousElementSibling.tagName&&(h++,e.push(i("",null,"divider",f+"div"))),e.push(i(j(l,g,k,m),b)));d.liObj[b]=h}}),this.multiple||0!==this.$element.find("option:selected").length||this.options.title||this.$element.find("option").eq(0).prop("selected",!0).attr("selected","selected"),e.join("")},findLis:function(){return null==this.$lis&&(this.$lis=this.$menu.find("li")),this.$lis},render:function(b){var c,d=this;b!==!1&&this.$element.find("option").each(function(a){var b=d.findLis().eq(d.liObj[a]);d.setDisabled(a,this.disabled||"OPTGROUP"===this.parentNode.tagName&&this.parentNode.disabled,b),d.setSelected(a,this.selected,b)}),this.tabIndex();var e=this.$element.find("option").map(function(){if(this.selected){if(d.options.hideDisabled&&(this.disabled||"OPTGROUP"===this.parentNode.tagName&&this.parentNode.disabled))return;var b,c=a(this),e=c.data("icon")&&d.options.showIcon?'<i class="'+d.options.iconBase+" "+c.data("icon")+'"></i> ':"";return b=d.options.showSubtext&&c.data("subtext")&&!d.multiple?' <small class="text-muted">'+c.data("subtext")+"</small>":"","undefined"!=typeof c.attr("title")?c.attr("title"):c.data("content")&&d.options.showContent?c.data("content"):e+c.html()+b}}).toArray(),f=this.multiple?e.join(this.options.multipleSeparator):e[0];if(this.multiple&&this.options.selectedTextFormat.indexOf("count")>-1){var g=this.options.selectedTextFormat.split(">");if(g.length>1&&e.length>g[1]||1==g.length&&e.length>=2){c=this.options.hideDisabled?", [disabled]":"";var h=this.$element.find("option").not('[data-divider="true"], [data-hidden="true"]'+c).length,i="function"==typeof this.options.countSelectedText?this.options.countSelectedText(e.length,h):this.options.countSelectedText;f=i.replace("{0}",e.length.toString()).replace("{1}",h.toString())}}void 0==this.options.title&&(this.options.title=this.$element.attr("title")),"static"==this.options.selectedTextFormat&&(f=this.options.title),f||(f="undefined"!=typeof this.options.title?this.options.title:this.options.noneSelectedText),this.$button.attr("title",a.trim(f.replace(/<[^>]*>?/g,""))),this.$button.children(".filter-option").html(f),this.$element.trigger("rendered.bs.select")},setStyle:function(a,b){this.$element.attr("class")&&this.$newElement.addClass(this.$element.attr("class").replace(/selectpicker|mobile-device|bs-select-hidden|validate\[.*\]/gi,""));var c=a?a:this.options.style;"add"==b?this.$button.addClass(c):"remove"==b?this.$button.removeClass(c):(this.$button.removeClass(this.options.style),this.$button.addClass(c))},liHeight:function(b){if(b||this.options.size!==!1&&!this.sizeInfo){var c=document.createElement("div"),d=document.createElement("div"),e=document.createElement("ul"),f=document.createElement("li"),g=document.createElement("li"),h=document.createElement("a"),i=document.createElement("span"),j=this.options.header&&this.$menu.find(".popover-title").length>0?this.$menu.find(".popover-title")[0].cloneNode(!0):null,k=this.options.liveSearch?document.createElement("div"):null,l=this.options.actionsBox&&this.multiple&&this.$menu.find(".bs-actionsbox").length>0?this.$menu.find(".bs-actionsbox")[0].cloneNode(!0):null,m=this.options.doneButton&&this.multiple&&this.$menu.find(".bs-donebutton").length>0?this.$menu.find(".bs-donebutton")[0].cloneNode(!0):null;if(i.className="text",c.className=this.$menu[0].parentNode.className+" open",d.className="dropdown-menu open",e.className="dropdown-menu inner",f.className="divider",i.appendChild(document.createTextNode("Inner text")),h.appendChild(i),g.appendChild(h),e.appendChild(g),e.appendChild(f),j&&d.appendChild(j),k){var n=document.createElement("span");k.className="bs-searchbox",n.className="form-control",k.appendChild(n),d.appendChild(k)}l&&d.appendChild(l),d.appendChild(e),m&&d.appendChild(m),c.appendChild(d),document.body.appendChild(c);var o=h.offsetHeight,p=j?j.offsetHeight:0,q=k?k.offsetHeight:0,r=l?l.offsetHeight:0,s=m?m.offsetHeight:0,t=a(f).outerHeight(!0),u="function"==typeof getComputedStyle?getComputedStyle(d):!1,v=u?null:a(d),w=parseInt(u?u.paddingTop:v.css("paddingTop"))+parseInt(u?u.paddingBottom:v.css("paddingBottom"))+parseInt(u?u.borderTopWidth:v.css("borderTopWidth"))+parseInt(u?u.borderBottomWidth:v.css("borderBottomWidth")),x=w+parseInt(u?u.marginTop:v.css("marginTop"))+parseInt(u?u.marginBottom:v.css("marginBottom"))+2;document.body.removeChild(c),this.sizeInfo={liHeight:o,headerHeight:p,searchHeight:q,actionsHeight:r,doneButtonHeight:s,dividerHeight:t,menuPadding:w,menuExtras:x}}},setSize:function(){if(this.findLis(),this.liHeight(),this.options.header&&this.$menu.css("padding-top",0),this.options.size!==!1){var b,c,d,e,f=this,g=this.$menu,h=this.$menuInner,i=a(window),j=this.$newElement[0].offsetHeight,k=this.sizeInfo.liHeight,l=this.sizeInfo.headerHeight,m=this.sizeInfo.searchHeight,n=this.sizeInfo.actionsHeight,o=this.sizeInfo.doneButtonHeight,p=this.sizeInfo.dividerHeight,q=this.sizeInfo.menuPadding,r=this.sizeInfo.menuExtras,s=this.options.hideDisabled?".disabled":"",t=function(){d=f.$newElement.offset().top-i.scrollTop(),e=i.height()-d-j};if(t(),"auto"===this.options.size){var u=function(){var i,j=function(b,c){return function(d){return c?d.classList?d.classList.contains(b):a(d).hasClass(b):!(d.classList?d.classList.contains(b):a(d).hasClass(b))}},p=f.$menuInner[0].getElementsByTagName("li"),s=Array.prototype.filter?Array.prototype.filter.call(p,j("hidden",!1)):f.$lis.not(".hidden"),u=Array.prototype.filter?Array.prototype.filter.call(s,j("dropdown-header",!0)):s.filter(".dropdown-header");t(),b=e-r,f.options.container?(g.data("height")||g.data("height",g.height()),c=g.data("height")):c=g.height(),f.options.dropupAuto&&f.$newElement.toggleClass("dropup",d>e&&c>b-r),f.$newElement.hasClass("dropup")&&(b=d-r),i=s.length+u.length>3?3*k+r-2:0,g.css({"max-height":b+"px",overflow:"hidden","min-height":i+l+m+n+o+"px"}),h.css({"max-height":b-l-m-n-o-q+"px","overflow-y":"auto","min-height":Math.max(i-q,0)+"px"})};u(),this.$searchbox.off("input.getSize propertychange.getSize").on("input.getSize propertychange.getSize",u),i.off("resize.getSize scroll.getSize").on("resize.getSize scroll.getSize",u)}else if(this.options.size&&"auto"!=this.options.size&&this.$lis.not(s).length>this.options.size){var v=this.$lis.not(".divider").not(s).children().slice(0,this.options.size).last().parent().index(),w=this.$lis.slice(0,v+1).filter(".divider").length;b=k*this.options.size+w*p+q,f.options.container?(g.data("height")||g.data("height",g.height()),c=g.data("height")):c=g.height(),f.options.dropupAuto&&this.$newElement.toggleClass("dropup",d>e&&c>b-r),g.css({"max-height":b+l+m+n+o+"px",overflow:"hidden","min-height":""}),h.css({"max-height":b-q+"px","overflow-y":"auto","min-height":""})}}},setWidth:function(){if("auto"===this.options.width){this.$menu.css("min-width","0");var a=this.$menu.parent().clone().appendTo("body"),b=this.options.container?this.$newElement.clone().appendTo("body"):a,c=a.children(".dropdown-menu").outerWidth(),d=b.css("width","auto").children("button").outerWidth();a.remove(),b.remove(),this.$newElement.css("width",Math.max(c,d)+"px")}else"fit"===this.options.width?(this.$menu.css("min-width",""),this.$newElement.css("width","").addClass("fit-width")):this.options.width?(this.$menu.css("min-width",""),this.$newElement.css("width",this.options.width)):(this.$menu.css("min-width",""),this.$newElement.css("width",""));this.$newElement.hasClass("fit-width")&&"fit"!==this.options.width&&this.$newElement.removeClass("fit-width")},selectPosition:function(){this.$bsContainer=a('<div class="bs-container" />');var b,c,d=this,e=function(a){d.$bsContainer.addClass(a.attr("class").replace(/form-control|fit-width/gi,"")).toggleClass("dropup",a.hasClass("dropup")),b=a.offset(),c=a.hasClass("dropup")?0:a[0].offsetHeight,d.$bsContainer.css({top:b.top+c,left:b.left,width:a[0].offsetWidth})};this.$button.on("click",function(){var b=a(this);d.isDisabled()||(e(d.$newElement),d.$bsContainer.appendTo(d.options.container).toggleClass("open",!b.hasClass("open")).append(d.$menu))}),a(window).on("resize scroll",function(){e(d.$newElement)}),this.$element.on("hide.bs.select",function(){d.$menu.data("height",d.$menu.height()),d.$bsContainer.detach()})},setSelected:function(a,b,c){c||(c=this.findLis().eq(this.liObj[a])),c.toggleClass("selected",b)},setDisabled:function(a,b,c){c||(c=this.findLis().eq(this.liObj[a])),b?c.addClass("disabled").children("a").attr("href","#").attr("tabindex",-1):c.removeClass("disabled").children("a").removeAttr("href").attr("tabindex",0)},isDisabled:function(){return this.$element[0].disabled},checkDisabled:function(){var a=this;this.isDisabled()?(this.$newElement.addClass("disabled"),this.$button.addClass("disabled").attr("tabindex",-1)):(this.$button.hasClass("disabled")&&(this.$newElement.removeClass("disabled"),this.$button.removeClass("disabled")),-1!=this.$button.attr("tabindex")||this.$element.data("tabindex")||this.$button.removeAttr("tabindex")),this.$button.click(function(){return!a.isDisabled()})},tabIndex:function(){this.$element.data("tabindex")!==this.$element.attr("tabindex")&&-98!==this.$element.attr("tabindex")&&"-98"!==this.$element.attr("tabindex")&&(this.$element.data("tabindex",this.$element.attr("tabindex")),this.$button.attr("tabindex",this.$element.data("tabindex"))),this.$element.attr("tabindex",-98)},clickListener:function(){var b=this,c=a(document);this.$newElement.on("touchstart.dropdown",".dropdown-menu",function(a){a.stopPropagation()}),c.data("spaceSelect",!1),this.$button.on("keyup",function(a){/(32)/.test(a.keyCode.toString(10))&&c.data("spaceSelect")&&(a.preventDefault(),c.data("spaceSelect",!1))}),this.$button.on("click",function(){b.setSize()}),this.$element.on("shown.bs.select",function(){if(b.options.liveSearch||b.multiple){if(!b.multiple){var a=b.liObj[b.$element[0].selectedIndex];if("number"!=typeof a||b.options.size===!1)return;var c=b.$lis.eq(a)[0].offsetTop-b.$menuInner[0].offsetTop;c=c-b.$menuInner[0].offsetHeight/2+b.sizeInfo.liHeight/2,b.$menuInner[0].scrollTop=c}}else b.$menuInner.find(".selected a").focus()}),this.$menuInner.on("click","li a",function(c){var d=a(this),e=d.parent().data("originalIndex"),f=b.$element.val(),g=b.$element.prop("selectedIndex");if(b.multiple&&c.stopPropagation(),c.preventDefault(),!b.isDisabled()&&!d.parent().hasClass("disabled")){var h=b.$element.find("option"),i=h.eq(e),j=i.prop("selected"),k=i.parent("optgroup"),l=b.options.maxOptions,m=k.data("maxOptions")||!1;if(b.multiple){if(i.prop("selected",!j),b.setSelected(e,!j),d.blur(),l!==!1||m!==!1){var n=l<h.filter(":selected").length,o=m<k.find("option:selected").length;if(l&&n||m&&o)if(l&&1==l)h.prop("selected",!1),i.prop("selected",!0),b.$menuInner.find(".selected").removeClass("selected"),b.setSelected(e,!0);else if(m&&1==m){k.find("option:selected").prop("selected",!1),i.prop("selected",!0);var p=d.parent().data("optgroup");b.$menuInner.find('[data-optgroup="'+p+'"]').removeClass("selected"),b.setSelected(e,!0)}else{var q="function"==typeof b.options.maxOptionsText?b.options.maxOptionsText(l,m):b.options.maxOptionsText,r=q[0].replace("{n}",l),s=q[1].replace("{n}",m),t=a('<div class="notify"></div>');q[2]&&(r=r.replace("{var}",q[2][l>1?0:1]),s=s.replace("{var}",q[2][m>1?0:1])),i.prop("selected",!1),b.$menu.append(t),l&&n&&(t.append(a("<div>"+r+"</div>")),b.$element.trigger("maxReached.bs.select")),m&&o&&(t.append(a("<div>"+s+"</div>")),b.$element.trigger("maxReachedGrp.bs.select")),setTimeout(function(){b.setSelected(e,!1)},10),t.delay(750).fadeOut(300,function(){a(this).remove()})}}}else h.prop("selected",!1),i.prop("selected",!0),b.$menuInner.find(".selected").removeClass("selected"),b.setSelected(e,!0);b.multiple?b.options.liveSearch&&b.$searchbox.focus():b.$button.focus(),(f!=b.$element.val()&&b.multiple||g!=b.$element.prop("selectedIndex")&&!b.multiple)&&b.$element.trigger("changed.bs.select",[e,i.prop("selected"),j]).triggerNative("change")}}),this.$menu.on("click","li.disabled a, .popover-title, .popover-title :not(.close)",function(c){c.currentTarget==this&&(c.preventDefault(),c.stopPropagation(),b.options.liveSearch&&!a(c.target).hasClass("close")?b.$searchbox.focus():b.$button.focus())}),this.$menuInner.on("click",".divider, .dropdown-header",function(a){a.preventDefault(),a.stopPropagation(),b.options.liveSearch?b.$searchbox.focus():b.$button.focus()}),this.$menu.on("click",".popover-title .close",function(){b.$button.click()}),this.$searchbox.on("click",function(a){a.stopPropagation()}),this.$menu.on("click",".actions-btn",function(c){b.options.liveSearch?b.$searchbox.focus():b.$button.focus(),c.preventDefault(),c.stopPropagation(),a(this).hasClass("bs-select-all")?b.selectAll():b.deselectAll()}),this.$element.change(function(){b.render(!1)})},liveSearchListener:function(){var d=this,e=a('<li class="no-results"></li>');this.$button.on("click.dropdown.data-api touchstart.dropdown.data-api",function(){d.$menuInner.find(".active").removeClass("active"),d.$searchbox.val()&&(d.$searchbox.val(""),d.$lis.not(".is-hidden").removeClass("hidden"),e.parent().length&&e.remove()),d.multiple||d.$menuInner.find(".selected").addClass("active"),setTimeout(function(){d.$searchbox.focus()},10)}),this.$searchbox.on("click.dropdown.data-api focus.dropdown.data-api touchend.dropdown.data-api",function(a){a.stopPropagation()}),this.$searchbox.on("input propertychange",function(){if(d.$searchbox.val()){var f=d.$lis.not(".is-hidden").removeClass("hidden").children("a");f=d.options.liveSearchNormalize?f.not(":a"+d._searchStyle()+'("'+b(d.$searchbox.val())+'")'):f.not(":"+d._searchStyle()+'("'+d.$searchbox.val()+'")'),f.parent().addClass("hidden"),d.$lis.filter(".dropdown-header").each(function(){var b=a(this),c=b.data("optgroup");0===d.$lis.filter("[data-optgroup="+c+"]").not(b).not(".hidden").length&&(b.addClass("hidden"),d.$lis.filter("[data-optgroup="+c+"div]").addClass("hidden"))});var g=d.$lis.not(".hidden");g.each(function(b){var c=a(this);c.hasClass("divider")&&(c.index()===g.first().index()||c.index()===g.last().index()||g.eq(b+1).hasClass("divider"))&&c.addClass("hidden")}),d.$lis.not(".hidden, .no-results").length?e.parent().length&&e.remove():(e.parent().length&&e.remove(),e.html(d.options.noneResultsText.replace("{0}",'"'+c(d.$searchbox.val())+'"')).show(),d.$menuInner.append(e))}else d.$lis.not(".is-hidden").removeClass("hidden"),e.parent().length&&e.remove();d.$lis.filter(".active").removeClass("active"),d.$searchbox.val()&&d.$lis.not(".hidden, .divider, .dropdown-header").eq(0).addClass("active").children("a").focus(),a(this).focus()})},_searchStyle:function(){var a={begins:"ibegins",startsWith:"ibegins"};return a[this.options.liveSearchStyle]||"icontains"},val:function(a){return"undefined"!=typeof a?(this.$element.val(a),this.render(),this.$element):this.$element.val()},changeAll:function(b){"undefined"==typeof b&&(b=!0),this.findLis();for(var c=this.$element.find("option"),d=this.$lis.not(".divider, .dropdown-header, .disabled, .hidden").toggleClass("selected",b),e=d.length,f=[],g=0;e>g;g++){var h=d[g].getAttribute("data-original-index");f[f.length]=c.eq(h)[0]}a(f).prop("selected",b),this.render(!1),this.$element.trigger("changed.bs.select").triggerNative("change")},selectAll:function(){return this.changeAll(!0)},deselectAll:function(){return this.changeAll(!1)},toggle:function(a){a=a||window.event,a&&a.stopPropagation(),this.$button.trigger("click")},keydown:function(c){var d,e,f,g,h,i,j,k,l,m=a(this),n=m.is("input")?m.parent().parent():m.parent(),o=n.data("this"),p=":not(.disabled, .hidden, .dropdown-header, .divider)",q={32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9"};if(o.options.liveSearch&&(n=m.parent().parent()),o.options.container&&(n=o.$menu),d=a("[role=menu] li",n),l=o.$newElement.hasClass("open"),!l&&(c.keyCode>=48&&c.keyCode<=57||c.keyCode>=96&&c.keyCode<=105||c.keyCode>=65&&c.keyCode<=90)&&(o.options.container?o.$button.trigger("click"):(o.setSize(),o.$menu.parent().addClass("open"),l=!0),o.$searchbox.focus()),o.options.liveSearch&&(/(^9$|27)/.test(c.keyCode.toString(10))&&l&&0===o.$menu.find(".active").length&&(c.preventDefault(),o.$menu.parent().removeClass("open"),o.options.container&&o.$newElement.removeClass("open"),o.$button.focus()),d=a("[role=menu] li"+p,n),m.val()||/(38|40)/.test(c.keyCode.toString(10))||0===d.filter(".active").length&&(d=o.$menuInner.find("li"),d=o.options.liveSearchNormalize?d.filter(":a"+o._searchStyle()+"("+b(q[c.keyCode])+")"):d.filter(":"+o._searchStyle()+"("+q[c.keyCode]+")"))),d.length){if(/(38|40)/.test(c.keyCode.toString(10)))e=d.index(d.find("a").filter(":focus").parent()),g=d.filter(p).first().index(),h=d.filter(p).last().index(),f=d.eq(e).nextAll(p).eq(0).index(),i=d.eq(e).prevAll(p).eq(0).index(),j=d.eq(f).prevAll(p).eq(0).index(),o.options.liveSearch&&(d.each(function(b){a(this).hasClass("disabled")||a(this).data("index",b)}),e=d.index(d.filter(".active")),g=d.first().data("index"),h=d.last().data("index"),f=d.eq(e).nextAll().eq(0).data("index"),i=d.eq(e).prevAll().eq(0).data("index"),j=d.eq(f).prevAll().eq(0).data("index")),k=m.data("prevIndex"),38==c.keyCode?(o.options.liveSearch&&e--,e!=j&&e>i&&(e=i),g>e&&(e=g),e==k&&(e=h)):40==c.keyCode&&(o.options.liveSearch&&e++,-1==e&&(e=0),e!=j&&f>e&&(e=f),e>h&&(e=h),e==k&&(e=g)),m.data("prevIndex",e),o.options.liveSearch?(c.preventDefault(),m.hasClass("dropdown-toggle")||(d.removeClass("active").eq(e).addClass("active").children("a").focus(),m.focus())):d.eq(e).children("a").focus();else if(!m.is("input")){var r,s,t=[];d.each(function(){a(this).hasClass("disabled")||a.trim(a(this).children("a").text().toLowerCase()).substring(0,1)==q[c.keyCode]&&t.push(a(this).index())}),r=a(document).data("keycount"),r++,a(document).data("keycount",r),s=a.trim(a(":focus").text().toLowerCase()).substring(0,1),s!=q[c.keyCode]?(r=1,a(document).data("keycount",r)):r>=t.length&&(a(document).data("keycount",0),r>t.length&&(r=1)),d.eq(t[r-1]).children("a").focus()}if((/(13|32)/.test(c.keyCode.toString(10))||/(^9$)/.test(c.keyCode.toString(10))&&o.options.selectOnTab)&&l){if(/(32)/.test(c.keyCode.toString(10))||c.preventDefault(),o.options.liveSearch)/(32)/.test(c.keyCode.toString(10))||(o.$menuInner.find(".active a").click(),m.focus());else{var u=a(":focus");u.click(),u.focus(),c.preventDefault(),a(document).data("spaceSelect",!0)}a(document).data("keycount",0)}(/(^9$|27)/.test(c.keyCode.toString(10))&&l&&(o.multiple||o.options.liveSearch)||/(27)/.test(c.keyCode.toString(10))&&!l)&&(o.$menu.parent().removeClass("open"),o.options.container&&o.$newElement.removeClass("open"),o.$button.focus())}},mobile:function(){this.$element.addClass("mobile-device")},refresh:function(){this.$lis=null,this.liObj={},this.reloadLi(),this.render(),this.checkDisabled(),this.liHeight(!0),this.setStyle(),this.setWidth(),this.$lis&&this.$searchbox.trigger("propertychange"),this.$element.trigger("refreshed.bs.select")},hide:function(){this.$newElement.hide()},show:function(){this.$newElement.show()},remove:function(){this.$newElement.remove(),this.$element.remove()},destroy:function(){this.$newElement.before(this.$element).remove(),this.$bsContainer?this.$bsContainer.remove():this.$menu.remove(),this.$element.off(".bs.select").removeData("selectpicker").removeClass("bs-select-hidden selectpicker")}};var f=a.fn.selectpicker;a.fn.selectpicker=d,a.fn.selectpicker.Constructor=e,a.fn.selectpicker.noConflict=function(){return a.fn.selectpicker=f,this},a(document).data("keycount",0).on("keydown.bs.select",'.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input',e.prototype.keydown).on("focusin.modal",'.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input',function(a){a.stopPropagation()}),a(window).on("load.bs.select.data-api",function(){a(".selectpicker").each(function(){var b=a(this);d.call(b,b.data())})})}(a)});
|
8 |
//# sourceMappingURL=bootstrap-select.js.map
|
4 |
* Copyright 2013-2016 bootstrap-select
|
5 |
* Licensed under MIT (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE)
|
6 |
*/
|
7 |
+
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof exports?module.exports=b(require("jquery")):b(jQuery)}(this,function(a){!function(a){"use strict";function b(b){var c=[{re:/[\xC0-\xC6]/g,ch:"A"},{re:/[\xE0-\xE6]/g,ch:"a"},{re:/[\xC8-\xCB]/g,ch:"E"},{re:/[\xE8-\xEB]/g,ch:"e"},{re:/[\xCC-\xCF]/g,ch:"I"},{re:/[\xEC-\xEF]/g,ch:"i"},{re:/[\xD2-\xD6]/g,ch:"O"},{re:/[\xF2-\xF6]/g,ch:"o"},{re:/[\xD9-\xDC]/g,ch:"U"},{re:/[\xF9-\xFC]/g,ch:"u"},{re:/[\xC7-\xE7]/g,ch:"c"},{re:/[\xD1]/g,ch:"N"},{re:/[\xF1]/g,ch:"n"}];return a.each(c,function(){b=b.replace(this.re,this.ch)}),b}function c(a){var b={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},c="(?:"+Object.keys(b).join("|")+")",d=new RegExp(c),e=new RegExp(c,"g"),f=null==a?"":""+a;return d.test(f)?f.replace(e,function(a){return b[a]}):f}function d(b,c){var d=arguments,f=b,g=c;[].shift.apply(d);var h,i=this.each(function(){var b=a(this);if(b.is("select")){var c=b.data("selectpicker"),i="object"==typeof f&&f;if(c){if(i)for(var j in i)i.hasOwnProperty(j)&&(c.options[j]=i[j])}else{var k=a.extend({},e.DEFAULTS,a.fn.selectpicker.defaults||{},b.data(),i);k.template=a.extend({},e.DEFAULTS.template,a.fn.selectpicker.defaults?a.fn.selectpicker.defaults.template:{},b.data().template,i.template),b.data("selectpicker",c=new e(this,k,g))}"string"==typeof f&&(h=c[f]instanceof Function?c[f].apply(c,d):c.options[f])}});return"undefined"!=typeof h?h:i}String.prototype.includes||!function(){var a={}.toString,b=function(){try{var a={},b=Object.defineProperty,c=b(a,a,a)&&b}catch(d){}return c}(),c="".indexOf,d=function(b){if(null==this)throw new TypeError;var d=String(this);if(b&&"[object RegExp]"==a.call(b))throw new TypeError;var e=d.length,f=String(b),g=f.length,h=arguments.length>1?arguments[1]:void 0,i=h?Number(h):0;i!=i&&(i=0);var j=Math.min(Math.max(i,0),e);return g+j>e?!1:-1!=c.call(d,f,i)};b?b(String.prototype,"includes",{value:d,configurable:!0,writable:!0}):String.prototype.includes=d}(),String.prototype.startsWith||!function(){var a=function(){try{var a={},b=Object.defineProperty,c=b(a,a,a)&&b}catch(d){}return c}(),b={}.toString,c=function(a){if(null==this)throw new TypeError;var c=String(this);if(a&&"[object RegExp]"==b.call(a))throw new TypeError;var d=c.length,e=String(a),f=e.length,g=arguments.length>1?arguments[1]:void 0,h=g?Number(g):0;h!=h&&(h=0);var i=Math.min(Math.max(h,0),d);if(f+i>d)return!1;for(var j=-1;++j<f;)if(c.charCodeAt(i+j)!=e.charCodeAt(j))return!1;return!0};a?a(String.prototype,"startsWith",{value:c,configurable:!0,writable:!0}):String.prototype.startsWith=c}(),Object.keys||(Object.keys=function(a,b,c){c=[];for(b in a)c.hasOwnProperty.call(a,b)&&c.push(b);return c}),a.fn.triggerNative=function(a){var b,c=this[0];c.dispatchEvent?("function"==typeof Event?b=new Event(a,{bubbles:!0}):(b=document.createEvent("Event"),b.initEvent(a,!0,!1)),c.dispatchEvent(b)):(c.fireEvent&&(b=document.createEventObject(),b.eventType=a,c.fireEvent("on"+a,b)),this.trigger(a))},a.expr[":"].icontains=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.text()).toUpperCase();return f.includes(d[3].toUpperCase())},a.expr[":"].ibegins=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.text()).toUpperCase();return f.startsWith(d[3].toUpperCase())},a.expr[":"].aicontains=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.data("normalizedText")||e.text()).toUpperCase();return f.includes(d[3].toUpperCase())},a.expr[":"].aibegins=function(b,c,d){var e=a(b),f=(e.data("tokens")||e.data("normalizedText")||e.text()).toUpperCase();return f.startsWith(d[3].toUpperCase())};var e=function(b,c,d){d&&(d.stopPropagation(),d.preventDefault()),this.$element=a(b),this.$newElement=null,this.$button=null,this.$menu=null,this.$lis=null,this.options=c,null===this.options.title&&(this.options.title=this.$element.attr("title")),this.val=e.prototype.val,this.render=e.prototype.render,this.refresh=e.prototype.refresh,this.setStyle=e.prototype.setStyle,this.selectAll=e.prototype.selectAll,this.deselectAll=e.prototype.deselectAll,this.destroy=e.prototype.destroy,this.remove=e.prototype.remove,this.show=e.prototype.show,this.hide=e.prototype.hide,this.init()};e.VERSION="1.10.0",e.DEFAULTS={noneSelectedText:"None selected",noneResultsText:"No results matched {0}",countSelectedText:function(a,b){return 1==a?"{0} item selected":"{0} items selected"},maxOptionsText:function(a,b){return[1==a?"Limit reached ({n} item max)":"Limit reached ({n} items max)",1==b?"Group limit reached ({n} item max)":"Group limit reached ({n} items max)"]},selectAllText:"Select All",deselectAllText:"Deselect All",doneButton:!1,doneButtonText:"Close",multipleSeparator:", ",styleBase:"btn",style:"btn-default",size:"auto",title:null,selectedTextFormat:"values",width:!1,container:!1,hideDisabled:!1,showSubtext:!1,showIcon:!0,showContent:!0,dropupAuto:!0,header:!1,liveSearch:!1,liveSearchPlaceholder:null,liveSearchNormalize:!1,liveSearchStyle:"contains",actionsBox:!1,iconBase:"glyphicon",tickIcon:"glyphicon-ok",showTick:!1,template:{caret:'<span class="caret"></span>'},maxOptions:!1,mobile:!1,selectOnTab:!1,dropdownAlignRight:!1},e.prototype={constructor:e,init:function(){var b=this,c=this.$element.attr("id");this.$element.addClass("bs-select-hidden"),this.liObj={},this.multiple=this.$element.prop("multiple"),this.autofocus=this.$element.prop("autofocus"),this.$newElement=this.createView(),this.$element.after(this.$newElement).appendTo(this.$newElement),this.$button=this.$newElement.children("button"),this.$menu=this.$newElement.children(".dropdown-menu"),this.$menuInner=this.$menu.children(".inner"),this.$searchbox=this.$menu.find("input"),this.$element.removeClass("bs-select-hidden"),this.options.dropdownAlignRight&&this.$menu.addClass("dropdown-menu-right"),"undefined"!=typeof c&&(this.$button.attr("data-id",c),a('label[for="'+c+'"]').click(function(a){a.preventDefault(),b.$button.focus()})),this.checkDisabled(),this.clickListener(),this.options.liveSearch&&this.liveSearchListener(),this.render(),this.setStyle(),this.setWidth(),this.options.container&&this.selectPosition(),this.$menu.data("this",this),this.$newElement.data("this",this),this.options.mobile&&this.mobile(),this.$newElement.on({"hide.bs.dropdown":function(a){b.$element.trigger("hide.bs.select",a)},"hidden.bs.dropdown":function(a){b.$element.trigger("hidden.bs.select",a)},"show.bs.dropdown":function(a){b.$element.trigger("show.bs.select",a)},"shown.bs.dropdown":function(a){b.$element.trigger("shown.bs.select",a)}}),b.$element[0].hasAttribute("required")&&this.$element.on("invalid",function(){b.$button.addClass("bs-invalid").focus(),b.$element.on({"focus.bs.select":function(){b.$button.focus(),b.$element.off("focus.bs.select")},"shown.bs.select":function(){b.$element.val(b.$element.val()).off("shown.bs.select")},"rendered.bs.select":function(){this.validity.valid&&b.$button.removeClass("bs-invalid"),b.$element.off("rendered.bs.select")}})}),setTimeout(function(){b.$element.trigger("loaded.bs.select")})},createDropdown:function(){var b=this.multiple||this.options.showTick?" show-tick":"",d=this.$element.parent().hasClass("input-group")?" input-group-btn":"",e=this.autofocus?" autofocus":"",f=this.options.header?'<div class="popover-title"><button type="button" class="close" aria-hidden="true">×</button>'+this.options.header+"</div>":"",g=this.options.liveSearch?'<div class="bs-searchbox"><input type="text" class="form-control" autocomplete="off"'+(null===this.options.liveSearchPlaceholder?"":' placeholder="'+c(this.options.liveSearchPlaceholder)+'"')+"></div>":"",h=this.multiple&&this.options.actionsBox?'<div class="bs-actionsbox"><div class="btn-group btn-group-sm btn-block"><button type="button" class="actions-btn bs-select-all btn btn-default">'+this.options.selectAllText+'</button><button type="button" class="actions-btn bs-deselect-all btn btn-default">'+this.options.deselectAllText+"</button></div></div>":"",i=this.multiple&&this.options.doneButton?'<div class="bs-donebutton"><div class="btn-group btn-block"><button type="button" class="btn btn-sm btn-default">'+this.options.doneButtonText+"</button></div></div>":"",j='<div class="btn-group bootstrap-select'+b+d+'"><button type="button" class="'+this.options.styleBase+' dropdown-toggle" data-toggle="dropdown"'+e+'><span class="filter-option pull-left"></span> <span class="bs-caret">'+this.options.template.caret+'</span></button><div class="dropdown-menu open">'+f+g+h+'<ul class="dropdown-menu inner" role="menu"></ul>'+i+"</div></div>";return a(j)},createView:function(){var a=this.createDropdown(),b=this.createLi();return a.find("ul")[0].innerHTML=b,a},reloadLi:function(){this.destroyLi();var a=this.createLi();this.$menuInner[0].innerHTML=a},destroyLi:function(){this.$menu.find("li").remove()},createLi:function(){var d=this,e=[],f=0,g=document.createElement("option"),h=-1,i=function(a,b,c,d){return"<li"+("undefined"!=typeof c&""!==c?' class="'+c+'"':"")+("undefined"!=typeof b&null!==b?' data-original-index="'+b+'"':"")+("undefined"!=typeof d&null!==d?'data-optgroup="'+d+'"':"")+">"+a+"</li>"},j=function(a,e,f,g){return'<a tabindex="0"'+("undefined"!=typeof e?' class="'+e+'"':"")+("undefined"!=typeof f?' style="'+f+'"':"")+(d.options.liveSearchNormalize?' data-normalized-text="'+b(c(a))+'"':"")+("undefined"!=typeof g||null!==g?' data-tokens="'+g+'"':"")+">"+a+'<span class="'+d.options.iconBase+" "+d.options.tickIcon+' check-mark"></span></a>'};if(this.options.title&&!this.multiple&&(h--,!this.$element.find(".bs-title-option").length)){var k=this.$element[0];g.className="bs-title-option",g.appendChild(document.createTextNode(this.options.title)),g.value="",k.insertBefore(g,k.firstChild),void 0===a(k.options[k.selectedIndex]).attr("selected")&&(g.selected=!0)}return this.$element.find("option").each(function(b){var c=a(this);if(h++,!c.hasClass("bs-title-option")){var g=this.className||"",k=this.style.cssText,l=c.data("content")?c.data("content"):c.html(),m=c.data("tokens")?c.data("tokens"):null,n="undefined"!=typeof c.data("subtext")?'<small class="text-muted">'+c.data("subtext")+"</small>":"",o="undefined"!=typeof c.data("icon")?'<span class="'+d.options.iconBase+" "+c.data("icon")+'"></span> ':"",p="OPTGROUP"===this.parentNode.tagName,q=this.disabled||p&&this.parentNode.disabled;if(""!==o&&q&&(o="<span>"+o+"</span>"),d.options.hideDisabled&&q&&!p)return void h--;if(c.data("content")||(l=o+'<span class="text">'+l+n+"</span>"),p&&c.data("divider")!==!0){var r=" "+this.parentNode.className||"";if(0===c.index()){f+=1;var s=this.parentNode.label,t="undefined"!=typeof c.parent().data("subtext")?'<small class="text-muted">'+c.parent().data("subtext")+"</small>":"",u=c.parent().data("icon")?'<span class="'+d.options.iconBase+" "+c.parent().data("icon")+'"></span> ':"";s=u+'<span class="text">'+s+t+"</span>",0!==b&&e.length>0&&(h++,e.push(i("",null,"divider",f+"div"))),h++,e.push(i(s,null,"dropdown-header"+r,f))}if(d.options.hideDisabled&&q)return void h--;e.push(i(j(l,"opt "+g+r,k,m),b,"",f))}else c.data("divider")===!0?e.push(i("",b,"divider")):c.data("hidden")===!0?e.push(i(j(l,g,k,m),b,"hidden is-hidden")):(this.previousElementSibling&&"OPTGROUP"===this.previousElementSibling.tagName&&(h++,e.push(i("",null,"divider",f+"div"))),e.push(i(j(l,g,k,m),b)));d.liObj[b]=h}}),this.multiple||0!==this.$element.find("option:selected").length||this.options.title||this.$element.find("option").eq(0).prop("selected",!0).attr("selected","selected"),e.join("")},findLis:function(){return null==this.$lis&&(this.$lis=this.$menu.find("li")),this.$lis},render:function(b){var c,d=this;b!==!1&&this.$element.find("option").each(function(a){var b=d.findLis().eq(d.liObj[a]);d.setDisabled(a,this.disabled||"OPTGROUP"===this.parentNode.tagName&&this.parentNode.disabled,b),d.setSelected(a,this.selected,b)}),this.tabIndex();var e=this.$element.find("option").map(function(){if(this.selected){if(d.options.hideDisabled&&(this.disabled||"OPTGROUP"===this.parentNode.tagName&&this.parentNode.disabled))return;var b,c=a(this),e=c.data("icon")&&d.options.showIcon?'<i class="'+d.options.iconBase+" "+c.data("icon")+'"></i> ':"";return b=d.options.showSubtext&&c.data("subtext")&&!d.multiple?' <small class="text-muted">'+c.data("subtext")+"</small>":"","undefined"!=typeof c.attr("title")?c.attr("title"):c.data("content")&&d.options.showContent?c.data("content"):e+c.html()+b}}).toArray(),f=this.multiple?e.join(this.options.multipleSeparator):e[0];if(this.multiple&&this.options.selectedTextFormat.indexOf("count")>-1){var g=this.options.selectedTextFormat.split(">");if(g.length>1&&e.length>g[1]||1==g.length&&e.length>=2){c=this.options.hideDisabled?", [disabled]":"";var h=this.$element.find("option").not('[data-divider="true"], [data-hidden="true"]'+c).length,i="function"==typeof this.options.countSelectedText?this.options.countSelectedText(e.length,h):this.options.countSelectedText;f=i.replace("{0}",e.length.toString()).replace("{1}",h.toString())}}void 0==this.options.title&&(this.options.title=this.$element.attr("title")),"static"==this.options.selectedTextFormat&&(f=this.options.title),f||(f="undefined"!=typeof this.options.title?this.options.title:this.options.noneSelectedText),this.$button.attr("title",a.trim(f.replace(/<[^>]*>?/g,""))),this.$button.children(".filter-option").html(f),this.$element.trigger("rendered.bs.select")},setStyle:function(a,b){this.$element.attr("class")&&this.$newElement.addClass(this.$element.attr("class").replace(/selectpicker|mobile-device|bs-select-hidden|validate\[.*\]/gi,""));var c=a?a:this.options.style;"add"==b?this.$button.addClass(c):"remove"==b?this.$button.removeClass(c):(this.$button.removeClass(this.options.style),this.$button.addClass(c))},liHeight:function(b){if(b||this.options.size!==!1&&!this.sizeInfo){var c=document.createElement("div"),d=document.createElement("div"),e=document.createElement("ul"),f=document.createElement("li"),g=document.createElement("li"),h=document.createElement("a"),i=document.createElement("span"),j=this.options.header&&this.$menu.find(".popover-title").length>0?this.$menu.find(".popover-title")[0].cloneNode(!0):null,k=this.options.liveSearch?document.createElement("div"):null,l=this.options.actionsBox&&this.multiple&&this.$menu.find(".bs-actionsbox").length>0?this.$menu.find(".bs-actionsbox")[0].cloneNode(!0):null,m=this.options.doneButton&&this.multiple&&this.$menu.find(".bs-donebutton").length>0?this.$menu.find(".bs-donebutton")[0].cloneNode(!0):null;if(i.className="text",c.className=this.$menu[0].parentNode.className+" open",d.className="dropdown-menu open",e.className="dropdown-menu inner",f.className="divider",i.appendChild(document.createTextNode("Inner text")),h.appendChild(i),g.appendChild(h),e.appendChild(g),e.appendChild(f),j&&d.appendChild(j),k){var n=document.createElement("span");k.className="bs-searchbox",n.className="form-control",k.appendChild(n),d.appendChild(k)}l&&d.appendChild(l),d.appendChild(e),m&&d.appendChild(m),c.appendChild(d),document.body.appendChild(c);var o=h.offsetHeight,p=j?j.offsetHeight:0,q=k?k.offsetHeight:0,r=l?l.offsetHeight:0,s=m?m.offsetHeight:0,t=a(f).outerHeight(!0),u="function"==typeof getComputedStyle?getComputedStyle(d):!1,v=u?null:a(d),w=parseInt(u?u.paddingTop:v.css("paddingTop"))+parseInt(u?u.paddingBottom:v.css("paddingBottom"))+parseInt(u?u.borderTopWidth:v.css("borderTopWidth"))+parseInt(u?u.borderBottomWidth:v.css("borderBottomWidth")),x=w+parseInt(u?u.marginTop:v.css("marginTop"))+parseInt(u?u.marginBottom:v.css("marginBottom"))+2;document.body.removeChild(c),this.sizeInfo={liHeight:o,headerHeight:p,searchHeight:q,actionsHeight:r,doneButtonHeight:s,dividerHeight:t,menuPadding:w,menuExtras:x}}},setSize:function(){if(this.findLis(),this.liHeight(),this.options.header&&this.$menu.css("padding-top",0),this.options.size!==!1){var b,c,d,e,f=this,g=this.$menu,h=this.$menuInner,i=a(window),j=this.$newElement[0].offsetHeight,k=this.sizeInfo.liHeight,l=this.sizeInfo.headerHeight,m=this.sizeInfo.searchHeight,n=this.sizeInfo.actionsHeight,o=this.sizeInfo.doneButtonHeight,p=this.sizeInfo.dividerHeight,q=this.sizeInfo.menuPadding,r=this.sizeInfo.menuExtras,s=this.options.hideDisabled?".disabled":"",t=function(){d=f.$newElement.offset().top-i.scrollTop(),e=i.height()-d-j};if(t(),"auto"===this.options.size){var u=function(){var i,j=function(b,c){return function(d){return c?d.classList?d.classList.contains(b):a(d).hasClass(b):!(d.classList?d.classList.contains(b):a(d).hasClass(b))}},p=f.$menuInner[0].getElementsByTagName("li"),s=Array.prototype.filter?Array.prototype.filter.call(p,j("hidden",!1)):f.$lis.not(".hidden"),u=Array.prototype.filter?Array.prototype.filter.call(s,j("dropdown-header",!0)):s.filter(".dropdown-header");t(),b=e-r,f.options.container?(g.data("height")||g.data("height",g.height()),c=g.data("height")):c=g.height(),f.options.dropupAuto&&f.$newElement.toggleClass("dropup",d>e&&c>b-r),f.$newElement.hasClass("dropup")&&(b=d-r),i=s.length+u.length>3?3*k+r-2:0,g.css({"max-height":b+"px",overflow:"hidden","min-height":i+l+m+n+o+"px"}),h.css({"max-height":b-l-m-n-o-q+"px","overflow-y":"auto","min-height":Math.max(i-q,0)+"px"})};u(),this.$searchbox.off("input.getSize propertychange.getSize").on("input.getSize propertychange.getSize",u),i.off("resize.getSize scroll.getSize").on("resize.getSize scroll.getSize",u)}else if(this.options.size&&"auto"!=this.options.size&&this.$lis.not(s).length>this.options.size){var v=this.$lis.not(".divider").not(s).children().slice(0,this.options.size).last().parent().index(),w=this.$lis.slice(0,v+1).filter(".divider").length;b=k*this.options.size+w*p+q,f.options.container?(g.data("height")||g.data("height",g.height()),c=g.data("height")):c=g.height(),f.options.dropupAuto&&this.$newElement.toggleClass("dropup",d>e&&c>b-r),g.css({"max-height":b+l+m+n+o+"px",overflow:"hidden","min-height":""}),h.css({"max-height":b-q+"px","overflow-y":"auto","min-height":""})}}},setWidth:function(){if("auto"===this.options.width){this.$menu.css("min-width","0");var a=this.$menu.parent().clone().appendTo("body"),b=this.options.container?this.$newElement.clone().appendTo("body"):a,c=a.children(".dropdown-menu").outerWidth(),d=b.css("width","auto").children("button").outerWidth();a.remove(),b.remove(),this.$newElement.css("width",Math.max(c,d)+"px")}else"fit"===this.options.width?(this.$menu.css("min-width",""),this.$newElement.css("width","").addClass("fit-width")):this.options.width?(this.$menu.css("min-width",""),this.$newElement.css("width",this.options.width)):(this.$menu.css("min-width",""),this.$newElement.css("width",""));this.$newElement.hasClass("fit-width")&&"fit"!==this.options.width&&this.$newElement.removeClass("fit-width")},selectPosition:function(){this.$bsContainer=a('<div class="bs-container" />');var b,c,d=this,e=function(a){d.$bsContainer.addClass(a.attr("class").replace(/form-control|fit-width/gi,"")).toggleClass("dropup",a.hasClass("dropup")),b=a.offset(),c=a.hasClass("dropup")?0:a[0].offsetHeight,d.$bsContainer.css({top:b.top+c,left:b.left,width:a[0].offsetWidth})};this.$button.on("click",function(){var b=a(this);d.isDisabled()||(e(d.$newElement),d.$bsContainer.appendTo(d.options.container).toggleClass("open",!b.hasClass("open")).append(d.$menu))}),a(window).on("resize scroll",function(){e(d.$newElement)}),this.$element.on("hide.bs.select",function(){d.$menu.data("height",d.$menu.height()),d.$bsContainer.detach()})},setSelected:function(a,b,c){c||(c=this.findLis().eq(this.liObj[a])),c.toggleClass("selected",b)},setDisabled:function(a,b,c){c||(c=this.findLis().eq(this.liObj[a])),b?c.addClass("disabled").children("a").attr("href","#").attr("tabindex",-1):c.removeClass("disabled").children("a").removeAttr("href").attr("tabindex",0)},isDisabled:function(){return this.$element[0].disabled},checkDisabled:function(){var a=this;this.isDisabled()?(this.$newElement.addClass("disabled"),this.$button.addClass("disabled").attr("tabindex",-1)):(this.$button.hasClass("disabled")&&(this.$newElement.removeClass("disabled"),this.$button.removeClass("disabled")),-1!=this.$button.attr("tabindex")||this.$element.data("tabindex")||this.$button.removeAttr("tabindex")),this.$button.click(function(){return!a.isDisabled()})},tabIndex:function(){this.$element.data("tabindex")!==this.$element.attr("tabindex")&&-98!==this.$element.attr("tabindex")&&"-98"!==this.$element.attr("tabindex")&&(this.$element.data("tabindex",this.$element.attr("tabindex")),this.$button.attr("tabindex",this.$element.data("tabindex"))),this.$element.attr("tabindex",-98)},clickListener:function(){var b=this,c=a(document);this.$newElement.on("touchstart.dropdown",".dropdown-menu",function(a){a.stopPropagation()}),c.data("spaceSelect",!1),this.$button.on("keyup",function(a){/(32)/.test(a.keyCode.toString(10))&&c.data("spaceSelect")&&(a.preventDefault(),c.data("spaceSelect",!1))}),this.$button.on("click",function(){b.setSize()}),this.$element.on("shown.bs.select",function(){if(b.options.liveSearch||b.multiple){if(!b.multiple){var a=b.liObj[b.$element[0].selectedIndex];if("number"!=typeof a||b.options.size===!1)return;var c=b.$lis.eq(a)[0].offsetTop-b.$menuInner[0].offsetTop;c=c-b.$menuInner[0].offsetHeight/2+b.sizeInfo.liHeight/2,b.$menuInner[0].scrollTop=c}}else b.$menuInner.find(".selected a").focus()}),this.$menuInner.on("click","li a",function(c){var d=a(this),e=d.parent().data("originalIndex"),f=b.$element.val(),g=b.$element.prop("selectedIndex");if(b.multiple&&c.stopPropagation(),c.preventDefault(),!b.isDisabled()&&!d.parent().hasClass("disabled")){var h=b.$element.find("option"),i=h.eq(e),j=i.prop("selected"),k=i.parent("optgroup"),l=b.options.maxOptions,m=k.data("maxOptions")||!1;if(b.multiple){if(i.prop("selected",!j),b.setSelected(e,!j),d.blur(),l!==!1||m!==!1){var n=l<h.filter(":selected").length,o=m<k.find("option:selected").length;if(l&&n||m&&o)if(l&&1==l)h.prop("selected",!1),i.prop("selected",!0),b.$menuInner.find(".selected").removeClass("selected"),b.setSelected(e,!0);else if(m&&1==m){k.find("option:selected").prop("selected",!1),i.prop("selected",!0);var p=d.parent().data("optgroup");b.$menuInner.find('[data-optgroup="'+p+'"]').removeClass("selected"),b.setSelected(e,!0)}else{var q="function"==typeof b.options.maxOptionsText?b.options.maxOptionsText(l,m):b.options.maxOptionsText,r=q[0].replace("{n}",l),s=q[1].replace("{n}",m),t=a('<div class="notify"></div>');q[2]&&(r=r.replace("{var}",q[2][l>1?0:1]),s=s.replace("{var}",q[2][m>1?0:1])),i.prop("selected",!1),b.$menu.append(t),l&&n&&(t.append(a("<div>"+r+"</div>")),b.$element.trigger("maxReached.bs.select")),m&&o&&(t.append(a("<div>"+s+"</div>")),b.$element.trigger("maxReachedGrp.bs.select")),setTimeout(function(){b.setSelected(e,!1)},10),t.delay(750).fadeOut(300,function(){a(this).remove()})}}}else h.prop("selected",!1),i.prop("selected",!0),b.$menuInner.find(".selected").removeClass("selected"),b.setSelected(e,!0);b.multiple?b.options.liveSearch&&b.$searchbox.focus():b.$button.focus(),(f!=b.$element.val()&&b.multiple||g!=b.$element.prop("selectedIndex")&&!b.multiple)&&b.$element.trigger("changed.bs.select",[e,i.prop("selected"),j]).triggerNative("change")}}),this.$menu.on("click","li.disabled a, .popover-title, .popover-title :not(.close)",function(c){c.currentTarget==this&&(c.preventDefault(),c.stopPropagation(),b.options.liveSearch&&!a(c.target).hasClass("close")?b.$searchbox.focus():b.$button.focus())}),this.$menuInner.on("click",".divider, .dropdown-header",function(a){a.preventDefault(),a.stopPropagation(),b.options.liveSearch?b.$searchbox.focus():b.$button.focus()}),this.$menu.on("click",".popover-title .close",function(){b.$button.click()}),this.$searchbox.on("click",function(a){a.stopPropagation()}),this.$menu.on("click",".actions-btn",function(c){b.options.liveSearch?b.$searchbox.focus():b.$button.focus(),c.preventDefault(),c.stopPropagation(),a(this).hasClass("bs-select-all")?b.selectAll():b.deselectAll()}),this.$element.change(function(){b.render(!1)})},liveSearchListener:function(){var d=this,e=a('<li class="no-results"></li>');this.$button.on("click.dropdown.data-api touchstart.dropdown.data-api",function(){d.$menuInner.find(".active").removeClass("active"),d.$searchbox.val()&&(d.$searchbox.val(""),d.$lis.not(".is-hidden").removeClass("hidden"),e.parent().length&&e.remove()),d.multiple||d.$menuInner.find(".selected").addClass("active"),setTimeout(function(){d.$searchbox.focus()},10)}),this.$searchbox.on("click.dropdown.data-api focus.dropdown.data-api touchend.dropdown.data-api",function(a){a.stopPropagation()}),this.$searchbox.on("input propertychange",function(){if(d.$searchbox.val()){var f=d.$lis.not(".is-hidden").removeClass("hidden").children("a");f=d.options.liveSearchNormalize?f.not(":a"+d._searchStyle()+'("'+b(d.$searchbox.val())+'")'):f.not(":"+d._searchStyle()+'("'+d.$searchbox.val()+'")'),f.parent().addClass("hidden"),d.$lis.filter(".dropdown-header").each(function(){var b=a(this),c=b.data("optgroup");0===d.$lis.filter("[data-optgroup="+c+"]").not(b).not(".hidden").length&&(b.addClass("hidden"),d.$lis.filter("[data-optgroup="+c+"div]").addClass("hidden"))});var g=d.$lis.not(".hidden");g.each(function(b){var c=a(this);c.hasClass("divider")&&(c.index()===g.first().index()||c.index()===g.last().index()||g.eq(b+1).hasClass("divider"))&&c.addClass("hidden")}),d.$lis.not(".hidden, .no-results").length?e.parent().length&&e.remove():(e.parent().length&&e.remove(),e.html(d.options.noneResultsText.replace("{0}",'"'+c(d.$searchbox.val())+'"')).show(),d.$menuInner.append(e))}else d.$lis.not(".is-hidden").removeClass("hidden"),e.parent().length&&e.remove();d.$lis.filter(".active").removeClass("active"),d.$searchbox.val()&&d.$lis.not(".hidden, .divider, .dropdown-header").eq(0).addClass("active").children("a").focus(),a(this).focus()})},_searchStyle:function(){var a={begins:"ibegins",startsWith:"ibegins"};return a[this.options.liveSearchStyle]||"icontains"},val:function(a){return"undefined"!=typeof a?(this.$element.val(a),this.render(),this.$element):this.$element.val()},changeAll:function(b){"undefined"==typeof b&&(b=!0),this.findLis();for(var c=this.$element.find("option"),d=this.$lis.not(".divider, .dropdown-header, .disabled, .hidden").toggleClass("selected",b),e=d.length,f=[],g=0;e>g;g++){var h=d[g].getAttribute("data-original-index");f[f.length]=c.eq(h)[0]}a(f).prop("selected",b),this.render(!1),this.$element.trigger("changed.bs.select").triggerNative("change")},selectAll:function(){return this.changeAll(!0)},deselectAll:function(){return this.changeAll(!1)},toggle:function(a){a=a||window.event,a&&a.stopPropagation(),this.$button.trigger("click")},keydown:function(c){var d,e,f,g,h,i,j,k,l,m=a(this),n=m.is("input")?m.parent().parent():m.parent(),o=n.data("this"),p=":not(.disabled, .hidden, .dropdown-header, .divider)",q={32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9"};if(o.options.liveSearch&&(n=m.parent().parent()),o.options.container&&(n=o.$menu),d=a("[role=menu] li",n),l=o.$newElement.hasClass("open"),!l&&(c.keyCode>=48&&c.keyCode<=57||c.keyCode>=96&&c.keyCode<=105||c.keyCode>=65&&c.keyCode<=90)&&(o.options.container?o.$button.trigger("click"):(o.setSize(),o.$menu.parent().addClass("open"),l=!0),o.$searchbox.focus()),o.options.liveSearch&&(/(^9$|27)/.test(c.keyCode.toString(10))&&l&&0===o.$menu.find(".active").length&&(c.preventDefault(),o.$menu.parent().removeClass("open"),o.options.container&&o.$newElement.removeClass("open"),o.$button.focus()),d=a("[role=menu] li"+p,n),m.val()||/(38|40)/.test(c.keyCode.toString(10))||0===d.filter(".active").length&&(d=o.$menuInner.find("li"),d=o.options.liveSearchNormalize?d.filter(":a"+o._searchStyle()+"("+b(q[c.keyCode])+")"):d.filter(":"+o._searchStyle()+"("+q[c.keyCode]+")"))),d.length){if(/(38|40)/.test(c.keyCode.toString(10)))e=d.index(d.find("a").filter(":focus").parent()),g=d.filter(p).first().index(),h=d.filter(p).last().index(),f=d.eq(e).nextAll(p).eq(0).index(),i=d.eq(e).prevAll(p).eq(0).index(),j=d.eq(f).prevAll(p).eq(0).index(),o.options.liveSearch&&(d.each(function(b){a(this).hasClass("disabled")||a(this).data("index",b)}),e=d.index(d.filter(".active")),g=d.first().data("index"),h=d.last().data("index"),f=d.eq(e).nextAll().eq(0).data("index"),i=d.eq(e).prevAll().eq(0).data("index"),j=d.eq(f).prevAll().eq(0).data("index")),k=m.data("prevIndex"),38==c.keyCode?(o.options.liveSearch&&e--,e!=j&&e>i&&(e=i),g>e&&(e=g),e==k&&(e=h)):40==c.keyCode&&(o.options.liveSearch&&e++,-1==e&&(e=0),e!=j&&f>e&&(e=f),e>h&&(e=h),e==k&&(e=g)),m.data("prevIndex",e),o.options.liveSearch?(c.preventDefault(),m.hasClass("dropdown-toggle")||(d.removeClass("active").eq(e).addClass("active").children("a").focus(),m.focus())):d.eq(e).children("a").focus();else if(!m.is("input")){var r,s,t=[];d.each(function(){a(this).hasClass("disabled")||a.trim(a(this).children("a").text().toLowerCase()).substring(0,1)==q[c.keyCode]&&t.push(a(this).index())}),r=a(document).data("keycount"),r++,a(document).data("keycount",r),s=a.trim(a(":focus").text().toLowerCase()).substring(0,1),s!=q[c.keyCode]?(r=1,a(document).data("keycount",r)):r>=t.length&&(a(document).data("keycount",0),r>t.length&&(r=1)),d.eq(t[r-1]).children("a").focus()}if((/(13|32)/.test(c.keyCode.toString(10))||/(^9$)/.test(c.keyCode.toString(10))&&o.options.selectOnTab)&&l){if(/(32)/.test(c.keyCode.toString(10))||c.preventDefault(),o.options.liveSearch)/(32)/.test(c.keyCode.toString(10))||(o.$menuInner.find(".active a").click(),m.focus());else{var u=a(":focus");u.click(),u.focus(),c.preventDefault(),a(document).data("spaceSelect",!0)}a(document).data("keycount",0)}(/(^9$|27)/.test(c.keyCode.toString(10))&&l&&(o.multiple||o.options.liveSearch)||/(27)/.test(c.keyCode.toString(10))&&!l)&&(o.$menu.parent().removeClass("open"),o.options.container&&o.$newElement.removeClass("open"),o.$button.focus())}},mobile:function(){this.$element.addClass("mobile-device")},refresh:function(){this.$lis=null,this.liObj={},this.reloadLi(),this.render(),this.checkDisabled(),this.liHeight(!0),this.setStyle(),this.setWidth(),this.$lis&&this.$searchbox.trigger("propertychange"),this.$element.trigger("refreshed.bs.select")},hide:function(){this.$newElement.hide()},show:function(){this.$newElement.show()},remove:function(){this.$newElement.remove(),this.$element.remove()},destroy:function(){this.$newElement.before(this.$element).remove(),this.$bsContainer?this.$bsContainer.remove():this.$menu.remove(),this.$element.off(".bs.select").removeData("selectpicker").removeClass("bs-select-hidden selectpicker")}};var f=a.fn.selectpicker;a.fn.selectpicker=d,a.fn.selectpicker.Constructor=e,a.fn.selectpicker.noConflict=function(){return a.fn.selectpicker=f,this},a(document).data("keycount",0).on("keydown.bs.select",'.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input',e.prototype.keydown).on("focusin.modal",'.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input',function(a){a.stopPropagation()}),a(window).on("load.bs.select.data-api",function(){a(".selectpicker").each(function(){var b=a(this);d.call(b,b.data({liveSearch: true}))})})}(a)});
|
8 |
//# sourceMappingURL=bootstrap-select.js.map
|
helper/general-helper-3.php
CHANGED
@@ -269,14 +269,17 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
269 |
if ($is_id) {
|
270 |
$id = $item;
|
271 |
} else {
|
272 |
-
|
|
|
|
|
|
|
|
|
273 |
}
|
274 |
$id = intval($id);
|
275 |
if (!$id) return false;
|
276 |
|
277 |
$categories = array();
|
278 |
$current_categories = wp_get_post_terms($id, 'product_cat');
|
279 |
-
|
280 |
foreach ($current_categories as $category) {
|
281 |
$categories[] = $category->term_id;
|
282 |
}
|
269 |
if ($is_id) {
|
270 |
$id = $item;
|
271 |
} else {
|
272 |
+
//for variant product
|
273 |
+
$id = $item['data']->get_parent_id();
|
274 |
+
if(!$id){
|
275 |
+
$id = $item['data']->get_id();
|
276 |
+
}
|
277 |
}
|
278 |
$id = intval($id);
|
279 |
if (!$id) return false;
|
280 |
|
281 |
$categories = array();
|
282 |
$current_categories = wp_get_post_terms($id, 'product_cat');
|
|
|
283 |
foreach ($current_categories as $category) {
|
284 |
$categories[] = $category->term_id;
|
285 |
}
|
helper/general-helper.php
CHANGED
@@ -269,7 +269,11 @@ if ( ! class_exists( 'woo_dicount_rules_generalHelper' ) ) {
|
|
269 |
if ($is_id) {
|
270 |
$id = $item;
|
271 |
} else {
|
272 |
-
|
|
|
|
|
|
|
|
|
273 |
}
|
274 |
$id = intval($id);
|
275 |
if (!$id) return false;
|
269 |
if ($is_id) {
|
270 |
$id = $item;
|
271 |
} else {
|
272 |
+
//for variant product
|
273 |
+
$id = $item['data']->parent_id;
|
274 |
+
if(!$id){
|
275 |
+
$id = $item['data']->id;
|
276 |
+
}
|
277 |
}
|
278 |
$id = intval($id);
|
279 |
if (!$id) return false;
|
includes/pricing-productbased.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
+
/**
|
4 |
+
* Class WooDiscountRulesPrice_ProductBased
|
5 |
+
*/
|
6 |
+
if (!class_exists('WooDiscountRulesPrice_ProductBased')) {
|
7 |
+
class WooDiscountRulesPrice_ProductBased
|
8 |
+
{
|
9 |
+
/**
|
10 |
+
* Verify Quantity
|
11 |
+
* */
|
12 |
+
public static function verifyQuantity($quantity_rule, $quantity, $quantity_from, $quantity_to, $buy_type){
|
13 |
+
$quantityMatched = array();
|
14 |
+
switch ($quantity_rule) {
|
15 |
+
case 'less':
|
16 |
+
foreach($quantity as $quantityValue){
|
17 |
+
$quantityMatched[] = ($quantityValue <= $quantity_from) ? 1: 0;
|
18 |
+
}
|
19 |
+
break;
|
20 |
+
case 'equal':
|
21 |
+
foreach($quantity as $quantityValue){
|
22 |
+
$quantityMatched[] = ($quantityValue == $quantity_from) ? 1: 0;
|
23 |
+
}
|
24 |
+
break;
|
25 |
+
case 'from':
|
26 |
+
foreach($quantity as $quantityValue){
|
27 |
+
$quantityMatched[] = (($quantityValue >= $quantity_from) && ($quantityValue <= $quantity_to)) ? 1: 0;
|
28 |
+
}
|
29 |
+
break;
|
30 |
+
case 'more':
|
31 |
+
default:
|
32 |
+
foreach($quantity as $quantityValue){
|
33 |
+
$quantityMatched[] = ($quantityValue >= $quantity_from) ? 1: 0;
|
34 |
+
}
|
35 |
+
break;
|
36 |
+
}
|
37 |
+
|
38 |
+
return WooDiscountRulesPrice_ProductBased::verifyBuyTypeWithQuantityMatched($buy_type, $quantityMatched);
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Verify Buy type with Quantity matched
|
43 |
+
* */
|
44 |
+
public static function verifyBuyTypeWithQuantityMatched($buy_type, $quantityMatched){
|
45 |
+
$result = 0;
|
46 |
+
if(!empty($quantityMatched)){
|
47 |
+
switch ($buy_type) {
|
48 |
+
case 'combine':
|
49 |
+
case 'any':
|
50 |
+
if(in_array(1, $quantityMatched)){
|
51 |
+
$result = 1;
|
52 |
+
}
|
53 |
+
break;
|
54 |
+
case 'each':
|
55 |
+
default:
|
56 |
+
$result = (in_array(0, $quantityMatched)) ? 0 : 1;
|
57 |
+
break;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
return $result;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Adjust Quantity
|
66 |
+
* */
|
67 |
+
public static function adjustQuantity($buy_type, $quantity_by_products){
|
68 |
+
switch ($buy_type) {
|
69 |
+
case 'combine':
|
70 |
+
$quantityCount = 0;
|
71 |
+
foreach($quantity_by_products as $quantity_by_product){
|
72 |
+
$quantityCount += $quantity_by_product;
|
73 |
+
}
|
74 |
+
$quantity = array($quantityCount);
|
75 |
+
break;
|
76 |
+
case 'any':
|
77 |
+
case 'each':
|
78 |
+
default:
|
79 |
+
$quantity = $quantity_by_products;
|
80 |
+
break;
|
81 |
+
}
|
82 |
+
return $quantity;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
}
|
includes/pricing-rules-3.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
include_once(WOO_DISCOUNT_DIR . '/helper/general-helper-3.php');
|
|
|
4 |
|
5 |
/**
|
6 |
* Class woo_dicount_rules_pricingRules
|
@@ -135,6 +136,8 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
135 |
'status',
|
136 |
'customer',
|
137 |
'discount_range',
|
|
|
|
|
138 |
'rule_order'
|
139 |
);
|
140 |
|
@@ -207,6 +210,13 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
207 |
// Reset the Discount Range, if its empty.
|
208 |
$request['discount_range'] = '';
|
209 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|
211 |
$request['status'] = 'publish';
|
212 |
|
@@ -459,7 +469,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
459 |
$found = false;
|
460 |
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
461 |
$_product = $values['data'];
|
462 |
-
if ($_product->
|
463 |
$freeProductRule[0]['amount'] = array('price_discount' => $_product->get_price());
|
464 |
$freeProductRule[0]['name'] = $free_product_detail['rule_name'];
|
465 |
$freeProductRule[0]['item'] = $cart_item_key;
|
@@ -503,68 +513,74 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
503 |
$rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
|
504 |
$rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
|
505 |
$rule_sets[$index]['allow']['purchase_history'] = 'yes';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
|
|
|
|
517 |
} else {
|
518 |
-
$rule_sets[$index]['type']
|
519 |
}
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
if($
|
524 |
-
$
|
525 |
-
$rule_sets[$index]['type']['specific_category'] = $this->getAllSubCategories($cat);
|
526 |
}
|
527 |
}
|
528 |
-
if (isset($rule->is_cumulative) && $rule->is_cumulative) {
|
529 |
-
$rule_sets[$index]['type']['is_cumulative'] = 1;
|
530 |
-
} else {
|
531 |
-
$rule_sets[$index]['type']['is_cumulative'] = 0;
|
532 |
-
}
|
533 |
-
} else {
|
534 |
-
$rule_sets[$index]['type'] = 'all';
|
535 |
-
}
|
536 |
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
|
|
541 |
}
|
542 |
-
|
543 |
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
if ($rule->customer == 'only_given') {
|
548 |
-
if (isset($rule->users_to_apply)) {
|
549 |
-
$rule_sets[$index]['allow']['users'] = $this->checkWithUsers($rule, $woocommerce);
|
550 |
}
|
551 |
}
|
552 |
-
$rule_sets[$index]['apply_to'] = $rule->apply_to;
|
553 |
|
554 |
-
//
|
555 |
-
if(
|
556 |
-
$rule_sets[$index]
|
557 |
}
|
558 |
-
}
|
559 |
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
unset($rule_sets[$index]);
|
568 |
}
|
569 |
}
|
570 |
$this->rule_sets = $rule_sets;
|
@@ -638,55 +654,129 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
638 |
$applied_rules = array();
|
639 |
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
640 |
$i = 0;
|
|
|
|
|
|
|
|
|
641 |
|
642 |
-
|
|
|
643 |
|
644 |
-
|
645 |
|
646 |
-
|
647 |
-
|
|
|
|
|
|
|
|
|
648 |
|
649 |
-
|
650 |
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
|
|
|
|
|
|
|
|
|
|
657 |
|
658 |
-
break;
|
659 |
|
660 |
-
|
661 |
-
if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
|
662 |
-
if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
|
663 |
-
$totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
|
664 |
-
$quantity = $totalQuantityInThisCategory;
|
665 |
-
}
|
666 |
-
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
667 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
668 |
-
$applied_rules[$i]['item'] = $index;
|
669 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
670 |
-
}
|
671 |
|
|
|
|
|
672 |
|
673 |
-
|
|
|
|
|
|
|
674 |
|
675 |
-
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
|
|
|
|
|
|
|
|
682 |
|
683 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
684 |
}
|
685 |
}
|
686 |
-
$i++;
|
687 |
}
|
688 |
-
|
689 |
-
$this->matched_sets[$index] = $applied_rules;
|
690 |
}
|
691 |
|
692 |
/**
|
@@ -1018,64 +1108,145 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1018 |
if(is_array($this->rules) && count($this->rules) > 0) {
|
1019 |
foreach ($this->rules as $index => $rule) {
|
1020 |
$status = false;
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
$status = true;
|
1027 |
-
} else {
|
1028 |
-
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
1029 |
-
$user_id = get_current_user_id();
|
1030 |
-
if (count(array_intersect($users, array($user_id))) > 0) {
|
1031 |
$status = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
1032 |
}
|
1033 |
}
|
1034 |
-
}
|
1035 |
|
1036 |
-
|
1037 |
|
1038 |
-
|
1039 |
-
|
1040 |
|
1041 |
-
|
1042 |
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
|
|
1047 |
}
|
1048 |
-
}
|
1049 |
-
} elseif ($rule->apply_to == 'specific_category') {
|
1050 |
|
1051 |
-
|
1052 |
-
|
1053 |
|
1054 |
-
|
1055 |
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
|
|
1065 |
}
|
|
|
|
|
|
|
1066 |
}
|
1067 |
|
1068 |
-
|
1069 |
-
$status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1070 |
}
|
1071 |
|
|
|
|
|
1072 |
|
1073 |
-
|
1074 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1075 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1076 |
}
|
|
|
1077 |
}
|
1078 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1079 |
}
|
1080 |
|
1081 |
/**
|
@@ -1125,38 +1296,49 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1125 |
foreach ($table as $index => $item) {
|
1126 |
if ($item) {
|
1127 |
foreach ($item as $id => $value) {
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
$product_discount = isset($value->discount_product) ? $value->discount_product : array();
|
1136 |
-
$html .= '<tr>';
|
1137 |
-
if (isset($base_config['show_discount_title_table'])) {
|
1138 |
-
if ($base_config['show_discount_title_table'] == 'show') {
|
1139 |
-
$html .= '<td>'.$title.'</td>';
|
1140 |
}
|
1141 |
-
}
|
1142 |
-
|
1143 |
-
|
1144 |
-
$
|
1145 |
-
if(
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1151 |
}
|
1152 |
-
|
|
|
|
|
|
|
1153 |
}
|
1154 |
-
|
1155 |
-
}
|
1156 |
-
|
1157 |
-
|
1158 |
-
$html .= '<td>'.
|
1159 |
}
|
|
|
|
|
1160 |
$html .= '</tr>';
|
1161 |
}
|
1162 |
$have_discount = true;
|
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
|
136 |
'status',
|
137 |
'customer',
|
138 |
'discount_range',
|
139 |
+
'product_based_condition',
|
140 |
+
'product_based_discount',
|
141 |
'rule_order'
|
142 |
);
|
143 |
|
210 |
// Reset the Discount Range, if its empty.
|
211 |
$request['discount_range'] = '';
|
212 |
}
|
213 |
+
if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
|
214 |
+
$request['product_based_condition'] = json_encode($request['product_based_condition']);
|
215 |
+
$request['product_based_discount'] = json_encode($request['product_based_discount']);
|
216 |
+
} else {
|
217 |
+
$request['product_based_condition'] = '{}';
|
218 |
+
$request['product_based_discount'] = '{}';
|
219 |
+
}
|
220 |
|
221 |
$request['status'] = 'publish';
|
222 |
|
469 |
$found = false;
|
470 |
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
471 |
$_product = $values['data'];
|
472 |
+
if ($_product->get_id() == $productId){
|
473 |
$freeProductRule[0]['amount'] = array('price_discount' => $_product->get_price());
|
474 |
$freeProductRule[0]['name'] = $free_product_detail['rule_name'];
|
475 |
$freeProductRule[0]['item'] = $cart_item_key;
|
513 |
$rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
|
514 |
$rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
|
515 |
$rule_sets[$index]['allow']['purchase_history'] = 'yes';
|
516 |
+
// Default setup for all customers.
|
517 |
+
$rule_sets[$index]['allow']['users'] = 'all';
|
518 |
+
|
519 |
+
// For quantity based discount
|
520 |
+
if($rule_sets[$index]['method'] == 'qty_based'){
|
521 |
+
// List the type of apply, by Product or by Category.
|
522 |
+
if (isset($rule->apply_to)) {
|
523 |
+
// If Rule is processed by Specific Products, then..
|
524 |
+
if ($rule->apply_to == 'specific_products') {
|
525 |
+
if (isset($rule->product_to_apply)) {
|
526 |
+
$rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
|
527 |
+
}
|
528 |
+
} else if ($rule->apply_to == 'specific_category') {
|
529 |
+
if (isset($rule->apply_child_categories) && $rule->apply_child_categories) {
|
530 |
+
$rule_sets[$index]['type']['apply_child_categories'] = 1;
|
531 |
+
} else {
|
532 |
+
$rule_sets[$index]['type']['apply_child_categories'] = 0;
|
533 |
+
}
|
534 |
|
535 |
+
if (isset($rule->category_to_apply)) {
|
536 |
+
$rule_sets[$index]['type']['specific_category'] = $this->checkWithCategory($rule, $woocommerce);
|
537 |
+
if($rule_sets[$index]['type']['apply_child_categories']){
|
538 |
+
$cat = $rule_sets[$index]['type']['specific_category'];
|
539 |
+
$rule_sets[$index]['type']['specific_category'] = $this->getAllSubCategories($cat);
|
540 |
+
}
|
541 |
+
}
|
542 |
+
if (isset($rule->is_cumulative) && $rule->is_cumulative) {
|
543 |
+
$rule_sets[$index]['type']['is_cumulative'] = 1;
|
544 |
+
} else {
|
545 |
+
$rule_sets[$index]['type']['is_cumulative'] = 0;
|
546 |
+
}
|
547 |
} else {
|
548 |
+
$rule_sets[$index]['type'] = 'all';
|
549 |
}
|
550 |
|
551 |
+
$rule_sets[$index]['discount'] = 0;
|
552 |
+
if (isset($rule->discount_range)) {
|
553 |
+
if ($rule->discount_range != '') {
|
554 |
+
$rule_sets[$index]['discount'] = $this->getDiscountRangeList($rule);
|
|
|
555 |
}
|
556 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
|
558 |
+
// If Rule is processed by Specific Customers, then..
|
559 |
+
if ($rule->customer == 'only_given') {
|
560 |
+
if (isset($rule->users_to_apply)) {
|
561 |
+
$rule_sets[$index]['allow']['users'] = $this->checkWithUsers($rule, $woocommerce);
|
562 |
+
}
|
563 |
}
|
564 |
+
$rule_sets[$index]['apply_to'] = $rule->apply_to;
|
565 |
|
566 |
+
// Default setup for purchase history
|
567 |
+
if(isset($rule->based_on_purchase_history) && $rule->based_on_purchase_history){
|
568 |
+
$rule_sets[$index]['allow']['purchase_history'] = $this->checkWithUsersPurchaseHistory($rule, $woocommerce);
|
|
|
|
|
|
|
569 |
}
|
570 |
}
|
|
|
571 |
|
572 |
+
// If Current Customer is not Allowed to use this discount, then it's going to be removed.
|
573 |
+
if ($rule_sets[$index]['allow']['users'] == 'no') {
|
574 |
+
unset($rule_sets[$index]);
|
575 |
}
|
|
|
576 |
|
577 |
+
// If Current Customer is not Allowed based on purchase history to use this discount, then it's going to be removed.
|
578 |
+
if ($rule_sets[$index]['allow']['purchase_history'] == 'no') {
|
579 |
+
unset($rule_sets[$index]);
|
580 |
+
}
|
581 |
+
} else if($rule_sets[$index]['method'] == 'product_based'){
|
582 |
+
$rule_sets[$index]['product_based_condition'] = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
583 |
+
$rule_sets[$index]['product_based_discount'] = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
|
|
|
584 |
}
|
585 |
}
|
586 |
$this->rule_sets = $rule_sets;
|
654 |
$applied_rules = array();
|
655 |
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
656 |
$i = 0;
|
657 |
+
if(!empty($this->rule_sets))
|
658 |
+
foreach ($this->rule_sets as $id => $rule) {
|
659 |
+
if(isset($rule['method']) && $rule['method'] == 'qty_based'){
|
660 |
+
if (isset($rule['type']) && isset($rule['apply_to'])) {
|
661 |
|
662 |
+
// Working with Products and Category.
|
663 |
+
switch ($rule['apply_to']) {
|
664 |
|
665 |
+
case 'specific_products':
|
666 |
|
667 |
+
if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
|
668 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
669 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
670 |
+
$applied_rules[$i]['item'] = $index;
|
671 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
672 |
+
}
|
673 |
|
674 |
+
break;
|
675 |
|
676 |
+
case 'specific_category':
|
677 |
+
if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
|
678 |
+
if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
|
679 |
+
$totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
|
680 |
+
$quantity = $totalQuantityInThisCategory;
|
681 |
+
}
|
682 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
683 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
684 |
+
$applied_rules[$i]['item'] = $index;
|
685 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
686 |
+
}
|
687 |
|
|
|
688 |
|
689 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
|
691 |
+
case 'all_products':
|
692 |
+
default:
|
693 |
|
694 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
695 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
696 |
+
$applied_rules[$i]['item'] = $index;
|
697 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
698 |
|
699 |
+
break;
|
700 |
+
}
|
701 |
+
}
|
702 |
+
} else if(isset($rule['method']) && $rule['method'] == 'product_based'){
|
703 |
+
$checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
|
704 |
+
if(!empty($checkRuleMatches)){
|
705 |
+
foreach ($checkRuleMatches['apply_to']['products'] as $key => $productId) {
|
706 |
+
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
707 |
+
$_product = $values['data'];
|
708 |
+
if ($_product->get_id() == $productId){
|
709 |
+
$applied_rules_new = array();
|
710 |
+
$applied_rules_new['amount'] = $checkRuleMatches['amount'];
|
711 |
+
$applied_rules_new['name'] = $rule['name'];
|
712 |
+
$applied_rules_new['item'] = $cart_item_key;
|
713 |
+
$applied_rules_new['id'] = $productId;
|
714 |
+
$applied_rules_new['rule_order'] = $id;
|
715 |
+
$applied_rules_new['apply_from'] = $item['product_id'];
|
716 |
+
$alreadyExists = 0;
|
717 |
+
if(!empty($this->matched_sets[$cart_item_key])){
|
718 |
+
foreach($this->matched_sets[$cart_item_key] as $machedRules){
|
719 |
+
if($machedRules['rule_order'] == $id){
|
720 |
+
$alreadyExists = 1;
|
721 |
+
break;
|
722 |
+
}
|
723 |
+
}
|
724 |
+
}
|
725 |
+
if(!$alreadyExists) $this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
726 |
+
}
|
727 |
+
}
|
728 |
+
}
|
729 |
+
}
|
730 |
+
}
|
731 |
|
732 |
+
$i++;
|
733 |
+
}
|
734 |
+
if(isset($this->matched_sets[$index]) && !empty($this->matched_sets[$index])){
|
735 |
+
$this->matched_sets[$index] = array_merge($this->matched_sets[$index], $applied_rules);
|
736 |
+
} else {
|
737 |
+
$this->matched_sets[$index] = $applied_rules;
|
738 |
+
}
|
739 |
+
}
|
740 |
|
741 |
+
/**
|
742 |
+
* Check Product based rules matches
|
743 |
+
* */
|
744 |
+
public function checkProductBasedRuleMatches($rule, $item, $quantity){
|
745 |
+
$result = array();
|
746 |
+
if(isset($rule['product_based_condition']) && !empty($rule['product_based_condition'])){
|
747 |
+
$product_based_conditions = $rule['product_based_condition'];
|
748 |
+
$buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
749 |
+
$quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
750 |
+
$quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
751 |
+
$quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
752 |
+
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
753 |
+
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
754 |
+
|
755 |
+
$product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
|
756 |
+
$discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
757 |
+
$discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
758 |
+
|
759 |
+
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
|
760 |
+
$_quantity = array();
|
761 |
+
foreach ($product_to_buy as $key => $productId) {
|
762 |
+
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
763 |
+
$_product = $values['data'];
|
764 |
+
if ($_product->get_id() == $productId){
|
765 |
+
$_quantity[$productId] = $values['quantity'];
|
766 |
+
}
|
767 |
+
}
|
768 |
+
}
|
769 |
+
}
|
770 |
+
$quantity = WooDiscountRulesPrice_ProductBased::adjustQuantity($buy_type, $_quantity);
|
771 |
+
if(in_array($item['product_id'], $product_to_buy)){
|
772 |
+
$quantityMatched = WooDiscountRulesPrice_ProductBased::verifyQuantity($quantity_rule, $quantity, $quantity_from, $quantity_to, $buy_type);
|
773 |
+
if($quantityMatched){
|
774 |
+
$result['amount'][$discount_type] = $discount_value;
|
775 |
+
$result['apply_to']['products'] = $product_to_apply;
|
776 |
}
|
777 |
}
|
|
|
778 |
}
|
779 |
+
return $result;
|
|
|
780 |
}
|
781 |
|
782 |
/**
|
1108 |
if(is_array($this->rules) && count($this->rules) > 0) {
|
1109 |
foreach ($this->rules as $index => $rule) {
|
1110 |
$status = false;
|
1111 |
+
if(isset($rule->rule_method) && $rule->rule_method == 'qty_based'){
|
1112 |
+
// Check with Active User Filter.
|
1113 |
+
if (isset($rule->customer)) {
|
1114 |
+
$status = false;
|
1115 |
+
if ($rule->customer == 'all') {
|
|
|
|
|
|
|
|
|
|
|
1116 |
$status = true;
|
1117 |
+
} else {
|
1118 |
+
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
1119 |
+
$user_id = get_current_user_id();
|
1120 |
+
if (count(array_intersect($users, array($user_id))) > 0) {
|
1121 |
+
$status = true;
|
1122 |
+
}
|
1123 |
}
|
1124 |
}
|
|
|
1125 |
|
1126 |
+
if ($rule->apply_to == 'specific_products') {
|
1127 |
|
1128 |
+
// Check with Product Filter.
|
1129 |
+
$products_to_apply = json_decode($rule->product_to_apply);
|
1130 |
|
1131 |
+
if ($rule->product_to_apply == null) $status = true;
|
1132 |
|
1133 |
+
if ($rule->product_to_apply != null) {
|
1134 |
+
$status = false;
|
1135 |
+
if (in_array($id, $products_to_apply)) {
|
1136 |
+
$status = true;
|
1137 |
+
}
|
1138 |
}
|
1139 |
+
} elseif ($rule->apply_to == 'specific_category') {
|
|
|
1140 |
|
1141 |
+
// Check with Product Category Filter.
|
1142 |
+
$category = woo_dicount_rules_generalHelper::getCategoryByPost($id, true);
|
1143 |
|
1144 |
+
if ($rule->category_to_apply == null) $status = true;
|
1145 |
|
1146 |
+
if ($rule->category_to_apply != null) {
|
1147 |
+
$category_to_apply = json_decode($rule->category_to_apply);
|
1148 |
+
if (isset($rule->apply_child_categories) && $rule->apply_child_categories == 1) {
|
1149 |
+
$category_to_apply = $this->getAllSubCategories($category_to_apply);
|
1150 |
+
}
|
1151 |
+
woo_dicount_rules_generalHelper::toInt($category_to_apply);
|
1152 |
+
$status = false;
|
1153 |
+
if (count(array_intersect($category_to_apply, $category)) > 0) {
|
1154 |
+
$status = true;
|
1155 |
+
}
|
1156 |
}
|
1157 |
+
|
1158 |
+
} else if ($rule->apply_to == 'all_products') {
|
1159 |
+
$status = true;
|
1160 |
}
|
1161 |
|
1162 |
+
|
1163 |
+
if ($status) {
|
1164 |
+
$discount_range[] = (isset($rule->discount_range) ? json_decode($rule->discount_range) : array());
|
1165 |
+
}
|
1166 |
+
} else if(isset($rule->rule_method) && $rule->rule_method == 'product_based'){
|
1167 |
+
$product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
1168 |
+
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
1169 |
+
if (in_array($id, $product_to_buy)) {
|
1170 |
+
$product_based_discounts = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
|
1171 |
+
$product_based_discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
1172 |
+
$product_based_discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
1173 |
+
$newTableContent = new stdClass();
|
1174 |
+
$newTableContent->rule_method = $rule->rule_method;
|
1175 |
+
$newTableContent->discount_type = $product_based_discount_type;
|
1176 |
+
$newTableContent->to_discount = $product_based_discount_value;
|
1177 |
+
$newTableContent->title = $rule->rule_name;
|
1178 |
+
$condition = $this->getTextForProductDiscountCondition($rule);
|
1179 |
+
$newTableContent->condition = $condition;
|
1180 |
+
$discount_range[][] = $newTableContent;
|
1181 |
+
}
|
1182 |
}
|
1183 |
|
1184 |
+
}
|
1185 |
+
}
|
1186 |
|
1187 |
+
return $discount_range;
|
1188 |
+
}
|
1189 |
+
|
1190 |
+
public function getTextForProductDiscountCondition($rule){
|
1191 |
+
$product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
1192 |
+
$product_buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
1193 |
+
$product_quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
1194 |
+
$product_quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
1195 |
+
$product_quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
1196 |
+
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
1197 |
+
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
1198 |
+
$condition = esc_html__('Buy', 'woo-discount-rules');
|
1199 |
+
|
1200 |
+
switch ($product_quantity_rule) {
|
1201 |
+
case 'less':
|
1202 |
+
$quantity_text = esc_html__(' less than or equal to ', 'woo-discount-rules').$product_quantity_from.esc_html__(' Quantity', 'woo-discount-rules');
|
1203 |
+
break;
|
1204 |
+
case 'equal':
|
1205 |
+
$quantity_text = ' '.$product_quantity_from.esc_html__(' Quantity ', 'woo-discount-rules');
|
1206 |
+
break;
|
1207 |
+
case 'from':
|
1208 |
+
$quantity_text = '( '.$product_quantity_from.' - '.$product_quantity_to.' )'.esc_html__(' Quantity', 'woo-discount-rules');
|
1209 |
+
break;
|
1210 |
+
case 'more':
|
1211 |
+
default:
|
1212 |
+
$quantity_text = ' '.$product_quantity_from.esc_html__(' or more Quantity', 'woo-discount-rules');
|
1213 |
+
}
|
1214 |
+
|
1215 |
+
switch ($product_buy_type) {
|
1216 |
+
case 'combine':
|
1217 |
+
case 'any':
|
1218 |
+
if(count($product_to_buy) == 1){
|
1219 |
+
$condition .= $quantity_text;
|
1220 |
+
} else {
|
1221 |
+
$condition .= esc_html__(' any ', 'woo-discount-rules').$quantity_text.esc_html__(' products from ','woo-discount-rules');
|
1222 |
}
|
1223 |
+
break;
|
1224 |
+
case 'each':
|
1225 |
+
if(count($product_to_buy) == 1){
|
1226 |
+
$condition .= $quantity_text;
|
1227 |
+
} else {
|
1228 |
+
$condition .= ' '.$quantity_text.esc_html__(' in each products', 'woo-discount-rules');
|
1229 |
+
}
|
1230 |
+
break;
|
1231 |
+
}
|
1232 |
+
if(count($product_to_buy) > 1){
|
1233 |
+
$htmlProduct = '';
|
1234 |
+
foreach ($product_to_buy as $product_id){
|
1235 |
+
$product = wc_get_product( $product_id );
|
1236 |
+
$htmlProduct .= $product->get_title().',';
|
1237 |
}
|
1238 |
+
$condition .= trim($htmlProduct, ',');
|
1239 |
}
|
1240 |
+
$condition .= esc_html__(' and get discount in ', 'woo-discount-rules');
|
1241 |
+
if(count($product_to_apply)){
|
1242 |
+
$htmlProduct = '';
|
1243 |
+
foreach ($product_to_apply as $product_id){
|
1244 |
+
$product = wc_get_product( $product_id );
|
1245 |
+
$htmlProduct .= '<a href="'.$product->get_permalink().'">'.$product->get_title().'</a>, ';
|
1246 |
+
}
|
1247 |
+
$condition .= trim($htmlProduct, ', ');
|
1248 |
+
}
|
1249 |
+
return $condition;
|
1250 |
}
|
1251 |
|
1252 |
/**
|
1296 |
foreach ($table as $index => $item) {
|
1297 |
if ($item) {
|
1298 |
foreach ($item as $id => $value) {
|
1299 |
+
if(isset($value->rule_method) && $value->rule_method == 'product_based'){
|
1300 |
+
$title = $value->title;
|
1301 |
+
$condition = $value->condition;
|
1302 |
+
if ($value->discount_type == 'percentage_discount') {
|
1303 |
+
$discount = $value->to_discount.' %';
|
1304 |
+
} else {
|
1305 |
+
$discount = wc_price($value->to_discount);
|
|
|
|
|
|
|
|
|
|
|
1306 |
}
|
1307 |
+
} else {
|
1308 |
+
$title = isset($value->title) ? $value->title : '';
|
1309 |
+
$min = isset($value->min_qty) ? $value->min_qty : 0;
|
1310 |
+
$max = isset($value->max_qty) ? $value->max_qty : 0;
|
1311 |
+
if($max == 0 || $max == '' || $max == false) $max = 999;
|
1312 |
+
$discount_type = isset($value->discount_type) ? $value->discount_type : 0;
|
1313 |
+
$to_discount = isset($value->to_discount) ? $value->to_discount : 0;
|
1314 |
+
$product_discount = isset($value->discount_product) ? $value->discount_product : array();
|
1315 |
+
if (isset($base_config['show_discount_title_table'])) {
|
1316 |
+
}
|
1317 |
+
$condition = $min .' - ' . $max;
|
1318 |
+
if ($discount_type == 'product_discount') {
|
1319 |
+
$discount = '';
|
1320 |
+
if(count($product_discount)){
|
1321 |
+
$htmlProduct = '';
|
1322 |
+
foreach ($product_discount as $product_id){
|
1323 |
+
$product = wc_get_product( $product_id );
|
1324 |
+
$htmlProduct .= $product->get_title();
|
1325 |
+
$htmlProduct .= ' ('.$product->get_price_html().')<br>';
|
1326 |
+
}
|
1327 |
+
$discount = trim($htmlProduct, '<br>');
|
1328 |
}
|
1329 |
+
} else if ($discount_type == 'percentage_discount') {
|
1330 |
+
$discount = $to_discount.' %';
|
1331 |
+
} else {
|
1332 |
+
$discount = wc_price($to_discount);
|
1333 |
}
|
1334 |
+
|
1335 |
+
}
|
1336 |
+
$html .= '<tr>';
|
1337 |
+
if ($base_config['show_discount_title_table'] == 'show') {
|
1338 |
+
$html .= '<td>'.$title.'</td>';
|
1339 |
}
|
1340 |
+
$html .= '<td>'.$condition.'</td>';
|
1341 |
+
$html .= '<td>'.$discount.'</td>';
|
1342 |
$html .= '</tr>';
|
1343 |
}
|
1344 |
$have_discount = true;
|
includes/pricing-rules.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
include_once(WOO_DISCOUNT_DIR . '/helper/general-helper.php');
|
|
|
4 |
|
5 |
/**
|
6 |
* Class woo_dicount_rules_pricingRules
|
@@ -135,6 +136,8 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
135 |
'status',
|
136 |
'customer',
|
137 |
'discount_range',
|
|
|
|
|
138 |
'rule_order'
|
139 |
);
|
140 |
|
@@ -208,6 +211,14 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
208 |
$request['discount_range'] = '';
|
209 |
}
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
$request['status'] = 'publish';
|
212 |
|
213 |
if (is_null($id) || !isset($id)) return false;
|
@@ -503,68 +514,76 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
503 |
$rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
|
504 |
$rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
|
505 |
$rule_sets[$index]['allow']['purchase_history'] = 'yes';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
|
|
|
|
517 |
} else {
|
518 |
-
$rule_sets[$index]['type']
|
519 |
}
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
if($
|
524 |
-
$
|
525 |
-
$rule_sets[$index]['type']['specific_category'] = $this->getAllSubCategories($cat);
|
526 |
}
|
527 |
}
|
528 |
-
if (isset($rule->is_cumulative) && $rule->is_cumulative) {
|
529 |
-
$rule_sets[$index]['type']['is_cumulative'] = 1;
|
530 |
-
} else {
|
531 |
-
$rule_sets[$index]['type']['is_cumulative'] = 0;
|
532 |
-
}
|
533 |
-
} else {
|
534 |
-
$rule_sets[$index]['type'] = 'all';
|
535 |
-
}
|
536 |
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
|
|
|
|
|
|
541 |
}
|
542 |
-
|
543 |
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
if ($rule->customer == 'only_given') {
|
548 |
-
if (isset($rule->users_to_apply)) {
|
549 |
-
$rule_sets[$index]['allow']['users'] = $this->checkWithUsers($rule, $woocommerce);
|
550 |
}
|
551 |
}
|
552 |
-
$rule_sets[$index]['apply_to'] = $rule->apply_to;
|
553 |
|
554 |
-
//
|
555 |
-
if(
|
556 |
-
$rule_sets[$index]
|
557 |
}
|
558 |
-
}
|
559 |
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
unset($rule_sets[$index]);
|
568 |
}
|
569 |
}
|
570 |
$this->rule_sets = $rule_sets;
|
@@ -638,53 +657,129 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
638 |
$applied_rules = array();
|
639 |
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
640 |
$i = 0;
|
641 |
-
|
|
|
|
|
|
|
642 |
|
643 |
-
|
|
|
644 |
|
645 |
-
|
646 |
-
switch ($rule['apply_to']) {
|
647 |
|
648 |
-
|
|
|
|
|
|
|
|
|
|
|
649 |
|
650 |
-
|
651 |
-
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
652 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
653 |
-
$applied_rules[$i]['item'] = $index;
|
654 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
655 |
-
}
|
656 |
|
657 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
658 |
|
659 |
-
case 'specific_category':
|
660 |
-
if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
|
661 |
-
if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
|
662 |
-
$totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
|
663 |
-
$quantity = $totalQuantityInThisCategory;
|
664 |
-
}
|
665 |
-
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
666 |
-
$applied_rules[$i]['name'] = $rule['name'];
|
667 |
-
$applied_rules[$i]['item'] = $index;
|
668 |
-
$applied_rules[$i]['id'] = $item['product_id'];
|
669 |
-
}
|
670 |
|
|
|
671 |
|
672 |
-
|
|
|
673 |
|
674 |
-
|
675 |
-
|
|
|
|
|
676 |
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
681 |
|
682 |
-
|
|
|
|
|
|
|
|
|
|
|
683 |
}
|
684 |
}
|
685 |
-
$i++;
|
686 |
}
|
687 |
-
|
688 |
}
|
689 |
|
690 |
/**
|
@@ -1016,64 +1111,142 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1016 |
if(is_array($this->rules) && count($this->rules) > 0){
|
1017 |
foreach ($this->rules as $index => $rule) {
|
1018 |
$status = false;
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
$status = true;
|
1025 |
-
} else {
|
1026 |
-
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
1027 |
-
$user_id = get_current_user_id();
|
1028 |
-
if (count(array_intersect($users, array($user_id))) > 0) {
|
1029 |
$status = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
1030 |
}
|
1031 |
}
|
1032 |
-
}
|
1033 |
|
1034 |
-
|
1035 |
|
1036 |
-
|
1037 |
-
|
1038 |
|
1039 |
-
|
1040 |
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
|
|
1045 |
}
|
1046 |
-
}
|
1047 |
-
} elseif ($rule->apply_to == 'specific_category') {
|
1048 |
|
1049 |
-
|
1050 |
-
|
1051 |
|
1052 |
-
|
1053 |
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
|
|
1063 |
}
|
|
|
|
|
|
|
1064 |
}
|
1065 |
|
1066 |
-
|
1067 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1068 |
}
|
|
|
|
|
|
|
|
|
1069 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1070 |
|
1071 |
-
|
1072 |
-
|
|
|
|
|
|
|
|
|
|
|
1073 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1074 |
}
|
|
|
1075 |
}
|
1076 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1077 |
}
|
1078 |
|
1079 |
/**
|
@@ -1123,36 +1296,49 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
|
|
1123 |
foreach ($table as $index => $item) {
|
1124 |
if ($item) {
|
1125 |
foreach ($item as $id => $value) {
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
$product_discount = isset($value->discount_product) ? $value->discount_product : array();
|
1134 |
-
$html .= '<tr>';
|
1135 |
-
if (isset($base_config['show_discount_title_table'])) {
|
1136 |
-
if ($base_config['show_discount_title_table'] == 'show') {
|
1137 |
-
$html .= '<td>'.$title.'</td>';
|
1138 |
}
|
1139 |
-
}
|
1140 |
-
|
1141 |
-
|
1142 |
-
$
|
1143 |
-
if(
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1148 |
}
|
|
|
|
|
|
|
|
|
1149 |
}
|
1150 |
-
|
1151 |
-
}
|
1152 |
-
|
1153 |
-
|
1154 |
-
$html .= '<td>'.
|
1155 |
}
|
|
|
|
|
1156 |
$html .= '</tr>';
|
1157 |
}
|
1158 |
$have_discount = true;
|
1 |
<?php
|
2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
3 |
include_once(WOO_DISCOUNT_DIR . '/helper/general-helper.php');
|
4 |
+
include_once(WOO_DISCOUNT_DIR . '/includes/pricing-productbased.php');
|
5 |
|
6 |
/**
|
7 |
* Class woo_dicount_rules_pricingRules
|
136 |
'status',
|
137 |
'customer',
|
138 |
'discount_range',
|
139 |
+
'product_based_condition',
|
140 |
+
'product_based_discount',
|
141 |
'rule_order'
|
142 |
);
|
143 |
|
211 |
$request['discount_range'] = '';
|
212 |
}
|
213 |
|
214 |
+
if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
|
215 |
+
$request['product_based_condition'] = json_encode($request['product_based_condition']);
|
216 |
+
$request['product_based_discount'] = json_encode($request['product_based_discount']);
|
217 |
+
} else {
|
218 |
+
$request['product_based_condition'] = '{}';
|
219 |
+
$request['product_based_discount'] = '{}';
|
220 |
+
}
|
221 |
+
|
222 |
$request['status'] = 'publish';
|
223 |
|
224 |
if (is_null($id) || !isset($id)) return false;
|
514 |
$rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
|
515 |
$rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
|
516 |
$rule_sets[$index]['allow']['purchase_history'] = 'yes';
|
517 |
+
// Default setup for all customers.
|
518 |
+
$rule_sets[$index]['allow']['users'] = 'all';
|
519 |
+
|
520 |
+
// For quantity based discount
|
521 |
+
if($rule_sets[$index]['method'] == 'qty_based'){
|
522 |
+
// List the type of apply, by Product or by Category.
|
523 |
+
if (isset($rule->apply_to)) {
|
524 |
+
// If Rule is processed by Specific Products, then..
|
525 |
+
if ($rule->apply_to == 'specific_products') {
|
526 |
+
if (isset($rule->product_to_apply)) {
|
527 |
+
$rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
|
528 |
+
}
|
529 |
+
} else if ($rule->apply_to == 'specific_category') {
|
530 |
+
if (isset($rule->apply_child_categories) && $rule->apply_child_categories) {
|
531 |
+
$rule_sets[$index]['type']['apply_child_categories'] = 1;
|
532 |
+
} else {
|
533 |
+
$rule_sets[$index]['type']['apply_child_categories'] = 0;
|
534 |
+
}
|
535 |
|
536 |
+
if (isset($rule->category_to_apply)) {
|
537 |
+
$rule_sets[$index]['type']['specific_category'] = $this->checkWithCategory($rule, $woocommerce);
|
538 |
+
if($rule_sets[$index]['type']['apply_child_categories']){
|
539 |
+
$cat = $rule_sets[$index]['type']['specific_category'];
|
540 |
+
$rule_sets[$index]['type']['specific_category'] = $this->getAllSubCategories($cat);
|
541 |
+
}
|
542 |
+
}
|
543 |
+
if (isset($rule->is_cumulative) && $rule->is_cumulative) {
|
544 |
+
$rule_sets[$index]['type']['is_cumulative'] = 1;
|
545 |
+
} else {
|
546 |
+
$rule_sets[$index]['type']['is_cumulative'] = 0;
|
547 |
+
}
|
548 |
} else {
|
549 |
+
$rule_sets[$index]['type'] = 'all';
|
550 |
}
|
551 |
|
552 |
+
$rule_sets[$index]['discount'] = 0;
|
553 |
+
if (isset($rule->discount_range)) {
|
554 |
+
if ($rule->discount_range != '') {
|
555 |
+
$rule_sets[$index]['discount'] = $this->getDiscountRangeList($rule);
|
|
|
556 |
}
|
557 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
558 |
|
559 |
+
// Default setup for all customers.
|
560 |
+
$rule_sets[$index]['allow']['users'] = 'all';
|
561 |
+
// If Rule is processed by Specific Customers, then..
|
562 |
+
if ($rule->customer == 'only_given') {
|
563 |
+
if (isset($rule->users_to_apply)) {
|
564 |
+
$rule_sets[$index]['allow']['users'] = $this->checkWithUsers($rule, $woocommerce);
|
565 |
+
}
|
566 |
}
|
567 |
+
$rule_sets[$index]['apply_to'] = $rule->apply_to;
|
568 |
|
569 |
+
// Default setup for purchase history
|
570 |
+
if(isset($rule->based_on_purchase_history) && $rule->based_on_purchase_history){
|
571 |
+
$rule_sets[$index]['allow']['purchase_history'] = $this->checkWithUsersPurchaseHistory($rule, $woocommerce);
|
|
|
|
|
|
|
572 |
}
|
573 |
}
|
|
|
574 |
|
575 |
+
// If Current Customer is not Allowed to use this discount, then it's going to be removed.
|
576 |
+
if ($rule_sets[$index]['allow']['users'] == 'no') {
|
577 |
+
unset($rule_sets[$index]);
|
578 |
}
|
|
|
579 |
|
580 |
+
// If Current Customer is not Allowed based on purchase history to use this discount, then it's going to be removed.
|
581 |
+
if ($rule_sets[$index]['allow']['purchase_history'] == 'no') {
|
582 |
+
unset($rule_sets[$index]);
|
583 |
+
}
|
584 |
+
} else if($rule_sets[$index]['method'] == 'product_based'){
|
585 |
+
$rule_sets[$index]['product_based_condition'] = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
586 |
+
$rule_sets[$index]['product_based_discount'] = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
|
|
|
587 |
}
|
588 |
}
|
589 |
$this->rule_sets = $rule_sets;
|
657 |
$applied_rules = array();
|
658 |
$quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
|
659 |
$i = 0;
|
660 |
+
if(!empty($this->rule_sets))
|
661 |
+
foreach ($this->rule_sets as $id => $rule) {
|
662 |
+
if(isset($rule['method']) && $rule['method'] == 'qty_based'){
|
663 |
+
if (isset($rule['type']) && isset($rule['apply_to'])) {
|
664 |
|
665 |
+
// Working with Products and Category.
|
666 |
+
switch ($rule['apply_to']) {
|
667 |
|
668 |
+
case 'specific_products':
|
|
|
669 |
|
670 |
+
if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
|
671 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
672 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
673 |
+
$applied_rules[$i]['item'] = $index;
|
674 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
675 |
+
}
|
676 |
|
677 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
678 |
|
679 |
+
case 'specific_category':
|
680 |
+
if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
|
681 |
+
if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
|
682 |
+
$totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
|
683 |
+
$quantity = $totalQuantityInThisCategory;
|
684 |
+
}
|
685 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
686 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
687 |
+
$applied_rules[$i]['item'] = $index;
|
688 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
689 |
+
}
|
690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
691 |
|
692 |
+
break;
|
693 |
|
694 |
+
case 'all_products':
|
695 |
+
default:
|
696 |
|
697 |
+
$applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
|
698 |
+
$applied_rules[$i]['name'] = $rule['name'];
|
699 |
+
$applied_rules[$i]['item'] = $index;
|
700 |
+
$applied_rules[$i]['id'] = $item['product_id'];
|
701 |
|
702 |
+
break;
|
703 |
+
}
|
704 |
+
}
|
705 |
+
} else if(isset($rule['method']) && $rule['method'] == 'product_based'){
|
706 |
+
$checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
|
707 |
+
if(!empty($checkRuleMatches)){
|
708 |
+
foreach ($checkRuleMatches['apply_to']['products'] as $key => $productId) {
|
709 |
+
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
710 |
+
$_product = $values['data'];
|
711 |
+
if ($_product->id == $productId){
|
712 |
+
$applied_rules_new = array();
|
713 |
+
$applied_rules_new['amount'] = $checkRuleMatches['amount'];
|
714 |
+
$applied_rules_new['name'] = $rule['name'];
|
715 |
+
$applied_rules_new['item'] = $cart_item_key;
|
716 |
+
$applied_rules_new['id'] = $productId;
|
717 |
+
$applied_rules_new['rule_order'] = $id;
|
718 |
+
$applied_rules_new['apply_from'] = $item['product_id'];
|
719 |
+
$alreadyExists = 0;
|
720 |
+
if(!empty($this->matched_sets[$cart_item_key])){
|
721 |
+
foreach($this->matched_sets[$cart_item_key] as $machedRules){
|
722 |
+
if($machedRules['rule_order'] == $id){
|
723 |
+
$alreadyExists = 1;
|
724 |
+
break;
|
725 |
+
}
|
726 |
+
}
|
727 |
+
}
|
728 |
+
if(!$alreadyExists) $this->matched_sets[$cart_item_key][] = $applied_rules_new;
|
729 |
+
}
|
730 |
+
}
|
731 |
+
}
|
732 |
+
}
|
733 |
+
}
|
734 |
+
$i++;
|
735 |
+
}
|
736 |
+
if(isset($this->matched_sets[$index]) && !empty($this->matched_sets[$index])){
|
737 |
+
$this->matched_sets[$index] = array_merge($this->matched_sets[$index], $applied_rules);
|
738 |
+
} else {
|
739 |
+
$this->matched_sets[$index] = $applied_rules;
|
740 |
+
}
|
741 |
+
}
|
742 |
+
|
743 |
+
/**
|
744 |
+
* Check Product based rules matches
|
745 |
+
* */
|
746 |
+
public function checkProductBasedRuleMatches($rule, $item, $quantity){
|
747 |
+
$result = array();
|
748 |
+
if(isset($rule['product_based_condition']) && !empty($rule['product_based_condition'])){
|
749 |
+
$product_based_conditions = $rule['product_based_condition'];
|
750 |
+
$buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
751 |
+
$quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
752 |
+
$quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
753 |
+
$quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
754 |
+
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
755 |
+
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
756 |
+
|
757 |
+
$product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
|
758 |
+
$discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
759 |
+
$discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
760 |
+
|
761 |
+
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
|
762 |
+
$_quantity = array();
|
763 |
+
foreach ($product_to_buy as $key => $productId) {
|
764 |
+
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
|
765 |
+
$_product = $values['data'];
|
766 |
+
if ($_product->id == $productId){
|
767 |
+
$_quantity[$productId] = $values['quantity'];
|
768 |
+
}
|
769 |
+
}
|
770 |
+
}
|
771 |
+
}
|
772 |
|
773 |
+
$quantity = WooDiscountRulesPrice_ProductBased::adjustQuantity($buy_type, $_quantity);
|
774 |
+
if(in_array($item['product_id'], $product_to_buy)){
|
775 |
+
$quantityMatched = WooDiscountRulesPrice_ProductBased::verifyQuantity($quantity_rule, $quantity, $quantity_from, $quantity_to, $buy_type);
|
776 |
+
if($quantityMatched){
|
777 |
+
$result['amount'][$discount_type] = $discount_value;
|
778 |
+
$result['apply_to']['products'] = $product_to_apply;
|
779 |
}
|
780 |
}
|
|
|
781 |
}
|
782 |
+
return $result;
|
783 |
}
|
784 |
|
785 |
/**
|
1111 |
if(is_array($this->rules) && count($this->rules) > 0){
|
1112 |
foreach ($this->rules as $index => $rule) {
|
1113 |
$status = false;
|
1114 |
+
if(isset($rule->rule_method) && $rule->rule_method == 'qty_based'){
|
1115 |
+
// Check with Active User Filter.
|
1116 |
+
if (isset($rule->customer)) {
|
1117 |
+
$status = false;
|
1118 |
+
if ($rule->customer == 'all') {
|
|
|
|
|
|
|
|
|
|
|
1119 |
$status = true;
|
1120 |
+
} else {
|
1121 |
+
$users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
|
1122 |
+
$user_id = get_current_user_id();
|
1123 |
+
if (count(array_intersect($users, array($user_id))) > 0) {
|
1124 |
+
$status = true;
|
1125 |
+
}
|
1126 |
}
|
1127 |
}
|
|
|
1128 |
|
1129 |
+
if ($rule->apply_to == 'specific_products') {
|
1130 |
|
1131 |
+
// Check with Product Filter.
|
1132 |
+
$products_to_apply = json_decode($rule->product_to_apply);
|
1133 |
|
1134 |
+
if ($rule->product_to_apply == null) $status = true;
|
1135 |
|
1136 |
+
if ($rule->product_to_apply != null) {
|
1137 |
+
$status = false;
|
1138 |
+
if (in_array($id, $products_to_apply)) {
|
1139 |
+
$status = true;
|
1140 |
+
}
|
1141 |
}
|
1142 |
+
} elseif ($rule->apply_to == 'specific_category') {
|
|
|
1143 |
|
1144 |
+
// Check with Product Category Filter.
|
1145 |
+
$category = woo_dicount_rules_generalHelper::getCategoryByPost($id, true);
|
1146 |
|
1147 |
+
if ($rule->category_to_apply == null) $status = true;
|
1148 |
|
1149 |
+
if ($rule->category_to_apply != null) {
|
1150 |
+
$category_to_apply = json_decode($rule->category_to_apply);
|
1151 |
+
if(isset($rule->apply_child_categories) && $rule->apply_child_categories == 1){
|
1152 |
+
$category_to_apply = $this->getAllSubCategories($category_to_apply);
|
1153 |
+
}
|
1154 |
+
woo_dicount_rules_generalHelper::toInt($category_to_apply);
|
1155 |
+
$status = false;
|
1156 |
+
if (count(array_intersect($category_to_apply, $category)) > 0) {
|
1157 |
+
$status = true;
|
1158 |
+
}
|
1159 |
}
|
1160 |
+
|
1161 |
+
} else if ($rule->apply_to == 'all_products') {
|
1162 |
+
$status = true;
|
1163 |
}
|
1164 |
|
1165 |
+
if ($status) {
|
1166 |
+
$discount_range[] = (isset($rule->discount_range) ? json_decode($rule->discount_range) : array());
|
1167 |
+
}
|
1168 |
+
} else if(isset($rule->rule_method) && $rule->rule_method == 'product_based'){
|
1169 |
+
$product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
1170 |
+
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
1171 |
+
if (in_array($id, $product_to_buy)) {
|
1172 |
+
$product_based_discounts = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
|
1173 |
+
$product_based_discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
1174 |
+
$product_based_discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
1175 |
+
$newTableContent = new stdClass();
|
1176 |
+
$newTableContent->rule_method = $rule->rule_method;
|
1177 |
+
$newTableContent->discount_type = $product_based_discount_type;
|
1178 |
+
$newTableContent->to_discount = $product_based_discount_value;
|
1179 |
+
$newTableContent->title = $rule->rule_name;
|
1180 |
+
$condition = $this->getTextForProductDiscountCondition($rule);
|
1181 |
+
$newTableContent->condition = $condition;
|
1182 |
+
$discount_range[][] = $newTableContent;
|
1183 |
+
}
|
1184 |
}
|
1185 |
+
}
|
1186 |
+
}
|
1187 |
+
return $discount_range;
|
1188 |
+
}
|
1189 |
|
1190 |
+
public function getTextForProductDiscountCondition($rule){
|
1191 |
+
$product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
|
1192 |
+
$product_buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
1193 |
+
$product_quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
1194 |
+
$product_quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
1195 |
+
$product_quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
1196 |
+
$product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
1197 |
+
$product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
1198 |
+
$condition = esc_html__('Buy', 'woo-discount-rules');
|
1199 |
+
|
1200 |
+
switch ($product_quantity_rule) {
|
1201 |
+
case 'less':
|
1202 |
+
$quantity_text = esc_html__(' less than or equal to ', 'woo-discount-rules').$product_quantity_from.esc_html__(' Quantity', 'woo-discount-rules');
|
1203 |
+
break;
|
1204 |
+
case 'equal':
|
1205 |
+
$quantity_text = ' '.$product_quantity_from.esc_html__(' Quantity ', 'woo-discount-rules');
|
1206 |
+
break;
|
1207 |
+
case 'from':
|
1208 |
+
$quantity_text = '( '.$product_quantity_from.' - '.$product_quantity_to.' )'.esc_html__(' Quantity', 'woo-discount-rules');
|
1209 |
+
break;
|
1210 |
+
case 'more':
|
1211 |
+
default:
|
1212 |
+
$quantity_text = ' '.$product_quantity_from.esc_html__(' or more Quantity', 'woo-discount-rules');
|
1213 |
+
}
|
1214 |
|
1215 |
+
switch ($product_buy_type) {
|
1216 |
+
case 'combine':
|
1217 |
+
case 'any':
|
1218 |
+
if(count($product_to_buy) == 1){
|
1219 |
+
$condition .= $quantity_text;
|
1220 |
+
} else {
|
1221 |
+
$condition .= esc_html__(' any ', 'woo-discount-rules').$quantity_text.esc_html__(' products from ','woo-discount-rules');
|
1222 |
}
|
1223 |
+
break;
|
1224 |
+
case 'each':
|
1225 |
+
if(count($product_to_buy) == 1){
|
1226 |
+
$condition .= $quantity_text;
|
1227 |
+
} else {
|
1228 |
+
$condition .= ' '.$quantity_text.esc_html__(' in each products', 'woo-discount-rules');
|
1229 |
+
}
|
1230 |
+
break;
|
1231 |
+
}
|
1232 |
+
if(count($product_to_buy) > 1){
|
1233 |
+
$htmlProduct = '';
|
1234 |
+
foreach ($product_to_buy as $product_id){
|
1235 |
+
$product = wc_get_product( $product_id );
|
1236 |
+
$htmlProduct .= $product->get_title().',';
|
1237 |
}
|
1238 |
+
$condition .= trim($htmlProduct, ',');
|
1239 |
}
|
1240 |
+
$condition .= esc_html__(' and get discount in ', 'woo-discount-rules');
|
1241 |
+
if(count($product_to_apply)){
|
1242 |
+
$htmlProduct = '';
|
1243 |
+
foreach ($product_to_apply as $product_id){
|
1244 |
+
$product = wc_get_product( $product_id );
|
1245 |
+
$htmlProduct .= '<a href="'.$product->get_permalink().'">'.$product->get_title().'</a>, ';
|
1246 |
+
}
|
1247 |
+
$condition .= trim($htmlProduct, ', ');
|
1248 |
+
}
|
1249 |
+
return $condition;
|
1250 |
}
|
1251 |
|
1252 |
/**
|
1296 |
foreach ($table as $index => $item) {
|
1297 |
if ($item) {
|
1298 |
foreach ($item as $id => $value) {
|
1299 |
+
if(isset($value->rule_method) && $value->rule_method == 'product_based'){
|
1300 |
+
$title = $value->title;
|
1301 |
+
$condition = $value->condition;
|
1302 |
+
if ($value->discount_type == 'percentage_discount') {
|
1303 |
+
$discount = $value->to_discount.' %';
|
1304 |
+
} else {
|
1305 |
+
$discount = wc_price($value->to_discount);
|
|
|
|
|
|
|
|
|
|
|
1306 |
}
|
1307 |
+
} else {
|
1308 |
+
$title = isset($value->title) ? $value->title : '';
|
1309 |
+
$min = isset($value->min_qty) ? $value->min_qty : 0;
|
1310 |
+
$max = isset($value->max_qty) ? $value->max_qty : 0;
|
1311 |
+
if($max == 0 || $max == '' || $max == false) $max = 999;
|
1312 |
+
$discount_type = isset($value->discount_type) ? $value->discount_type : 0;
|
1313 |
+
$to_discount = isset($value->to_discount) ? $value->to_discount : 0;
|
1314 |
+
$product_discount = isset($value->discount_product) ? $value->discount_product : array();
|
1315 |
+
if (isset($base_config['show_discount_title_table'])) {
|
1316 |
+
}
|
1317 |
+
$condition = $min .' - ' . $max;
|
1318 |
+
if ($discount_type == 'product_discount') {
|
1319 |
+
$discount = '';
|
1320 |
+
if(count($product_discount)){
|
1321 |
+
$htmlProduct = '';
|
1322 |
+
foreach ($product_discount as $product_id){
|
1323 |
+
$product = wc_get_product( $product_id );
|
1324 |
+
$htmlProduct .= $product->get_title();
|
1325 |
+
$htmlProduct .= ' ('.$product->get_price_html().')<br>';
|
1326 |
+
}
|
1327 |
+
$discount = trim($htmlProduct, '<br>');
|
1328 |
}
|
1329 |
+
} else if ($discount_type == 'percentage_discount') {
|
1330 |
+
$discount = $to_discount.' %';
|
1331 |
+
} else {
|
1332 |
+
$discount = wc_price($to_discount);
|
1333 |
}
|
1334 |
+
|
1335 |
+
}
|
1336 |
+
$html .= '<tr>';
|
1337 |
+
if ($base_config['show_discount_title_table'] == 'show') {
|
1338 |
+
$html .= '<td>'.$title.'</td>';
|
1339 |
}
|
1340 |
+
$html .= '<td>'.$condition.'</td>';
|
1341 |
+
$html .= '<td>'.$discount.'</td>';
|
1342 |
$html .= '</tr>';
|
1343 |
}
|
1344 |
$have_discount = true;
|
loader.php
CHANGED
@@ -72,23 +72,26 @@ include_once('helper/purchase.php');
|
|
72 |
require_once __DIR__ . '/vendor/autoload.php';
|
73 |
|
74 |
// -------------------------- updater -----------------------------------------------------
|
75 |
-
|
|
|
76 |
|
77 |
-
$purchase_helper = new woo_dicount_rules_purchase();
|
78 |
-
$purchase_helper->init();
|
79 |
-
$update_url = $purchase_helper->getUpdateURL();
|
80 |
|
81 |
-
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
);
|
|
|
86 |
|
87 |
-
add_action(
|
|
|
|
|
|
|
88 |
|
89 |
-
add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey'));
|
90 |
|
91 |
-
add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages'));
|
92 |
|
93 |
// -------------------------- end updater -------------------------------------------------
|
94 |
|
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 |
|
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 |
|
@@ -176,6 +176,11 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
|
|
176 |
|
177 |
== Changelog ==
|
178 |
|
|
|
|
|
|
|
|
|
|
|
179 |
= 1.4.26 - 20/11/17 =
|
180 |
* Fix – Error occurred in Woocommerce 2.x
|
181 |
|
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.27
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
176 |
|
177 |
== Changelog ==
|
178 |
|
179 |
+
= 1.4.27 - 24/11/17 =
|
180 |
+
* Fix – Category based rule not applying rule for variant product in cart
|
181 |
+
* Feature – Search option in Select box for product and categories
|
182 |
+
* Feature – Product based rule for pro version
|
183 |
+
|
184 |
= 1.4.26 - 20/11/17 =
|
185 |
* Fix – Error occurred in Woocommerce 2.x
|
186 |
|
view/view-pricing-rules.php
CHANGED
@@ -83,11 +83,21 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
83 |
title="Method to Apply."></i></label></div>
|
84 |
<?php $opt = (isset($data->rule_method) ? $data->rule_method : ''); ?>
|
85 |
<div class="col-md-6"><select class="form-control"
|
86 |
-
name="rule_method">
|
87 |
<option
|
88 |
value="qty_based" <?php if ($opt == 'qty_based') { ?> selected=selected <?php } ?>>
|
89 |
Quantity Based
|
90 |
</option>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
</select></div>
|
92 |
</div>
|
93 |
</div>
|
@@ -134,121 +144,169 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
134 |
</div>
|
135 |
|
136 |
<div class="col-md-12" id="restriction_block"><h4 class="text text-muted"> Discount
|
137 |
-
|
138 |
<hr>
|
139 |
-
<div class="
|
140 |
-
<div class="
|
141 |
-
<div class="
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
<div class="form-group" id="product_list">
|
164 |
-
<?php $products_list = json_decode((isset($data->product_to_apply) ? $data->product_to_apply : '{}'), true); ?>
|
165 |
-
<select class="product_list selectpicker" multiple
|
166 |
-
name="product_to_apply[]">
|
167 |
-
<?php foreach ($products as $index => $value) { ?>
|
168 |
-
<option
|
169 |
-
value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
170 |
-
<?php } ?>
|
171 |
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
</div>
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
</select>
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
187 |
</div>
|
188 |
</div>
|
189 |
</div>
|
190 |
</div>
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
<
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
}
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
<div class="form-group" id="user_list">
|
213 |
-
<?php $users_list = json_decode((isset($data->users_to_apply) ? $data->users_to_apply : '{}'), true); ?>
|
214 |
-
<select class="user_list selectpicker" multiple name="users_to_apply[]">
|
215 |
-
<?php foreach ($users as $index => $value) { ?>
|
216 |
-
<option
|
217 |
-
value="<?php echo $index; ?>"<?php if (in_array($index, $users_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
218 |
-
<?php } ?>
|
219 |
-
</select>
|
220 |
</div>
|
221 |
</div>
|
222 |
</div>
|
223 |
</div>
|
224 |
-
<div class="
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
</div>
|
253 |
</div>
|
254 |
<div class="form-group">
|
@@ -261,100 +319,117 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
|
|
261 |
</div>
|
262 |
</div>
|
263 |
<!-- TODO: Implement ForEach Concept -->
|
264 |
-
<div class="col-md-12" id="discount_block"
|
265 |
-
<
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
276 |
}
|
277 |
-
}
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
|
348 |
-
|
349 |
-
|
350 |
|
|
|
351 |
</div>
|
352 |
-
|
353 |
-
<?php $fieldIndex++; } ?>
|
354 |
-
<div align="right">
|
355 |
-
<input type="button" class="button button-secondary restriction_tab" value="Previous">
|
356 |
</div>
|
357 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
</div>
|
359 |
</div>
|
360 |
<div class="col-md-1"></div>
|
83 |
title="Method to Apply."></i></label></div>
|
84 |
<?php $opt = (isset($data->rule_method) ? $data->rule_method : ''); ?>
|
85 |
<div class="col-md-6"><select class="form-control"
|
86 |
+
name="rule_method" id="price_rule_method">
|
87 |
<option
|
88 |
value="qty_based" <?php if ($opt == 'qty_based') { ?> selected=selected <?php } ?>>
|
89 |
Quantity Based
|
90 |
</option>
|
91 |
+
<option
|
92 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="product_based" <?php
|
93 |
+
}
|
94 |
+
if ($opt == 'product_based') { ?> selected=selected <?php } ?>>
|
95 |
+
<?php if (!$pro) { ?>
|
96 |
+
Product Based <b><?php echo $suffix; ?></b>
|
97 |
+
<?php } else { ?>
|
98 |
+
Product Based
|
99 |
+
<?php } ?>
|
100 |
+
</option>
|
101 |
</select></div>
|
102 |
</div>
|
103 |
</div>
|
144 |
</div>
|
145 |
|
146 |
<div class="col-md-12" id="restriction_block"><h4 class="text text-muted"> Discount
|
147 |
+
Conditions </h4>
|
148 |
<hr>
|
149 |
+
<div class="qty_based_condition_cont price_discount_condition_con">
|
150 |
+
<div class="form-group">
|
151 |
+
<div class="row">
|
152 |
+
<div class="col-md-3"><label> Apply To </label></div>
|
153 |
+
<?php $opt = (isset($data->apply_to) ? $data->apply_to : ''); ?>
|
154 |
+
<div class="col-md-6"><select class="selectpicker"
|
155 |
+
name="apply_to" id="apply_to">
|
156 |
+
<option
|
157 |
+
value="all_products" <?php if ($opt == 'all_products') { ?> selected=selected <?php } ?>>
|
158 |
+
All Products
|
159 |
+
</option>
|
160 |
+
<option
|
161 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="specific_category" <?php }
|
162 |
+
if ($opt == 'specific_category') { ?> selected=selected <?php } ?>>
|
163 |
+
<?php if (!$pro) { ?>
|
164 |
+
Specific Categories <b><?php echo $suffix; ?></b>
|
165 |
+
<?php } else { ?>
|
166 |
+
Specific Categories
|
167 |
+
<?php } ?>
|
168 |
+
</option>
|
169 |
+
<option
|
170 |
+
value="specific_products" <?php if ($opt == 'specific_products') { ?> selected=selected <?php } ?>>
|
171 |
+
Specific Products
|
172 |
+
</option>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
</select>
|
174 |
+
<div class="form-group" id="product_list">
|
175 |
+
<?php $products_list = json_decode((isset($data->product_to_apply) ? $data->product_to_apply : '{}'), true); ?>
|
176 |
+
<select class="product_list selectpicker" multiple
|
177 |
+
name="product_to_apply[]">
|
178 |
+
<?php foreach ($products as $index => $value) { ?>
|
179 |
+
<option
|
180 |
+
value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
181 |
+
<?php } ?>
|
182 |
+
</select>
|
183 |
+
</div>
|
184 |
+
<div class="form-group" id="category_list">
|
185 |
+
<?php $category_list = json_decode((isset($data->category_to_apply) ? $data->category_to_apply : '{}'), true); ?>
|
186 |
+
<select class="category_list selectpicker" multiple
|
187 |
+
name="category_to_apply[]">
|
188 |
+
<?php foreach ($category as $index => $value) { ?>
|
189 |
+
<option
|
190 |
+
value="<?php echo $index; ?>"<?php if (in_array($index, $category_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
191 |
+
<?php } ?>
|
192 |
+
</select>
|
193 |
+
<?php $is_cumulative = (isset($data->is_cumulative))? $data->is_cumulative : 0 ?>
|
194 |
+
<input type="checkbox" name="is_cumulative" id="is_cumulative" value="1" <?php if($is_cumulative) { echo "checked"; } ?>> <label class="checkbox_label" for="is_cumulative">Is Cumulative</label>
|
195 |
+
<div class="apply_child_categories">
|
196 |
+
<?php $apply_child_categories = (isset($data->apply_child_categories))? $data->apply_child_categories : 0 ?>
|
197 |
+
<input type="checkbox" name="apply_child_categories" id="apply_child_categories" value="1" <?php if($apply_child_categories) { echo "checked"; } ?>> <label class="checkbox_label" for="apply_child_categories">Apply Child Categories</label>
|
198 |
+
</div>
|
199 |
+
</div>
|
200 |
</div>
|
201 |
+
</div>
|
202 |
+
</div>
|
203 |
+
|
204 |
+
<div class="form-group">
|
205 |
+
<div class="row">
|
206 |
+
<div class="col-md-3"><label> Customers </label></div>
|
207 |
+
<?php $opt = (isset($data->customer) ? $data->customer : ''); ?>
|
208 |
+
<div class="col-md-6"><select class="selectpicker"
|
209 |
+
name="customer" id="apply_customer">
|
210 |
+
<option value="all" <?php if ($opt == 'all') { ?> selected=selected <?php } ?>>
|
211 |
+
All
|
212 |
+
</option>
|
213 |
+
<option
|
214 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="only_given" <?php
|
215 |
+
}
|
216 |
+
if ($opt == 'only_given') { ?> selected=selected <?php } ?>>
|
217 |
+
<?php if (!$pro) { ?>
|
218 |
+
Only Given <b><?php echo $suffix; ?></b>
|
219 |
+
<?php } else { ?>
|
220 |
+
Only Given
|
221 |
+
<?php } ?>
|
222 |
+
</option>
|
223 |
</select>
|
224 |
+
<div class="form-group" id="user_list">
|
225 |
+
<?php $users_list = json_decode((isset($data->users_to_apply) ? $data->users_to_apply : '{}'), true); ?>
|
226 |
+
<select class="user_list selectpicker" multiple name="users_to_apply[]">
|
227 |
+
<?php foreach ($users as $index => $value) { ?>
|
228 |
+
<option
|
229 |
+
value="<?php echo $index; ?>"<?php if (in_array($index, $users_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
230 |
+
<?php } ?>
|
231 |
+
</select>
|
232 |
</div>
|
233 |
</div>
|
234 |
</div>
|
235 |
</div>
|
236 |
+
<div class="form-group">
|
237 |
+
<div class="row">
|
238 |
+
<div class="col-md-3"><label><?php esc_html_e('Purchase History', 'woo-discount-rules'); ?></label></div>
|
239 |
+
<?php $based_on_purchase_history = (isset($data->based_on_purchase_history) ? $data->based_on_purchase_history : 0); ?>
|
240 |
+
<div class="col-md-6">
|
241 |
+
<input type="checkbox" class="" id="based_on_purchase_history" name="based_on_purchase_history"
|
242 |
+
value="1" <?php if($based_on_purchase_history){ echo 'checked'; } ?>>
|
243 |
+
<label class="checkbox_label" for="based_on_purchase_history"><?php esc_html_e('Yes, based on Purchase history.', 'woo-discount-rules'); ?></label>
|
244 |
+
<div class="form-group" id="based_on_purchase_history_fields">
|
245 |
+
<?php $purchased_history_amount = (isset($data->purchased_history_amount) ? $data->purchased_history_amount : 0); ?>
|
246 |
+
<label><?php esc_html_e('Total purchased amount at least', 'woo-discount-rules'); ?></label>
|
247 |
+
<input type="text" value="<?php echo $purchased_history_amount; ?>" name="purchased_history_amount"/>
|
248 |
+
<label><?php esc_html_e('In Order status', 'woo-discount-rules'); ?></label>
|
249 |
+
<?php
|
250 |
+
$woocommerce_order_status = wc_get_order_statuses();
|
251 |
+
$purchase_history_status_list = json_decode((isset($data->purchase_history_status_list) ? $data->purchase_history_status_list : '{}'), true);
|
252 |
+
if(empty($purchase_history_status_list)){
|
253 |
+
$purchase_history_status_list[] = 'wc-completed';
|
254 |
}
|
255 |
+
?>
|
256 |
+
<select class="purchase_history_status_list selectpicker" multiple name="purchase_history_status_list[]">
|
257 |
+
<?php foreach ($woocommerce_order_status as $index => $value) { ?>
|
258 |
+
<option
|
259 |
+
value="<?php echo $index; ?>"<?php if (in_array($index, $purchase_history_status_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
260 |
+
<?php } ?>
|
261 |
+
</select>
|
262 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
</div>
|
264 |
</div>
|
265 |
</div>
|
266 |
</div>
|
267 |
+
<div class="product_based_condition_cont price_discount_condition_con">
|
268 |
+
<?php
|
269 |
+
$product_based_conditions = json_decode((isset($data->product_based_condition) ? $data->product_based_condition : '{}'), true);
|
270 |
+
$product_based_condition_product_buy_type = isset($product_based_conditions['product_buy_type']) ? $product_based_conditions['product_buy_type'] : 'any';
|
271 |
+
$product_based_condition_product_quantity_rule = isset($product_based_conditions['product_quantity_rule']) ? $product_based_conditions['product_quantity_rule'] : 'more';
|
272 |
+
$product_based_condition_product_quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
|
273 |
+
$product_based_condition_product_quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
|
274 |
+
$product_based_condition_product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
|
275 |
+
$product_based_condition_product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
|
276 |
+
?>
|
277 |
+
<div class="form-group" id="product_list">
|
278 |
+
<label ><?php esc_html_e('Buy', 'woo-discount-rules') ?></label>
|
279 |
+
<select class="selectpicker" name="product_based_condition[product_buy_type]">
|
280 |
+
<option value="any"<?php echo ($product_based_condition_product_buy_type == 'any')? ' selected="selected"': ''; ?>><?php esc_html_e('Any', 'woo-discount-rules') ?></option>
|
281 |
+
<option value="each"<?php echo ($product_based_condition_product_buy_type == 'each')? ' selected="selected"': ''; ?>><?php esc_html_e('Each', 'woo-discount-rules') ?></option>
|
282 |
+
<option value="combine"<?php echo ($product_based_condition_product_buy_type == 'combine')? ' selected="selected"': ''; ?>><?php esc_html_e('Combine', 'woo-discount-rules') ?></option>
|
283 |
+
</select>
|
284 |
+
<select class="selectpicker" id="product_based_condition_quantity_rule" name="product_based_condition[product_quantity_rule]">
|
285 |
+
<option value="more"<?php echo ($product_based_condition_product_quantity_rule == 'more')? ' selected="selected"': ''; ?>><?php esc_html_e('More than', 'woo-discount-rules') ?></option>
|
286 |
+
<option value="less"<?php echo ($product_based_condition_product_quantity_rule == 'less')? ' selected="selected"': ''; ?>><?php esc_html_e('Less than', 'woo-discount-rules') ?></option>
|
287 |
+
<option value="equal"<?php echo ($product_based_condition_product_quantity_rule == 'equal')? ' selected="selected"': ''; ?>><?php esc_html_e('Equal', 'woo-discount-rules') ?></option>
|
288 |
+
<option value="from"<?php echo ($product_based_condition_product_quantity_rule == 'from')? ' selected="selected"': ''; ?>><?php esc_html_e('From', 'woo-discount-rules') ?></option>
|
289 |
+
</select>
|
290 |
+
<input placeholder="<?php esc_html_e('Quantity', 'woo-discount-rules') ?>" type="text" name="product_based_condition[product_quantity_from]" value="<?php echo $product_based_condition_product_quantity_from; ?>"/ >
|
291 |
+
<div class="product_based_condition_to">
|
292 |
+
<label ><?php esc_html_e('to', 'woo-discount-rules')?></label>
|
293 |
+
<input placeholder="<?php esc_html_e('Quantity', 'woo-discount-rules') ?>" type="text" name="product_based_condition[product_quantity_to]" value="<?php echo $product_based_condition_product_quantity_to; ?>"/ >
|
294 |
</div>
|
295 |
+
<label ><?php esc_html_e('Product(s) from', 'woo-discount-rules')?></label>
|
296 |
+
<select class="product_list selectpicker" multiple name="product_based_condition[product_to_buy][]">
|
297 |
+
<?php foreach ($products as $index => $value) { ?>
|
298 |
+
<option
|
299 |
+
value="<?php echo $index; ?>" <?php if (in_array($index, $product_based_condition_product_to_buy)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
300 |
+
<?php } ?>
|
301 |
+
</select>
|
302 |
+
<label ><?php esc_html_e('and get discount in ', 'woo-discount-rules') ?></label>
|
303 |
+
<select class="product_list selectpicker" multiple name="product_based_condition[product_to_apply][]">
|
304 |
+
<?php foreach ($products as $index => $value) { ?>
|
305 |
+
<option
|
306 |
+
value="<?php echo $index; ?>" <?php if (in_array($index, $product_based_condition_product_to_apply)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
307 |
+
<?php } ?>
|
308 |
+
</select>
|
309 |
+
<label ><?php esc_html_e('Product(s)', 'woo-discount-rules') ?></label>
|
310 |
</div>
|
311 |
</div>
|
312 |
<div class="form-group">
|
319 |
</div>
|
320 |
</div>
|
321 |
<!-- TODO: Implement ForEach Concept -->
|
322 |
+
<div class="col-md-12" id="discount_block">
|
323 |
+
<h4 class="text text-muted"> Discount</h4>
|
324 |
+
<div class="qty_based_discount_cont price_discounts_con">
|
325 |
+
<a href=javascript:void(0) class="button button-primary" id="addNewDiscountRange"><i
|
326 |
+
class="glyphicon glyphicon-plus"></i> Add New Range</a>
|
327 |
+
<hr>
|
328 |
+
<div id="discount_rule_list">
|
329 |
+
<?php
|
330 |
+
$discount_range = new stdClass();
|
331 |
+
if (isset($data->discount_range)) {
|
332 |
+
if (is_string($data->discount_range)) {
|
333 |
+
$discount_range = json_decode($data->discount_range);
|
334 |
+
} else {
|
335 |
+
$discount_range = $data->discount_range;
|
336 |
+
}
|
337 |
}
|
|
|
338 |
|
339 |
+
// Make Dummy Element.
|
340 |
+
if ($discount_range == '') $discount_range = array(0 => '');
|
341 |
+
$fieldIndex = 1;
|
342 |
+
foreach ($discount_range as $index => $discount) {
|
343 |
+
?>
|
344 |
+
<div class="discount_rule_list">
|
345 |
+
<div class="form-group">
|
346 |
+
<label>Min Quantity
|
347 |
+
<input type="text"
|
348 |
+
name="discount_range[<?php echo $fieldIndex; ?>][min_qty]"
|
349 |
+
class="form-control"
|
350 |
+
value="<?php echo(isset($discount->min_qty) ? $discount->min_qty : ''); ?>"
|
351 |
+
placeholder="ex. 1">
|
352 |
+
</label>
|
353 |
+
<label>Max Quantity
|
354 |
+
<input type="text"
|
355 |
+
name="discount_range[<?php echo $fieldIndex; ?>][max_qty]"
|
356 |
+
class="form-control"
|
357 |
+
value="<?php echo(isset($discount->max_qty) ? $discount->max_qty : ''); ?>"
|
358 |
+
placeholder="ex. 50"> </label>
|
359 |
+
<label>Adjustment Type
|
360 |
+
<select class="form-control price_discount_type"
|
361 |
+
name="discount_range[<?php echo $fieldIndex; ?>][discount_type]">
|
362 |
+
<?php $opt = (isset($discount->discount_type) ? $discount->discount_type : ''); ?>
|
363 |
+
<option
|
364 |
+
value="percentage_discount" <?php if ($opt == 'percentage_discount') { ?> selected=selected <?php } ?> >
|
365 |
+
Percentage Discount
|
366 |
+
</option>
|
367 |
|
368 |
+
<option
|
369 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="price_discount" <?php
|
370 |
+
}
|
371 |
+
if ($opt == 'price_discount') { ?> selected=selected <?php } ?>>
|
372 |
+
<?php if (!$pro) { ?>
|
373 |
+
Price Discount <b><?php echo $suffix; ?></b>
|
374 |
+
<?php } else { ?>
|
375 |
+
Price Discount
|
376 |
+
<?php } ?>
|
377 |
+
</option>
|
378 |
+
<option
|
379 |
+
<?php if (!$pro) { ?> disabled <?php } else { ?> value="product_discount" <?php
|
380 |
+
}
|
381 |
+
if ($opt == 'product_discount') { ?> selected=selected <?php } ?>>
|
382 |
+
<?php if (!$pro) { ?>
|
383 |
+
Product Discount <b><?php echo $suffix; ?></b>
|
384 |
+
<?php } else { ?>
|
385 |
+
Product Discount
|
386 |
+
<?php } ?>
|
387 |
+
</option>
|
388 |
+
</select></label>
|
389 |
+
<label>Value
|
390 |
+
<input type="text"
|
391 |
+
name="discount_range[<?php echo $fieldIndex; ?>][to_discount]"
|
392 |
+
class="form-control price_discount_amount"
|
393 |
+
value="<?php echo(isset($discount->to_discount) ? $discount->to_discount : ''); ?>"
|
394 |
+
placeholder="ex. 50">
|
395 |
+
<?php
|
396 |
+
$products_list = (isset($discount->discount_product) ? $discount->discount_product : array()); ?>
|
397 |
+
<div class="price_discount_product_list_con hide">
|
398 |
+
<select class="product_list selectpicker price_discount_product_list" multiple
|
399 |
+
name="discount_range[<?php echo $fieldIndex; ?>][discount_product][]">
|
400 |
+
<?php foreach ($products as $index => $value) { ?>
|
401 |
+
<option
|
402 |
+
value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
|
403 |
+
<?php } ?>
|
404 |
+
</select>
|
405 |
+
</div>
|
406 |
+
</label>
|
407 |
|
408 |
+
<label>Action <a href=javascript:void(0)
|
409 |
+
class="button button-secondary form-control remove_discount_range">Remove</a></label>
|
410 |
|
411 |
+
</div>
|
412 |
</div>
|
413 |
+
<?php $fieldIndex++; } ?>
|
|
|
|
|
|
|
414 |
</div>
|
415 |
</div>
|
416 |
+
<div class="product_based_discount_cont price_discounts_con">
|
417 |
+
<div class="price_discount_product_list_con">
|
418 |
+
<?php
|
419 |
+
$product_based_discounts = json_decode((isset($data->product_based_discount) ? $data->product_based_discount : '{}'), true);
|
420 |
+
$product_based_discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
|
421 |
+
$product_based_discount_value = isset($product_based_discounts['discount_value']) ? $product_based_discounts['discount_value'] : '';
|
422 |
+
?>
|
423 |
+
<select class="selectpicker" name="product_based_discount[discount_type]">
|
424 |
+
<option value="percentage_discount"<?php echo ($product_based_discount_type == 'percentage_discount')? ' selected="selected"': ''; ?>><?php esc_html_e('Percent', 'woo-discount-rules') ?></option>
|
425 |
+
<option value="price_discount"<?php echo ($product_based_discount_type == 'price_discount')? ' selected="selected"': ''; ?>><?php esc_html_e('Fixed', 'woo-discount-rules') ?></option>
|
426 |
+
</select> <label><?php esc_html_e('Value', 'woo-discount-rules') ?></label>
|
427 |
+
<input type="text" name="product_based_discount[discount_value]" value="<?php echo $product_based_discount_value; ?>" />
|
428 |
+
</div>
|
429 |
+
</div>
|
430 |
+
<div align="right">
|
431 |
+
<input type="button" class="button button-secondary restriction_tab" value="Previous">
|
432 |
+
</div>
|
433 |
</div>
|
434 |
</div>
|
435 |
<div class="col-md-1"></div>
|
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.27
|
9 |
* Slug: woo-discount-rules
|
10 |
* Text Domain: woo-discount-rules
|
11 |
* Requires at least: 4.6.1
|