Version Description
Download this release
Release Info
Developer | damian-gora |
Plugin | Ajax Search for WooCommerce |
Version | 1.1.3 |
Comparing to | |
See all releases |
Code changes from version 1.1.2 to 1.1.3
- ajax-search-for-woocommerce.php +2 -2
- assets/js/jquery.dgwt-wcas.js +2 -2
- assets/js/jquery.dgwt-wcas.min.js +1 -1
- includes/class-result-details.php +1 -1
- includes/class-search.php +530 -484
- includes/install.php +96 -96
- readme.txt +120 -115
ajax-search-for-woocommerce.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Ajax Search for WooCommerce
|
5 |
* Plugin URI: https://wordpress.org/plugins/ajax-search-for-woocommerce/
|
6 |
* Description: The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
|
7 |
-
* Version: 1.1.
|
8 |
* Author: Damian Góra
|
9 |
* Author URI: http://damiangora.com
|
10 |
* Text Domain: ajax-search-for-woocommerce
|
@@ -97,7 +97,7 @@ if ( !class_exists( 'DGWT_WC_Ajax_Search' ) ) {
|
|
97 |
*/
|
98 |
private function constants() {
|
99 |
|
100 |
-
$this->define( 'DGWT_WCAS_VERSION', '1.1.
|
101 |
$this->define( 'DGWT_WCAS_NAME', 'Ajax Search for WooCommerce' );
|
102 |
$this->define( 'DGWT_WCAS_FILE', __FILE__ );
|
103 |
$this->define( 'DGWT_WCAS_DIR', plugin_dir_path( __FILE__ ) );
|
4 |
* Plugin Name: Ajax Search for WooCommerce
|
5 |
* Plugin URI: https://wordpress.org/plugins/ajax-search-for-woocommerce/
|
6 |
* Description: The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
|
7 |
+
* Version: 1.1.3
|
8 |
* Author: Damian Góra
|
9 |
* Author URI: http://damiangora.com
|
10 |
* Text Domain: ajax-search-for-woocommerce
|
97 |
*/
|
98 |
private function constants() {
|
99 |
|
100 |
+
$this->define( 'DGWT_WCAS_VERSION', '1.1.3' );
|
101 |
$this->define( 'DGWT_WCAS_NAME', 'Ajax Search for WooCommerce' );
|
102 |
$this->define( 'DGWT_WCAS_FILE', __FILE__ );
|
103 |
$this->define( 'DGWT_WCAS_DIR', plugin_dir_path( __FILE__ ) );
|
assets/js/jquery.dgwt-wcas.js
CHANGED
@@ -844,8 +844,8 @@
|
|
844 |
if ( result.details != null ) {
|
845 |
containerDetails.html( result.details );
|
846 |
} else {
|
847 |
-
|
848 |
-
containerDetails.html( '
|
849 |
}
|
850 |
that.fixPositionDetailsBox();
|
851 |
that.fixHeight();
|
844 |
if ( result.details != null ) {
|
845 |
containerDetails.html( result.details );
|
846 |
} else {
|
847 |
+
// @TODO Co wyświetlić w details box gdy napotkamy błąd?
|
848 |
+
containerDetails.html( '' );
|
849 |
}
|
850 |
that.fixPositionDetailsBox();
|
851 |
that.fixHeight();
|
assets/js/jquery.dgwt-wcas.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(e){"use strict";function t(s,n){var i=e.noop,o=this,a={ajaxSettings:{},autoSelectFirst:!1,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,onMouseOver:null,onMouseLeave:null,width:"auto",containerDetailsWidth:"auto",showDetailsPanel:!1,showImage:!1,showPrice:!1,showSKU:!1,showDescription:!1,showSaleBadge:!1,showFeaturedBadge:!1,saleBadgeText:"sale",featuredBadgeText:"featured",minChars:1,maxHeight:1e3,deferRequestBy:0,params:{},formatResult:t.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,is_rtl:!1,onSearchStart:i,onSearchComplete:i,onSearchError:i,preserveInput:!1,wrapperaClass:"dgwt-wcas-search-wrapp",containerClass:"dgwt-wcas-suggestions-wrapp",containerDetailsClass:"dgwt-wcas-details-wrapp",cointainerDetailsPos:"right",preloaderClass:"dgwt-wcas-preloader",closeTrigger:"dgwt-wcas-close",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:function(e,t,s){return-1!==e.value.toLowerCase().indexOf(s)},paramName:"query",transformResult:function(t){return"string"==typeof t?e.parseJSON(t):t},showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1};o.element=s,o.el=e(s),o.suggestions=[],o.badQueries=[],o.selectedIndex=-1,o.currentValue=o.element.value,o.intervalId=0,o.cachedResponse={},o.cachedDetails={},o.detailsRequestsSent=[],o.onChangeInterval=null,o.onChange=null,o.isLocal=!1,o.suggestionsContainer=null,o.detailsContainer=null,o.noSuggestionsContainer=null,o.options=e.extend({},a,n),o.classes={selected:"dgwt-wcas-suggestion-selected",suggestion:"dgwt-wcas-suggestion"},o.hint=null,o.hintValue="",o.selection=null,o.initialize(),o.setOptions(n)}var s=function(){return{escapeRegExChars:function(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},createNode:function(e){var t=document.createElement("div");return t.className=e,t.style.position="absolute",t.style.display="none",t}}}(),n={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40};t.utils=s,e.Autocomplete=t,t.formatResult=function(e,t){if(!t)return e;var n="("+s.escapeRegExChars(t)+")";return e.replace(new RegExp(n,"gi"),"<strong>$1</strong>").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/<(\/?strong)>/g,"<$1>")},t.prototype={killerFn:null,initialize:function(){var s,n=this,i="."+n.classes.suggestion,o=(n.classes.selected,n.options),a="."+o.closeTrigger;n.element.setAttribute("autocomplete","off"),n.killerFn=function(t){0===e(t.target).closest("."+n.options.containerClass).length&&0===e(t.target).closest("."+n.options.containerDetailsClass).length&&(n.killSuggestions(),n.disableKillerFn())},n.noSuggestionsContainer=e('<div class="dgwt-wcas-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),n.suggestionsContainer=t.utils.createNode(o.containerClass),(s=e(n.suggestionsContainer)).appendTo(n.el.closest("."+o.wrapperaClass)),!0===o.showImage&&s.addClass("dgwt-wcas-has-img"),!0===o.showPrice&&s.addClass("dgwt-wcas-has-price"),!0===o.showDescription&&s.addClass("dgwt-wcas-has-desc"),!0===o.showSKU&&s.addClass("dgwt-wcas-has-sku"),"auto"!==o.width&&s.width(o.width),!0===o.showDetailsPanel&&(n.detailsContainer=t.utils.createNode(o.containerDetailsClass),e(n.detailsContainer).appendTo(n.el.closest("."+o.wrapperaClass))),s.on("mouseover.autocomplete",i,function(){n.onMouseOver(e(this).data("index")),n.activate(e(this).data("index"))}),s.on("mouseout.autocomplete",function(){}),e(document).on("click.autocomplete",a,function(t){n.killerFn(t),n.clear(t),e(this).removeClass(o.closeTrigger),n.el.val("").focus()}),s.on("click.autocomplete",i,function(){return n.select(e(this).data("index")),!1}),n.fixPositionCapture=function(){n.visible&&n.fixPosition()},e(window).on("resize.autocomplete",n.fixPositionCapture),n.el.on("keydown.autocomplete",function(e){n.onKeyPress(e)}),n.el.on("keyup.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("blur.autocomplete",function(){n.onBlur()}),n.el.on("focus.autocomplete",function(){n.onFocus()}),n.el.on("change.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("input.autocomplete",function(e){n.onKeyUp(e)})},onFocus:function(){var e=this;e.fixPosition(),e.el.val().length>=e.options.minChars&&e.onValueChange()},onBlur:function(){this.enableKillerFn()},abortAjax:function(){var e=this;e.currentRequest&&(e.currentRequest.abort(),e.currentRequest=null)},setOptions:function(t){var s=this,n=s.options;e.extend(n,t),s.isLocal=e.isArray(n.lookup),s.isLocal&&(n.lookup=s.verifySuggestionsFormat(n.lookup)),n.orientation=s.validateOrientation(n.orientation,"bottom"),e(s.suggestionsContainer).css({"max-height":n.maxHeight+"px",width:n.width+"px","z-index":n.zIndex}),!0===n.showDetailsPanel&&jQuery(s.suggestionsContainer).parent().addClass("dgwt-wcas-is-details"),s.options.onSearchComplete=function(){s.preloader("hide",e("."+n.preloaderClass),"dgwt-wcas-inner-preloader"),s.preloader("show",e("."+n.preloaderClass),n.closeTrigger)}},clearCache:function(){this.cachedResponse={},this.cachedDetails={},this.badQueries=[]},clear:function(){this.clearCache(),this.currentValue="",this.suggestions=[]},disable:function(){var e=this;e.disabled=!0,clearInterval(e.onChangeInterval),e.abortAjax()},enable:function(){this.disabled=!1},fixPosition:function(){var t=this,s=(t.options,e(t.suggestionsContainer)),n=(e(t.detailsContainer),s.parent().get(0));if(n===document.body||t.options.forceFixPosition){var i=t.options.orientation,o=s.outerHeight(),a=t.el.outerHeight(),l=t.el.offset(),r={top:l.top,left:l.left};if("auto"===i){var u=e(window).height(),c=e(window).scrollTop(),d=-c+l.top-o,g=c+u-(l.top+a+o);i=Math.max(d,g)===d?"top":"bottom"}if(r.top+="top"===i?-o:a,n!==document.body){var h,p=s.css("opacity");t.visible||s.css("opacity",0).show(),h=s.offsetParent().offset(),r.top-=h.top,r.left-=h.left,t.visible||s.css("opacity",p).hide()}"auto"===t.options.width&&(r.width=t.el.outerWidth()-2+"px"),s.css(r)}},fixPositionDetailsBox:function(){var t=e(this.detailsContainer);if(0==t.length)return!1;var s=e(window).width(),n=t.parent(),i=t.prev(),o=t.width(),a=t.offset();n.width()>=550||(s<a.left+o&&(n.removeClass("dgwt-wcas-details-right"),n.addClass("dgwt-wcas-details-left"),t.css("left","-"+t.outerWidth()+"px")),a.left<1&&(n.removeClass("dgwt-wcas-details-left"),n.addClass("dgwt-wcas-details-right"),t.css("left",i.outerWidth()+"px")))},fixHeight:function(t,s){var n=this,i=n.options;if(1!=i.showDetailsPanel)return!1;var s,o=e("."+i.containerClass),a=e("."+i.containerDetailsClass),l=0,r=0;e("."+i.containerClass+"> *").each(function(){l+=e(this).outerHeight()}),e("."+i.containerDetailsClass+"> *").each(function(){r+=e(this).outerHeight()}),((s=l>=r?l:r)>l||s>r)&&(o.css("height",s+"px"),a.css("height",s+"px")),void 0===t&&(t=0),t<5?setTimeout(function(){n.fixHeight(t+1,s)},30):t=0},enableKillerFn:function(){var t=this;e(document).on("click.autocomplete",t.killerFn)},disableKillerFn:function(){var t=this;e(document).off("click.autocomplete",t.killerFn)},killSuggestions:function(){var t=this,s=e(t.suggestionsContainer).parent();t.stopKillSuggestions(),t.intervalId=window.setInterval(function(){t.visible&&(t.options.preserveInput||t.el.val(t.currentValue),t.hide(),s.removeClass("dgwt-wcas-open")),t.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var e,t=this,s=t.el.val().length,n=t.element.selectionStart;return"number"==typeof n?n===s:!document.selection||((e=document.selection.createRange()).moveStart("character",-s),s===e.text.length)},onKeyPress:function(e){var t=this;if(t.disabled||t.visible||e.which!==n.DOWN||!t.currentValue){if(!t.disabled&&t.visible){switch(e.which){case n.ESC:t.el.val(t.currentValue),t.hide();break;case n.RIGHT:if(t.hint&&t.options.onHint&&t.isCursorAtEnd()){t.selectHint();break}return;case n.TAB:if(t.hint&&t.options.onHint)return void t.selectHint();if(-1===t.selectedIndex)return void t.hide();if(t.select(t.selectedIndex),!1===t.options.tabDisabled)return;break;case n.RETURN:if(-1===t.selectedIndex)return void t.hide();t.select(t.selectedIndex);break;case n.UP:t.moveUp();break;case n.DOWN:t.moveDown();break;default:return}e.stopImmediatePropagation(),e.preventDefault()}}else t.suggest()},onKeyUp:function(e){var t=this;if(!t.disabled){switch(e.which){case n.UP:case n.DOWN:return}clearInterval(t.onChangeInterval),t.currentValue!==t.el.val()&&(t.findBestHint(),t.options.deferRequestBy>0?t.onChangeInterval=setInterval(function(){t.onValueChange()},t.options.deferRequestBy):t.onValueChange())}},onValueChange:function(){var t=this,s=t.options,n=t.el.val(),i=t.getQuery(n);t.selection&&t.currentValue!==i&&(t.selection=null,(s.onInvalidateSelection||e.noop).call(t.element)),clearInterval(t.onChangeInterval),t.currentValue=n,t.selectedIndex=-1,s.triggerSelectOnValidInput&&t.isExactMatch(i)?t.select(0):i.length<s.minChars?(e("."+t.options.closeTrigger).removeClass(t.options.closeTrigger),t.hide()):t.getSuggestions(i)},isExactMatch:function(e){var t=this.suggestions;return 1===t.length&&t[0].value.toLowerCase()===e.toLowerCase()},getQuery:function(t){var s,n=this.options.delimiter;return n?(s=t.split(n),e.trim(s[s.length-1])):t},getSuggestionsLocal:function(t){var s,n=this.options,i=t.toLowerCase(),o=n.lookupFilter,a=parseInt(n.lookupLimit,10);return s={suggestions:e.grep(n.lookup,function(e){return o(e,t,i)})},a&&s.suggestions.length>a&&(s.suggestions=s.suggestions.slice(0,a)),s},getSuggestions:function(t){var s,n,i,o,a=this,l=a.options,r=l.serviceUrl;l.params[l.paramName]=t,n=l.ignoreParams?null:l.params,a.preloader("show",e("."+l.preloaderClass),"dgwt-wcas-inner-preloader"),!1!==l.onSearchStart.call(a.element,l.params)&&(e.isFunction(l.lookup)?l.lookup(t,function(e){a.suggestions=e.suggestions,a.suggest(),a.getDetails(e.suggestions[0]),l.onSearchComplete.call(a.element,t,e.suggestions)}):(a.isLocal?s=a.getSuggestionsLocal(t):(e.isFunction(r)&&(r=r.call(a.element,t)),i=r+"?"+e.param(n||{}),s=a.cachedResponse[i]),s&&e.isArray(s.suggestions)?(a.suggestions=s.suggestions,a.suggest(),a.getDetails(s.suggestions[0]),l.onSearchComplete.call(a.element,t,s.suggestions)):a.isBadQuery(t)?l.onSearchComplete.call(a.element,t,[]):(a.abortAjax(),o={url:r,data:n,type:l.type,dataType:l.dataType},e.extend(o,l.ajaxSettings),a.currentRequest=e.ajax(o).done(function(e){var s;a.currentRequest=null,void 0!==(s=l.transformResult(e,t)).suggestions&&(a.processResponse(s,t,i),a.getDetails(s.suggestions[0])),l.onSearchComplete.call(a.element,t,s.suggestions)}).fail(function(e,s,n){l.onSearchError.call(a.element,t,e,s,n)}))))},getDetails:function(t){var s=this,n=s.options;if(1!=n.showDetailsPanel||e(window).width()<992||"ontouchend"in document)return!1;if(null!=t){var i,o,a=e("."+n.containerDetailsClass);s.fixHeight();var l={action:dgwt_wcas.action_result_details,post_id:null!=t.post_id?t.post_id:0,term_id:null!=t.term_id?t.term_id:0,taxonomy:null!=t.taxonomy?t.taxonomy:"",value:null!=t.value?t.value:""};if(i=l.action+l.post_id+l.term_id+l.taxonomy,null!=(o=s.cachedDetails[i]))a.html(o.details),s.fixHeight(),s.fixPositionDetailsBox();else{if(a.html(""),s.preloader("show",a,"",!0),-1!=e.inArray(i,s.detailsRequestsSent))return;s.detailsRequestsSent.push(i),e.ajax({data:l,type:"post",url:dgwt_wcas.ajax_details_endpoint,success:function(e){var t="string"==typeof e?jQuery.parseJSON(e):e;s.cachedDetails[i]=t,s.preloader("hide",a,"",!0),null!=t.details?a.html(t.details):a.html("@TODO BŁĄD"),s.fixPositionDetailsBox(),s.fixHeight()},error:function(e,t){s.preloader("hide",a,"",!0),a.html(e),s.fixPositionDetailsBox(),s.fixHeight()}})}}},isBadQuery:function(e){if(!this.options.preventBadQueries)return!1;for(var t=this.badQueries,s=t.length;s--;)if(0===e.indexOf(t[s]))return!0;return!1},hide:function(){var t=this,s=e(t.suggestionsContainer);e(t.detailsContainer);e.isFunction(t.options.onHide)&&t.visible&&t.options.onHide.call(t.element,s),t.visible=!1,t.selectedIndex=-1,clearInterval(t.onChangeInterval),e(t.suggestionsContainer).hide(),e(t.detailsContainer).hide(),t.signalHint(null)},suggest:function(){if(this.suggestions.length){var t,s=this,n=s.options,i=n.groupBy,o=n.formatResult,a=s.getQuery(s.currentValue),l=s.classes.suggestion,r=s.classes.selected,u=e(s.suggestionsContainer),c=e(s.detailsContainer),d=e(s.noSuggestionsContainer),g=n.beforeRender,h="",p=function(e,s){var n=e.data[i];return t===n?"":'<div class="autocomplete-group"><strong>'+(t=n)+"</strong></div>"};n.triggerSelectOnValidInput&&s.isExactMatch(a)?s.select(0):(e.each(s.suggestions,function(e,t){var s="",r="",u=!1;i&&(h+=p(t,0)),void 0===t.post_id?(h+='<div class="'+l+' dgwt-wcas-nores" data-index="'+e+'">',h+='<span class="dgwt-wcas-st">'+t.value+"</span>",h+="</div>"):(void 0!==t.parents&&(s=t.parents),!0===n.showImage&&void 0!==t.thumb_html&&(u=!0),r+=void 0!==t.post_id?'data-post-id="'+t.post_id+'" ':"",r+=void 0!==t.taxonomy?'data-taxonomy="'+t.taxonomy+'" ':"",r+=void 0!==t.term_id?'data-term-id="'+t.term_id+'" ':"",h+='<div class="'+l+'" data-index="'+e+'" '+r+">",u&&(h+='<span class="dgwt-wcas-si">'+t.thumb_html+"</span>"),h+=u?'<div class="dgwt-wcas-content-wrapp">':"",h+='<span class="dgwt-wcas-st">',h+="<span>"+o(t.value,a)+s+"</span>",!0===n.showSKU&&void 0!==t.sku&&t.sku.length>0&&(h+='<span class="dgwt-wcas-sku">(SKU: '+o(t.sku,a)+")</span>"),h+="</span>",!0===n.showPrice&&void 0!==t.price&&(h+='<span class="dgwt-wcas-sp">'+t.price+"</span>"),!0===n.showDescription&&void 0!==t.desc&&(h+='<span class="dgwt-wcas-sd">'+o(t.desc,a)+"</span>"),!0===n.showFeaturedBadge&&!0===t.on_sale&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-os">'+n.saleBadgeText+"</span>"),!0===n.showFeaturedBadge&&!0===t.featured&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-f">'+n.featuredBadgeText+"</span>"),h+=u?"</div>":"",h+="</div>")}),this.adjustContainerWidth(),d.detach(),u.html(h),e.isFunction(g)&&g.call(s.element,u,s.suggestions),s.fixPosition(),u.show(),u.parent().addClass("dgwt-wcas-open"),!0===n.showDetailsPanel&&c.show(),n.autoSelectFirst&&(s.selectedIndex=0,u.scrollTop(0),u.children("."+l).first().addClass(r)),s.visible=!0,s.findBestHint())}else this.options.showNoSuggestionNotice?this.noSuggestions():this.hide()},noSuggestions:function(){var t=this,s=e(t.suggestionsContainer),n=e(t.noSuggestionsContainer);this.adjustContainerWidth(),n.detach(),s.empty(),s.append(n),t.fixPosition(),s.show(),t.visible=!0},adjustContainerWidth:function(){var t,s=this,n=s.options,i=e(s.suggestionsContainer).parent(),o=e(s.suggestionsContainer),a=e(s.detailsContainer);if("auto"===n.width&&(t=s.el.outerWidth(),o.css("width",t+"px")),i.width()>=550&&!0===n.showDetailsPanel)return i.addClass("dgwt-wcas-full-width"),o.outerWidth(300),a.innerWidth(i.width()-300),i.removeClass("dgwt-wcas-details-left"),i.removeClass("dgwt-wcas-details-right"),void(!0===n.is_rtl?(a.css("left","0"),o.css("right","0")):(a.css("right","0"),o.css("left","0")));"left"===n.cointainerDetailsPos?(a.parent().addClass("dgwt-wcas-details-left"),a.css("left","-"+a.outerWidth()+"px")):(a.parent().addClass("dgwt-wcas-details-right"),a.css("left",i.outerWidth()+"px"))},findBestHint:function(){var t=this,s=t.el.val().toLowerCase(),n=null;s&&(e.each(t.suggestions,function(e,t){var i=0===t.value.toLowerCase().indexOf(s);return i&&(n=t),!i}),t.signalHint(n))},signalHint:function(t){var s="",n=this;t&&(s=n.currentValue+t.value.substr(n.currentValue.length)),n.hintValue!==s&&(n.hintValue=s,n.hint=t,(this.options.onHint||e.noop)(s))},preloader:function(t,s,n,i){var o,a="dgwt-wcas-preloader-wrapp",l=null==n?a:a+" "+n;1==dgwt_wcas.show_preloader&&0!=s.length&&(!0===i?"hide"!==t?"show"===t&&(o='<div class="'+l+'"><div class="dgwt-wcas-default-preloader"></div></div>',s.html(o)):e(a).remove():"hide"===t?s.removeClass(n):s.addClass(n))},verifySuggestionsFormat:function(t){return t.length&&"string"==typeof t[0]?e.map(t,function(e){return{value:e,data:null}}):t},validateOrientation:function(t,s){return t=e.trim(t||"").toLowerCase(),-1===e.inArray(t,["auto","bottom","top"])&&(t=s),t},processResponse:function(e,t,s){var n=this,i=n.options;e.suggestions=n.verifySuggestionsFormat(e.suggestions),i.noCache||(n.cachedResponse[s]=e,i.preventBadQueries&&!e.suggestions.length&&n.badQueries.push(t)),t===n.getQuery(n.currentValue)&&(n.suggestions=e.suggestions,n.suggest())},activate:function(t){var s,n=this,i=n.classes.selected,o=e(n.suggestionsContainer),a=o.find("."+n.classes.suggestion);return o.find("."+i).removeClass(i),n.selectedIndex=t,-1!==n.selectedIndex&&a.length>n.selectedIndex?(s=a.get(n.selectedIndex),e(s).addClass(i),s):null},selectHint:function(){var t=this,s=e.inArray(t.hint,t.suggestions);t.select(s)},select:function(e){var t=this;t.hide(),t.onSelect(e),t.disableKillerFn()},moveUp:function(){var t=this;if(-1!==t.selectedIndex)return 0===t.selectedIndex?(e(t.suggestionsContainer).children().first().removeClass(t.classes.selected),t.selectedIndex=-1,t.el.val(t.currentValue),void t.findBestHint()):void t.adjustScroll(t.selectedIndex-1)},moveDown:function(){var e=this;e.selectedIndex!==e.suggestions.length-1&&e.adjustScroll(e.selectedIndex+1)},adjustScroll:function(t){var s=this,n=s.activate(t);if(n){var i,o,a,l=e(n).outerHeight();i=n.offsetTop,a=(o=e(s.suggestionsContainer).scrollTop())+s.options.maxHeight-l,i<o?e(s.suggestionsContainer).scrollTop(i):i>a&&e(s.suggestionsContainer).scrollTop(i-s.options.maxHeight+l),s.options.preserveInput||s.el.val(s.getValue(s.suggestions[t].value)),s.signalHint(null)}},onSelect:function(t){var s=this,n=s.options.onSelect,i=s.suggestions[t];s.currentValue=s.getValue(i.value),s.currentValue===s.el.val()||s.options.preserveInput||s.el.val(s.currentValue),-1!=i.id&&(window.location.href=i.url),s.signalHint(null),s.suggestions=[],s.selection=i,e.isFunction(n)&&n.call(s.element,i)},onMouseOver:function(t){var s=this,n=s.options.onMouseOver,i=s.suggestions[t];s.selectedIndex!==t&&s.getDetails(i),e.isFunction(n)&&n.call(s.element,i)},onMouseLeave:function(t){var s=this,n=s.options.onMouseLeave,i=s.suggestions[t];e.isFunction(n)&&n.call(s.element,i)},getValue:function(e){var t,s,n=this,i=n.options.delimiter;return i?(t=n.currentValue,s=t.split(i),1===s.length?e:t.substr(0,t.length-s[s.length-1].length)+e):e},dispose:function(){var t=this;t.el.off(".autocomplete").removeData("autocomplete"),t.disableKillerFn(),e(window).off("resize.autocomplete",t.fixPositionCapture),e(t.suggestionsContainer).remove()}},e.fn.dgwtWcasAutocomplete=function(s,n){return arguments.length?this.each(function(){var i=e(this),o=i.data("autocomplete");"string"==typeof s?o&&"function"==typeof o[s]&&o[s](n):(o&&o.dispose&&o.dispose(),o=new t(this,s),i.data("autocomplete",o))}):this.first().data("autocomplete")},function(){e(document).ready(function(){e(".dgwt-wcas-search-submit").length>0&&e(".dgwt-wcas-preloader").css("right",e(".dgwt-wcas-search-submit").outerWidth()+"px");var t=1==dgwt_wcas.show_details_box;(jQuery(window).width()<992||"ontouchend"in document)&&(t=!1),e(".dgwt-wcas-search-input").dgwtWcasAutocomplete({minChars:dgwt_wcas.min_chars,width:dgwt_wcas.sug_width,autoSelectFirst:!1,triggerSelectOnValidInput:!1,serviceUrl:dgwt_wcas.ajax_search_endpoint,paramName:"dgwt_wcas_keyword",showDetailsPanel:t,showImage:1==dgwt_wcas.show_images,showPrice:1==dgwt_wcas.show_price,showDescription:1==dgwt_wcas.show_desc,showSKU:1==dgwt_wcas.show_sku,showSaleBadge:1==dgwt_wcas.show_sale_badge,showFeaturedBadge:1==dgwt_wcas.show_featured_badge,saleBadgeText:dgwt_wcas.t.sale_badge,featuredBadgeText:dgwt_wcas.t.featured_badge,cointainerDetailsPos:dgwt_wcas.details_box_pos,is_rtl:1==dgwt_wcas.is_rtl})})}()});
|
1 |
+
!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(e){"use strict";function t(s,n){var i=e.noop,o=this,a={ajaxSettings:{},autoSelectFirst:!1,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,onMouseOver:null,onMouseLeave:null,width:"auto",containerDetailsWidth:"auto",showDetailsPanel:!1,showImage:!1,showPrice:!1,showSKU:!1,showDescription:!1,showSaleBadge:!1,showFeaturedBadge:!1,saleBadgeText:"sale",featuredBadgeText:"featured",minChars:1,maxHeight:1e3,deferRequestBy:0,params:{},formatResult:t.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,is_rtl:!1,onSearchStart:i,onSearchComplete:i,onSearchError:i,preserveInput:!1,wrapperaClass:"dgwt-wcas-search-wrapp",containerClass:"dgwt-wcas-suggestions-wrapp",containerDetailsClass:"dgwt-wcas-details-wrapp",cointainerDetailsPos:"right",preloaderClass:"dgwt-wcas-preloader",closeTrigger:"dgwt-wcas-close",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:function(e,t,s){return-1!==e.value.toLowerCase().indexOf(s)},paramName:"query",transformResult:function(t){return"string"==typeof t?e.parseJSON(t):t},showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1};o.element=s,o.el=e(s),o.suggestions=[],o.badQueries=[],o.selectedIndex=-1,o.currentValue=o.element.value,o.intervalId=0,o.cachedResponse={},o.cachedDetails={},o.detailsRequestsSent=[],o.onChangeInterval=null,o.onChange=null,o.isLocal=!1,o.suggestionsContainer=null,o.detailsContainer=null,o.noSuggestionsContainer=null,o.options=e.extend({},a,n),o.classes={selected:"dgwt-wcas-suggestion-selected",suggestion:"dgwt-wcas-suggestion"},o.hint=null,o.hintValue="",o.selection=null,o.initialize(),o.setOptions(n)}var s=function(){return{escapeRegExChars:function(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},createNode:function(e){var t=document.createElement("div");return t.className=e,t.style.position="absolute",t.style.display="none",t}}}(),n={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40};t.utils=s,e.Autocomplete=t,t.formatResult=function(e,t){if(!t)return e;var n="("+s.escapeRegExChars(t)+")";return e.replace(new RegExp(n,"gi"),"<strong>$1</strong>").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/<(\/?strong)>/g,"<$1>")},t.prototype={killerFn:null,initialize:function(){var s,n=this,i="."+n.classes.suggestion,o=(n.classes.selected,n.options),a="."+o.closeTrigger;n.element.setAttribute("autocomplete","off"),n.killerFn=function(t){0===e(t.target).closest("."+n.options.containerClass).length&&0===e(t.target).closest("."+n.options.containerDetailsClass).length&&(n.killSuggestions(),n.disableKillerFn())},n.noSuggestionsContainer=e('<div class="dgwt-wcas-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),n.suggestionsContainer=t.utils.createNode(o.containerClass),(s=e(n.suggestionsContainer)).appendTo(n.el.closest("."+o.wrapperaClass)),!0===o.showImage&&s.addClass("dgwt-wcas-has-img"),!0===o.showPrice&&s.addClass("dgwt-wcas-has-price"),!0===o.showDescription&&s.addClass("dgwt-wcas-has-desc"),!0===o.showSKU&&s.addClass("dgwt-wcas-has-sku"),"auto"!==o.width&&s.width(o.width),!0===o.showDetailsPanel&&(n.detailsContainer=t.utils.createNode(o.containerDetailsClass),e(n.detailsContainer).appendTo(n.el.closest("."+o.wrapperaClass))),s.on("mouseover.autocomplete",i,function(){n.onMouseOver(e(this).data("index")),n.activate(e(this).data("index"))}),s.on("mouseout.autocomplete",function(){}),e(document).on("click.autocomplete",a,function(t){n.killerFn(t),n.clear(t),e(this).removeClass(o.closeTrigger),n.el.val("").focus()}),s.on("click.autocomplete",i,function(){return n.select(e(this).data("index")),!1}),n.fixPositionCapture=function(){n.visible&&n.fixPosition()},e(window).on("resize.autocomplete",n.fixPositionCapture),n.el.on("keydown.autocomplete",function(e){n.onKeyPress(e)}),n.el.on("keyup.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("blur.autocomplete",function(){n.onBlur()}),n.el.on("focus.autocomplete",function(){n.onFocus()}),n.el.on("change.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("input.autocomplete",function(e){n.onKeyUp(e)})},onFocus:function(){var e=this;e.fixPosition(),e.el.val().length>=e.options.minChars&&e.onValueChange()},onBlur:function(){this.enableKillerFn()},abortAjax:function(){var e=this;e.currentRequest&&(e.currentRequest.abort(),e.currentRequest=null)},setOptions:function(t){var s=this,n=s.options;e.extend(n,t),s.isLocal=e.isArray(n.lookup),s.isLocal&&(n.lookup=s.verifySuggestionsFormat(n.lookup)),n.orientation=s.validateOrientation(n.orientation,"bottom"),e(s.suggestionsContainer).css({"max-height":n.maxHeight+"px",width:n.width+"px","z-index":n.zIndex}),!0===n.showDetailsPanel&&jQuery(s.suggestionsContainer).parent().addClass("dgwt-wcas-is-details"),s.options.onSearchComplete=function(){s.preloader("hide",e("."+n.preloaderClass),"dgwt-wcas-inner-preloader"),s.preloader("show",e("."+n.preloaderClass),n.closeTrigger)}},clearCache:function(){this.cachedResponse={},this.cachedDetails={},this.badQueries=[]},clear:function(){this.clearCache(),this.currentValue="",this.suggestions=[]},disable:function(){var e=this;e.disabled=!0,clearInterval(e.onChangeInterval),e.abortAjax()},enable:function(){this.disabled=!1},fixPosition:function(){var t=this,s=(t.options,e(t.suggestionsContainer)),n=(e(t.detailsContainer),s.parent().get(0));if(n===document.body||t.options.forceFixPosition){var i=t.options.orientation,o=s.outerHeight(),a=t.el.outerHeight(),l=t.el.offset(),r={top:l.top,left:l.left};if("auto"===i){var u=e(window).height(),c=e(window).scrollTop(),d=-c+l.top-o,g=c+u-(l.top+a+o);i=Math.max(d,g)===d?"top":"bottom"}if(r.top+="top"===i?-o:a,n!==document.body){var h,p=s.css("opacity");t.visible||s.css("opacity",0).show(),h=s.offsetParent().offset(),r.top-=h.top,r.left-=h.left,t.visible||s.css("opacity",p).hide()}"auto"===t.options.width&&(r.width=t.el.outerWidth()-2+"px"),s.css(r)}},fixPositionDetailsBox:function(){var t=e(this.detailsContainer);if(0==t.length)return!1;var s=e(window).width(),n=t.parent(),i=t.prev(),o=t.width(),a=t.offset();n.width()>=550||(s<a.left+o&&(n.removeClass("dgwt-wcas-details-right"),n.addClass("dgwt-wcas-details-left"),t.css("left","-"+t.outerWidth()+"px")),a.left<1&&(n.removeClass("dgwt-wcas-details-left"),n.addClass("dgwt-wcas-details-right"),t.css("left",i.outerWidth()+"px")))},fixHeight:function(t,s){var n=this,i=n.options;if(1!=i.showDetailsPanel)return!1;var s,o=e("."+i.containerClass),a=e("."+i.containerDetailsClass),l=0,r=0;e("."+i.containerClass+"> *").each(function(){l+=e(this).outerHeight()}),e("."+i.containerDetailsClass+"> *").each(function(){r+=e(this).outerHeight()}),((s=l>=r?l:r)>l||s>r)&&(o.css("height",s+"px"),a.css("height",s+"px")),void 0===t&&(t=0),t<5?setTimeout(function(){n.fixHeight(t+1,s)},30):t=0},enableKillerFn:function(){var t=this;e(document).on("click.autocomplete",t.killerFn)},disableKillerFn:function(){var t=this;e(document).off("click.autocomplete",t.killerFn)},killSuggestions:function(){var t=this,s=e(t.suggestionsContainer).parent();t.stopKillSuggestions(),t.intervalId=window.setInterval(function(){t.visible&&(t.options.preserveInput||t.el.val(t.currentValue),t.hide(),s.removeClass("dgwt-wcas-open")),t.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var e,t=this,s=t.el.val().length,n=t.element.selectionStart;return"number"==typeof n?n===s:!document.selection||((e=document.selection.createRange()).moveStart("character",-s),s===e.text.length)},onKeyPress:function(e){var t=this;if(t.disabled||t.visible||e.which!==n.DOWN||!t.currentValue){if(!t.disabled&&t.visible){switch(e.which){case n.ESC:t.el.val(t.currentValue),t.hide();break;case n.RIGHT:if(t.hint&&t.options.onHint&&t.isCursorAtEnd()){t.selectHint();break}return;case n.TAB:if(t.hint&&t.options.onHint)return void t.selectHint();if(-1===t.selectedIndex)return void t.hide();if(t.select(t.selectedIndex),!1===t.options.tabDisabled)return;break;case n.RETURN:if(-1===t.selectedIndex)return void t.hide();t.select(t.selectedIndex);break;case n.UP:t.moveUp();break;case n.DOWN:t.moveDown();break;default:return}e.stopImmediatePropagation(),e.preventDefault()}}else t.suggest()},onKeyUp:function(e){var t=this;if(!t.disabled){switch(e.which){case n.UP:case n.DOWN:return}clearInterval(t.onChangeInterval),t.currentValue!==t.el.val()&&(t.findBestHint(),t.options.deferRequestBy>0?t.onChangeInterval=setInterval(function(){t.onValueChange()},t.options.deferRequestBy):t.onValueChange())}},onValueChange:function(){var t=this,s=t.options,n=t.el.val(),i=t.getQuery(n);t.selection&&t.currentValue!==i&&(t.selection=null,(s.onInvalidateSelection||e.noop).call(t.element)),clearInterval(t.onChangeInterval),t.currentValue=n,t.selectedIndex=-1,s.triggerSelectOnValidInput&&t.isExactMatch(i)?t.select(0):i.length<s.minChars?(e("."+t.options.closeTrigger).removeClass(t.options.closeTrigger),t.hide()):t.getSuggestions(i)},isExactMatch:function(e){var t=this.suggestions;return 1===t.length&&t[0].value.toLowerCase()===e.toLowerCase()},getQuery:function(t){var s,n=this.options.delimiter;return n?(s=t.split(n),e.trim(s[s.length-1])):t},getSuggestionsLocal:function(t){var s,n=this.options,i=t.toLowerCase(),o=n.lookupFilter,a=parseInt(n.lookupLimit,10);return s={suggestions:e.grep(n.lookup,function(e){return o(e,t,i)})},a&&s.suggestions.length>a&&(s.suggestions=s.suggestions.slice(0,a)),s},getSuggestions:function(t){var s,n,i,o,a=this,l=a.options,r=l.serviceUrl;l.params[l.paramName]=t,n=l.ignoreParams?null:l.params,a.preloader("show",e("."+l.preloaderClass),"dgwt-wcas-inner-preloader"),!1!==l.onSearchStart.call(a.element,l.params)&&(e.isFunction(l.lookup)?l.lookup(t,function(e){a.suggestions=e.suggestions,a.suggest(),a.getDetails(e.suggestions[0]),l.onSearchComplete.call(a.element,t,e.suggestions)}):(a.isLocal?s=a.getSuggestionsLocal(t):(e.isFunction(r)&&(r=r.call(a.element,t)),i=r+"?"+e.param(n||{}),s=a.cachedResponse[i]),s&&e.isArray(s.suggestions)?(a.suggestions=s.suggestions,a.suggest(),a.getDetails(s.suggestions[0]),l.onSearchComplete.call(a.element,t,s.suggestions)):a.isBadQuery(t)?l.onSearchComplete.call(a.element,t,[]):(a.abortAjax(),o={url:r,data:n,type:l.type,dataType:l.dataType},e.extend(o,l.ajaxSettings),a.currentRequest=e.ajax(o).done(function(e){var s;a.currentRequest=null,void 0!==(s=l.transformResult(e,t)).suggestions&&(a.processResponse(s,t,i),a.getDetails(s.suggestions[0])),l.onSearchComplete.call(a.element,t,s.suggestions)}).fail(function(e,s,n){l.onSearchError.call(a.element,t,e,s,n)}))))},getDetails:function(t){var s=this,n=s.options;if(1!=n.showDetailsPanel||e(window).width()<992||"ontouchend"in document)return!1;if(null!=t){var i,o,a=e("."+n.containerDetailsClass);s.fixHeight();var l={action:dgwt_wcas.action_result_details,post_id:null!=t.post_id?t.post_id:0,term_id:null!=t.term_id?t.term_id:0,taxonomy:null!=t.taxonomy?t.taxonomy:"",value:null!=t.value?t.value:""};if(i=l.action+l.post_id+l.term_id+l.taxonomy,null!=(o=s.cachedDetails[i]))a.html(o.details),s.fixHeight(),s.fixPositionDetailsBox();else{if(a.html(""),s.preloader("show",a,"",!0),-1!=e.inArray(i,s.detailsRequestsSent))return;s.detailsRequestsSent.push(i),e.ajax({data:l,type:"post",url:dgwt_wcas.ajax_details_endpoint,success:function(e){var t="string"==typeof e?jQuery.parseJSON(e):e;s.cachedDetails[i]=t,s.preloader("hide",a,"",!0),null!=t.details?a.html(t.details):a.html(""),s.fixPositionDetailsBox(),s.fixHeight()},error:function(e,t){s.preloader("hide",a,"",!0),a.html(e),s.fixPositionDetailsBox(),s.fixHeight()}})}}},isBadQuery:function(e){if(!this.options.preventBadQueries)return!1;for(var t=this.badQueries,s=t.length;s--;)if(0===e.indexOf(t[s]))return!0;return!1},hide:function(){var t=this,s=e(t.suggestionsContainer);e(t.detailsContainer);e.isFunction(t.options.onHide)&&t.visible&&t.options.onHide.call(t.element,s),t.visible=!1,t.selectedIndex=-1,clearInterval(t.onChangeInterval),e(t.suggestionsContainer).hide(),e(t.detailsContainer).hide(),t.signalHint(null)},suggest:function(){if(this.suggestions.length){var t,s=this,n=s.options,i=n.groupBy,o=n.formatResult,a=s.getQuery(s.currentValue),l=s.classes.suggestion,r=s.classes.selected,u=e(s.suggestionsContainer),c=e(s.detailsContainer),d=e(s.noSuggestionsContainer),g=n.beforeRender,h="",p=function(e,s){var n=e.data[i];return t===n?"":'<div class="autocomplete-group"><strong>'+(t=n)+"</strong></div>"};n.triggerSelectOnValidInput&&s.isExactMatch(a)?s.select(0):(e.each(s.suggestions,function(e,t){var s="",r="",u=!1;i&&(h+=p(t,0)),void 0===t.post_id?(h+='<div class="'+l+' dgwt-wcas-nores" data-index="'+e+'">',h+='<span class="dgwt-wcas-st">'+t.value+"</span>",h+="</div>"):(void 0!==t.parents&&(s=t.parents),!0===n.showImage&&void 0!==t.thumb_html&&(u=!0),r+=void 0!==t.post_id?'data-post-id="'+t.post_id+'" ':"",r+=void 0!==t.taxonomy?'data-taxonomy="'+t.taxonomy+'" ':"",r+=void 0!==t.term_id?'data-term-id="'+t.term_id+'" ':"",h+='<div class="'+l+'" data-index="'+e+'" '+r+">",u&&(h+='<span class="dgwt-wcas-si">'+t.thumb_html+"</span>"),h+=u?'<div class="dgwt-wcas-content-wrapp">':"",h+='<span class="dgwt-wcas-st">',h+="<span>"+o(t.value,a)+s+"</span>",!0===n.showSKU&&void 0!==t.sku&&t.sku.length>0&&(h+='<span class="dgwt-wcas-sku">(SKU: '+o(t.sku,a)+")</span>"),h+="</span>",!0===n.showPrice&&void 0!==t.price&&(h+='<span class="dgwt-wcas-sp">'+t.price+"</span>"),!0===n.showDescription&&void 0!==t.desc&&(h+='<span class="dgwt-wcas-sd">'+o(t.desc,a)+"</span>"),!0===n.showFeaturedBadge&&!0===t.on_sale&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-os">'+n.saleBadgeText+"</span>"),!0===n.showFeaturedBadge&&!0===t.featured&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-f">'+n.featuredBadgeText+"</span>"),h+=u?"</div>":"",h+="</div>")}),this.adjustContainerWidth(),d.detach(),u.html(h),e.isFunction(g)&&g.call(s.element,u,s.suggestions),s.fixPosition(),u.show(),u.parent().addClass("dgwt-wcas-open"),!0===n.showDetailsPanel&&c.show(),n.autoSelectFirst&&(s.selectedIndex=0,u.scrollTop(0),u.children("."+l).first().addClass(r)),s.visible=!0,s.findBestHint())}else this.options.showNoSuggestionNotice?this.noSuggestions():this.hide()},noSuggestions:function(){var t=this,s=e(t.suggestionsContainer),n=e(t.noSuggestionsContainer);this.adjustContainerWidth(),n.detach(),s.empty(),s.append(n),t.fixPosition(),s.show(),t.visible=!0},adjustContainerWidth:function(){var t,s=this,n=s.options,i=e(s.suggestionsContainer).parent(),o=e(s.suggestionsContainer),a=e(s.detailsContainer);if("auto"===n.width&&(t=s.el.outerWidth(),o.css("width",t+"px")),i.width()>=550&&!0===n.showDetailsPanel)return i.addClass("dgwt-wcas-full-width"),o.outerWidth(300),a.innerWidth(i.width()-300),i.removeClass("dgwt-wcas-details-left"),i.removeClass("dgwt-wcas-details-right"),void(!0===n.is_rtl?(a.css("left","0"),o.css("right","0")):(a.css("right","0"),o.css("left","0")));"left"===n.cointainerDetailsPos?(a.parent().addClass("dgwt-wcas-details-left"),a.css("left","-"+a.outerWidth()+"px")):(a.parent().addClass("dgwt-wcas-details-right"),a.css("left",i.outerWidth()+"px"))},findBestHint:function(){var t=this,s=t.el.val().toLowerCase(),n=null;s&&(e.each(t.suggestions,function(e,t){var i=0===t.value.toLowerCase().indexOf(s);return i&&(n=t),!i}),t.signalHint(n))},signalHint:function(t){var s="",n=this;t&&(s=n.currentValue+t.value.substr(n.currentValue.length)),n.hintValue!==s&&(n.hintValue=s,n.hint=t,(this.options.onHint||e.noop)(s))},preloader:function(t,s,n,i){var o,a="dgwt-wcas-preloader-wrapp",l=null==n?a:a+" "+n;1==dgwt_wcas.show_preloader&&0!=s.length&&(!0===i?"hide"!==t?"show"===t&&(o='<div class="'+l+'"><div class="dgwt-wcas-default-preloader"></div></div>',s.html(o)):e(a).remove():"hide"===t?s.removeClass(n):s.addClass(n))},verifySuggestionsFormat:function(t){return t.length&&"string"==typeof t[0]?e.map(t,function(e){return{value:e,data:null}}):t},validateOrientation:function(t,s){return t=e.trim(t||"").toLowerCase(),-1===e.inArray(t,["auto","bottom","top"])&&(t=s),t},processResponse:function(e,t,s){var n=this,i=n.options;e.suggestions=n.verifySuggestionsFormat(e.suggestions),i.noCache||(n.cachedResponse[s]=e,i.preventBadQueries&&!e.suggestions.length&&n.badQueries.push(t)),t===n.getQuery(n.currentValue)&&(n.suggestions=e.suggestions,n.suggest())},activate:function(t){var s,n=this,i=n.classes.selected,o=e(n.suggestionsContainer),a=o.find("."+n.classes.suggestion);return o.find("."+i).removeClass(i),n.selectedIndex=t,-1!==n.selectedIndex&&a.length>n.selectedIndex?(s=a.get(n.selectedIndex),e(s).addClass(i),s):null},selectHint:function(){var t=this,s=e.inArray(t.hint,t.suggestions);t.select(s)},select:function(e){var t=this;t.hide(),t.onSelect(e),t.disableKillerFn()},moveUp:function(){var t=this;if(-1!==t.selectedIndex)return 0===t.selectedIndex?(e(t.suggestionsContainer).children().first().removeClass(t.classes.selected),t.selectedIndex=-1,t.el.val(t.currentValue),void t.findBestHint()):void t.adjustScroll(t.selectedIndex-1)},moveDown:function(){var e=this;e.selectedIndex!==e.suggestions.length-1&&e.adjustScroll(e.selectedIndex+1)},adjustScroll:function(t){var s=this,n=s.activate(t);if(n){var i,o,a,l=e(n).outerHeight();i=n.offsetTop,a=(o=e(s.suggestionsContainer).scrollTop())+s.options.maxHeight-l,i<o?e(s.suggestionsContainer).scrollTop(i):i>a&&e(s.suggestionsContainer).scrollTop(i-s.options.maxHeight+l),s.options.preserveInput||s.el.val(s.getValue(s.suggestions[t].value)),s.signalHint(null)}},onSelect:function(t){var s=this,n=s.options.onSelect,i=s.suggestions[t];s.currentValue=s.getValue(i.value),s.currentValue===s.el.val()||s.options.preserveInput||s.el.val(s.currentValue),-1!=i.id&&(window.location.href=i.url),s.signalHint(null),s.suggestions=[],s.selection=i,e.isFunction(n)&&n.call(s.element,i)},onMouseOver:function(t){var s=this,n=s.options.onMouseOver,i=s.suggestions[t];s.selectedIndex!==t&&s.getDetails(i),e.isFunction(n)&&n.call(s.element,i)},onMouseLeave:function(t){var s=this,n=s.options.onMouseLeave,i=s.suggestions[t];e.isFunction(n)&&n.call(s.element,i)},getValue:function(e){var t,s,n=this,i=n.options.delimiter;return i?(t=n.currentValue,s=t.split(i),1===s.length?e:t.substr(0,t.length-s[s.length-1].length)+e):e},dispose:function(){var t=this;t.el.off(".autocomplete").removeData("autocomplete"),t.disableKillerFn(),e(window).off("resize.autocomplete",t.fixPositionCapture),e(t.suggestionsContainer).remove()}},e.fn.dgwtWcasAutocomplete=function(s,n){return arguments.length?this.each(function(){var i=e(this),o=i.data("autocomplete");"string"==typeof s?o&&"function"==typeof o[s]&&o[s](n):(o&&o.dispose&&o.dispose(),o=new t(this,s),i.data("autocomplete",o))}):this.first().data("autocomplete")},function(){e(document).ready(function(){e(".dgwt-wcas-search-submit").length>0&&e(".dgwt-wcas-preloader").css("right",e(".dgwt-wcas-search-submit").outerWidth()+"px");var t=1==dgwt_wcas.show_details_box;(jQuery(window).width()<992||"ontouchend"in document)&&(t=!1),e(".dgwt-wcas-search-input").dgwtWcasAutocomplete({minChars:dgwt_wcas.min_chars,width:dgwt_wcas.sug_width,autoSelectFirst:!1,triggerSelectOnValidInput:!1,serviceUrl:dgwt_wcas.ajax_search_endpoint,paramName:"dgwt_wcas_keyword",showDetailsPanel:t,showImage:1==dgwt_wcas.show_images,showPrice:1==dgwt_wcas.show_price,showDescription:1==dgwt_wcas.show_desc,showSKU:1==dgwt_wcas.show_sku,showSaleBadge:1==dgwt_wcas.show_sale_badge,showFeaturedBadge:1==dgwt_wcas.show_featured_badge,saleBadgeText:dgwt_wcas.t.sale_badge,featuredBadgeText:dgwt_wcas.t.featured_badge,cointainerDetailsPos:dgwt_wcas.details_box_pos,is_rtl:1==dgwt_wcas.is_rtl})})}()});
|
includes/class-result-details.php
CHANGED
@@ -34,7 +34,7 @@ class DGWT_WCAS_Result_Details {
|
|
34 |
}
|
35 |
|
36 |
// Get product details
|
37 |
-
if (
|
38 |
|
39 |
$product_id = absint( $_REQUEST[ 'post_id' ] );
|
40 |
if ( DGWT_WCAS_WOO_PRODUCT_POST_TYPE === get_post_type( $product_id ) ) {
|
34 |
}
|
35 |
|
36 |
// Get product details
|
37 |
+
if ( !empty( $_REQUEST[ 'post_id' ] ) && is_numeric( $_REQUEST[ 'post_id' ] ) ) {
|
38 |
|
39 |
$product_id = absint( $_REQUEST[ 'post_id' ] );
|
40 |
if ( DGWT_WCAS_WOO_PRODUCT_POST_TYPE === get_post_type( $product_id ) ) {
|
includes/class-search.php
CHANGED
@@ -1,485 +1,531 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Exit if accessed directly
|
4 |
-
if ( !defined( 'ABSPATH' ) ) {
|
5 |
-
exit;
|
6 |
-
}
|
7 |
-
|
8 |
-
class DGWT_WCAS_Search {
|
9 |
-
/*
|
10 |
-
* Suggestions limit
|
11 |
-
* int
|
12 |
-
*/
|
13 |
-
|
14 |
-
private $limit;
|
15 |
-
|
16 |
-
/*
|
17 |
-
* Description limit
|
18 |
-
* int
|
19 |
-
*/
|
20 |
-
private $desc_limit = 130;
|
21 |
-
|
22 |
-
/*
|
23 |
-
* Empty slots
|
24 |
-
* int
|
25 |
-
*/
|
26 |
-
private $slots;
|
27 |
-
|
28 |
-
function __construct() {
|
29 |
-
|
30 |
-
$this->limit = absint( DGWT_WCAS()->settings->get_opt( 'suggestions_limit', 10 ) );
|
31 |
-
$this->slots = $this->limit; // Free slots for the results. Default 10
|
32 |
-
|
33 |
-
add_filter( 'posts_search', array( $this, 'search_filters' ), 501, 2 );
|
34 |
-
add_filter(
|
35 |
-
add_filter( '
|
36 |
-
add_filter( 'pre_get_posts', array( $this, '
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
add_action( '
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
$
|
60 |
-
$
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
'
|
96 |
-
'
|
97 |
-
'
|
98 |
-
'
|
99 |
-
'
|
100 |
-
'
|
101 |
-
'
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
'
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
*
|
223 |
-
*
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
$
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
'
|
250 |
-
'
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
*
|
275 |
-
*
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
$
|
290 |
-
|
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 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
$search .= "
|
370 |
-
|
371 |
-
// Search in
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Exit if accessed directly
|
4 |
+
if ( !defined( 'ABSPATH' ) ) {
|
5 |
+
exit;
|
6 |
+
}
|
7 |
+
|
8 |
+
class DGWT_WCAS_Search {
|
9 |
+
/*
|
10 |
+
* Suggestions limit
|
11 |
+
* int
|
12 |
+
*/
|
13 |
+
|
14 |
+
private $limit;
|
15 |
+
|
16 |
+
/*
|
17 |
+
* Description limit
|
18 |
+
* int
|
19 |
+
*/
|
20 |
+
private $desc_limit = 130;
|
21 |
+
|
22 |
+
/*
|
23 |
+
* Empty slots
|
24 |
+
* int
|
25 |
+
*/
|
26 |
+
private $slots;
|
27 |
+
|
28 |
+
function __construct() {
|
29 |
+
|
30 |
+
$this->limit = absint( DGWT_WCAS()->settings->get_opt( 'suggestions_limit', 10 ) );
|
31 |
+
$this->slots = $this->limit; // Free slots for the results. Default 10
|
32 |
+
|
33 |
+
add_filter( 'posts_search', array( $this, 'search_filters' ), 501, 2 );
|
34 |
+
add_filter('posts_distinct', array($this, 'search_distinct'), 501, 2);
|
35 |
+
add_filter( 'posts_join', array( $this, 'search_filters_join' ), 501, 2 );
|
36 |
+
add_filter( 'pre_get_posts', array( $this, 'change_wp_search_size' ), 500 );
|
37 |
+
add_filter( 'pre_get_posts', array( $this, 'set_search_results_query' ), 501 );
|
38 |
+
|
39 |
+
// Search results ajax action
|
40 |
+
if ( DGWT_WCAS_WC_AJAX_ENDPOINT ) {
|
41 |
+
add_action( 'wc_ajax_' . DGWT_WCAS_SEARCH_ACTION, array( $this, 'get_search_results' ) );
|
42 |
+
} else {
|
43 |
+
add_action( 'wp_ajax_nopriv_' . DGWT_WCAS_SEARCH_ACTION, array( $this, 'get_search_results' ) );
|
44 |
+
add_action( 'wp_ajax_' . DGWT_WCAS_SEARCH_ACTION, array( $this, 'get_search_results' ) );
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
/*
|
49 |
+
* Get search results via ajax
|
50 |
+
*/
|
51 |
+
|
52 |
+
public function get_search_results() {
|
53 |
+
global $woocommerce;
|
54 |
+
|
55 |
+
if ( !defined( 'DGWT_WCAS_AJAX' ) ) {
|
56 |
+
define( 'DGWT_WCAS_AJAX', true );
|
57 |
+
}
|
58 |
+
|
59 |
+
$output = array();
|
60 |
+
$results = array();
|
61 |
+
$keyword = sanitize_text_field( $_REQUEST[ 'dgwt_wcas_keyword' ] );
|
62 |
+
|
63 |
+
|
64 |
+
//@todo Get results from cache
|
65 |
+
|
66 |
+
/* SEARCH IN WOO CATEGORIES */
|
67 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_matching_categories' ) === 'on' ) {
|
68 |
+
|
69 |
+
$results = array_merge( $this->get_categories( $keyword ), $results );
|
70 |
+
|
71 |
+
// Update slots
|
72 |
+
$this->slots = $this->slots - count( $results );
|
73 |
+
} /* END SEARCH IN WOO CATEGORIES */
|
74 |
+
|
75 |
+
|
76 |
+
/* SEARCH IN WOO TAGS */
|
77 |
+
if ( $this->slots > 0 ) {
|
78 |
+
|
79 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_matching_tags' ) === 'on' ) {
|
80 |
+
|
81 |
+
$results = array_merge( $this->get_tags( $keyword ), $results );
|
82 |
+
|
83 |
+
// Update slots
|
84 |
+
$this->slots = $this->slots - count( $results );
|
85 |
+
}
|
86 |
+
}/* END SEARCH IN WOO TAGS */
|
87 |
+
|
88 |
+
|
89 |
+
// Continue searching in products if there are room in the slots
|
90 |
+
/* SEARCH IN PRODUCTS */
|
91 |
+
if ( $this->slots > 0 ) {
|
92 |
+
$ordering_args = $woocommerce->query->get_catalog_ordering_args( 'title', 'asc' );
|
93 |
+
|
94 |
+
$args = array(
|
95 |
+
's' => $keyword,
|
96 |
+
'post_type' => DGWT_WCAS_WOO_PRODUCT_POST_TYPE,
|
97 |
+
'post_status' => 'publish',
|
98 |
+
'ignore_sticky_posts' => 1,
|
99 |
+
'orderby' => $ordering_args[ 'orderby' ],
|
100 |
+
'order' => $ordering_args[ 'order' ],
|
101 |
+
'suppress_filters' => false,
|
102 |
+
'meta_query' => $this->get_meta_query()
|
103 |
+
);
|
104 |
+
|
105 |
+
$args = apply_filters('dgwt_wcas_products_args', $args);
|
106 |
+
|
107 |
+
$products = get_posts( $args );
|
108 |
+
|
109 |
+
if ( !empty( $products ) ) {
|
110 |
+
|
111 |
+
foreach ( $products as $post ) {
|
112 |
+
$product = wc_get_product( $post );
|
113 |
+
|
114 |
+
$r = array(
|
115 |
+
'post_id' => $product->get_id(),
|
116 |
+
'value' => strip_tags( $product->get_title() ),
|
117 |
+
'url' => $product->get_permalink(),
|
118 |
+
);
|
119 |
+
|
120 |
+
// Get thumb HTML
|
121 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_product_image' ) === 'on' ) {
|
122 |
+
$r[ 'thumb_html' ] = $product->get_image( array( 60, 60 ) );
|
123 |
+
}
|
124 |
+
|
125 |
+
// Get price
|
126 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_product_price' ) === 'on' ) {
|
127 |
+
$r[ 'price' ] = $product->get_price_html();
|
128 |
+
}
|
129 |
+
|
130 |
+
// Get description
|
131 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_product_desc' ) === 'on' ) {
|
132 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_details_box' ) === 'on' ) {
|
133 |
+
$this->desc_limit = 60;
|
134 |
+
}
|
135 |
+
$r[ 'desc' ] = dgwt_wcas_get_product_desc( $product->get_id(), $this->desc_limit );
|
136 |
+
}
|
137 |
+
|
138 |
+
// Get SKU
|
139 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_product_sku' ) === 'on' ) {
|
140 |
+
$r[ 'sku' ] = $product->get_sku();
|
141 |
+
}
|
142 |
+
|
143 |
+
// Is on sale
|
144 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_sale_badge' ) === 'on' ) {
|
145 |
+
$r[ 'on_sale' ] = $product->is_on_sale();
|
146 |
+
}
|
147 |
+
|
148 |
+
// Is featured
|
149 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_featured_badge' ) === 'on' ) {
|
150 |
+
$r[ 'featured' ] = $product->is_featured();
|
151 |
+
}
|
152 |
+
|
153 |
+
$results[] = apply_filters( 'dgwt_wcas_products_suggestions', $r, $product );
|
154 |
+
}
|
155 |
+
}
|
156 |
+
wp_reset_postdata();
|
157 |
+
} /* END SEARCH IN PRODUCTS */
|
158 |
+
|
159 |
+
|
160 |
+
|
161 |
+
// Show nothing on empty results
|
162 |
+
//@todo show 'No results' as option
|
163 |
+
if ( empty( $results ) ) {
|
164 |
+
|
165 |
+
$results[] = array(
|
166 |
+
'value' => __( 'No results', 'ajax-search-for-woocommerce' ),
|
167 |
+
);
|
168 |
+
}
|
169 |
+
|
170 |
+
//@todo Add results to the wp cache
|
171 |
+
|
172 |
+
$output[ 'suggestions' ] = $results;
|
173 |
+
|
174 |
+
echo json_encode( $output );
|
175 |
+
die();
|
176 |
+
}
|
177 |
+
|
178 |
+
/*
|
179 |
+
* Get meta query
|
180 |
+
*
|
181 |
+
* return array
|
182 |
+
*/
|
183 |
+
|
184 |
+
private function get_meta_query() {
|
185 |
+
|
186 |
+
$meta_query = array();
|
187 |
+
|
188 |
+
// Backward compatibility WC < 3.0
|
189 |
+
if ( dgwt_wcas_compare_wc_version( '3.0', '<' ) ) {
|
190 |
+
$meta_query = array(
|
191 |
+
'relation' => 'AND',
|
192 |
+
1 => array(
|
193 |
+
'key' => '_visibility',
|
194 |
+
'value' => array( 'search', 'visible' ),
|
195 |
+
'compare' => 'IN'
|
196 |
+
),
|
197 |
+
2 => array(
|
198 |
+
'relation' => 'OR',
|
199 |
+
array(
|
200 |
+
'key' => '_visibility',
|
201 |
+
'value' => array( 'search', 'visible' ),
|
202 |
+
'compare' => 'IN'
|
203 |
+
)
|
204 |
+
)
|
205 |
+
);
|
206 |
+
}
|
207 |
+
|
208 |
+
|
209 |
+
// Exclude out of stock products from suggestions
|
210 |
+
if ( DGWT_WCAS()->settings->get_opt( 'exclude_out_of_stock' ) === 'on' ) {
|
211 |
+
$meta_query[] = array(
|
212 |
+
'key' => '_stock_status',
|
213 |
+
'value' => 'outofstock',
|
214 |
+
'compare' => 'NOT IN'
|
215 |
+
);
|
216 |
+
};
|
217 |
+
|
218 |
+
return $meta_query;
|
219 |
+
}
|
220 |
+
|
221 |
+
/*
|
222 |
+
* Search for matching category
|
223 |
+
*
|
224 |
+
* @param string $keyword
|
225 |
+
*
|
226 |
+
* @return array
|
227 |
+
*/
|
228 |
+
|
229 |
+
public function get_categories( $keyword ) {
|
230 |
+
|
231 |
+
$results = array();
|
232 |
+
|
233 |
+
$args = array(
|
234 |
+
'taxonomy' => DGWT_WCAS_WOO_PRODUCT_CATEGORY
|
235 |
+
);
|
236 |
+
|
237 |
+
$product_categories = get_terms( DGWT_WCAS_WOO_PRODUCT_CATEGORY, $args );
|
238 |
+
|
239 |
+
// Compare keyword and term name
|
240 |
+
$i = 0;
|
241 |
+
foreach ( $product_categories as $cat ) {
|
242 |
+
|
243 |
+
if ( $i < $this->limit ) {
|
244 |
+
|
245 |
+
$pos = strpos( strtolower( $cat->name ), strtolower( $keyword ) );
|
246 |
+
|
247 |
+
if ( $pos !== false ) {
|
248 |
+
$results[ $i ] = array(
|
249 |
+
'term_id' => $cat->term_id,
|
250 |
+
'taxonomy' => DGWT_WCAS_WOO_PRODUCT_CATEGORY,
|
251 |
+
'value' => preg_replace( sprintf( "/(%s)/", $keyword ), "$1", $cat->name ),
|
252 |
+
'url' => get_term_link( $cat, DGWT_WCAS_WOO_PRODUCT_CATEGORY ),
|
253 |
+
'parents' => ''
|
254 |
+
);
|
255 |
+
|
256 |
+
|
257 |
+
// Add category parents info
|
258 |
+
$parents = $this->get_taxonomy_parent_string( $cat->term_id, DGWT_WCAS_WOO_PRODUCT_CATEGORY, array(), array( $cat->term_id ) );
|
259 |
+
|
260 |
+
if ( !empty( $parents ) ) {
|
261 |
+
|
262 |
+
$results[ $i ][ 'parents' ] = sprintf( ' <em>%s <b>%s</b></em>', __( 'in', 'ajax-search-for-woocommerce' ), mb_substr( $parents, 0, -3 ) );
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
$i++;
|
268 |
+
}
|
269 |
+
|
270 |
+
return $results;
|
271 |
+
}
|
272 |
+
|
273 |
+
/*
|
274 |
+
* Extend research in the Woo tags
|
275 |
+
*
|
276 |
+
* @param strong $keyword
|
277 |
+
*
|
278 |
+
* @return array
|
279 |
+
*/
|
280 |
+
|
281 |
+
public function get_tags( $keyword ) {
|
282 |
+
|
283 |
+
$results = array();
|
284 |
+
|
285 |
+
$args = array(
|
286 |
+
'taxonomy' => DGWT_WCAS_WOO_PRODUCT_TAG
|
287 |
+
);
|
288 |
+
|
289 |
+
$product_tags = get_terms( DGWT_WCAS_WOO_PRODUCT_TAG, $args );
|
290 |
+
|
291 |
+
// Compare keyword and term name
|
292 |
+
$i = 0;
|
293 |
+
foreach ( $product_tags as $tag ) {
|
294 |
+
|
295 |
+
if ( $i < $this->limit ) {
|
296 |
+
|
297 |
+
$pos = strpos( strtolower( $tag->name ), strtolower( $keyword ) );
|
298 |
+
|
299 |
+
if ( $pos !== false ) {
|
300 |
+
$results[ $i ] = array(
|
301 |
+
'term_id' => $tag->term_id,
|
302 |
+
'taxonomy' => DGWT_WCAS_WOO_PRODUCT_TAG,
|
303 |
+
'value' => preg_replace( sprintf( "/(%s)/", $keyword ), "$1", $tag->name ),
|
304 |
+
'url' => get_term_link( $tag, DGWT_WCAS_WOO_PRODUCT_TAG ),
|
305 |
+
'parents' => ''
|
306 |
+
);
|
307 |
+
|
308 |
+
// Add taxonomy parents info
|
309 |
+
$parents = $this->get_taxonomy_parent_string( $tag->term_id, DGWT_WCAS_WOO_PRODUCT_TAG, array(), array( $tag->term_id ) );
|
310 |
+
|
311 |
+
if ( !empty( $parents ) ) {
|
312 |
+
|
313 |
+
$results[ $i ][ 'parents' ] = sprintf( ' <em>%s <b>%s</b></em>', __( 'in', 'ajax-search-for-woocommerce' ), mb_substr( $parents, 0, -3 ) );
|
314 |
+
}
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
$i++;
|
319 |
+
}
|
320 |
+
|
321 |
+
return $results;
|
322 |
+
}
|
323 |
+
|
324 |
+
/*
|
325 |
+
* Set search product limit
|
326 |
+
*/
|
327 |
+
|
328 |
+
public function change_wp_search_size( $query ) {
|
329 |
+
|
330 |
+
if ( $this->is_ajax_search() ) {
|
331 |
+
if ( $query->is_search )
|
332 |
+
$query->query_vars[ 'posts_per_page' ] = $this->slots;
|
333 |
+
}
|
334 |
+
|
335 |
+
return $query;
|
336 |
+
}
|
337 |
+
|
338 |
+
/*
|
339 |
+
* Search only in products titles
|
340 |
+
*
|
341 |
+
* @param string $search SQL
|
342 |
+
*
|
343 |
+
* @return string prepared SQL
|
344 |
+
*/
|
345 |
+
|
346 |
+
public function search_filters( $search, $wp_query ) {
|
347 |
+
global $wpdb;
|
348 |
+
|
349 |
+
if ( empty( $search ) || is_admin() ) {
|
350 |
+
return $search; // skip processing - there is no keyword
|
351 |
+
}
|
352 |
+
|
353 |
+
if ( $this->is_ajax_search() || $this->is_search_page() ) {
|
354 |
+
|
355 |
+
$q = $wp_query->query_vars;
|
356 |
+
|
357 |
+
if ( $q[ 'post_type' ] !== DGWT_WCAS_WOO_PRODUCT_POST_TYPE ) {
|
358 |
+
return $search; // skip processing
|
359 |
+
}
|
360 |
+
|
361 |
+
$n = !empty( $q[ 'exact' ] ) ? '' : '%';
|
362 |
+
|
363 |
+
$search = $searchand = '';
|
364 |
+
|
365 |
+
if ( !empty( $q[ 'search_terms' ] ) ) {
|
366 |
+
foreach ( (array) $q[ 'search_terms' ] as $term ) {
|
367 |
+
$term = esc_sql( $wpdb->esc_like( $term ) );
|
368 |
+
|
369 |
+
$search .= "{$searchand} (";
|
370 |
+
|
371 |
+
// Search in title
|
372 |
+
$search .= "($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
|
373 |
+
|
374 |
+
// Search in content
|
375 |
+
if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_content' ) === 'on' ) {
|
376 |
+
$search .= " OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}')";
|
377 |
+
}
|
378 |
+
|
379 |
+
// Search in excerpt
|
380 |
+
if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_excerpt' ) === 'on' ) {
|
381 |
+
$search .= " OR ($wpdb->posts.post_excerpt LIKE '{$n}{$term}{$n}')";
|
382 |
+
}
|
383 |
+
|
384 |
+
// Search in SKU
|
385 |
+
if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_sku' ) === 'on' ) {
|
386 |
+
$search .= " OR (dgwt_wcasmsku.meta_key='_sku' AND dgwt_wcasmsku.meta_value LIKE '{$n}{$term}{$n}')";
|
387 |
+
}
|
388 |
+
|
389 |
+
$search .= ")";
|
390 |
+
|
391 |
+
$searchand = ' AND ';
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
if ( !empty( $search ) ) {
|
396 |
+
$search = " AND ({$search}) ";
|
397 |
+
if ( !is_user_logged_in() )
|
398 |
+
$search .= " AND ($wpdb->posts.post_password = '') ";
|
399 |
+
}
|
400 |
+
}
|
401 |
+
|
402 |
+
return $search;
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* @param $where
|
407 |
+
*
|
408 |
+
* @return string
|
409 |
+
*/
|
410 |
+
public function search_distinct($where) {
|
411 |
+
if ( $this->is_ajax_search() || $this->is_search_page() ) {
|
412 |
+
return 'DISTINCT';
|
413 |
+
}
|
414 |
+
|
415 |
+
return $where;
|
416 |
+
}
|
417 |
+
|
418 |
+
/*
|
419 |
+
* Join the postmeta column in the search posts SQL
|
420 |
+
*/
|
421 |
+
|
422 |
+
public function search_filters_join( $join, $query ) {
|
423 |
+
global $wpdb;
|
424 |
+
|
425 |
+
if ( empty( $query->query_vars[ 'post_type' ] ) || $query->query_vars[ 'post_type' ] !== 'product' ) {
|
426 |
+
return $join; // skip processing
|
427 |
+
}
|
428 |
+
|
429 |
+
if ( ($this->is_ajax_search() || $this->is_search_page()) && !is_admin() ) {
|
430 |
+
|
431 |
+
if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_sku' ) === 'on' ) {
|
432 |
+
$join .= " INNER JOIN $wpdb->postmeta AS dgwt_wcasmsku ON ( $wpdb->posts.ID = dgwt_wcasmsku.post_id )";
|
433 |
+
}
|
434 |
+
}
|
435 |
+
|
436 |
+
|
437 |
+
return $join;
|
438 |
+
}
|
439 |
+
|
440 |
+
/*
|
441 |
+
* Get taxonomy parent
|
442 |
+
*
|
443 |
+
* @param int $term_id
|
444 |
+
* @param string $taxonomy
|
445 |
+
*
|
446 |
+
* @return string
|
447 |
+
*/
|
448 |
+
|
449 |
+
private function get_taxonomy_parent_string( $term_id, $taxonomy, $visited = array(), $exclude = array() ) {
|
450 |
+
|
451 |
+
$chain = '';
|
452 |
+
$separator = ' > ';
|
453 |
+
|
454 |
+
$parent = get_term( $term_id, $taxonomy );
|
455 |
+
|
456 |
+
if ( empty( $parent ) || !isset( $parent->name ) ) {
|
457 |
+
return '';
|
458 |
+
}
|
459 |
+
|
460 |
+
$name = $parent->name;
|
461 |
+
|
462 |
+
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
|
463 |
+
$visited[] = $parent->parent;
|
464 |
+
$chain .= $this->get_taxonomy_parent_string( $parent->parent, $taxonomy, $visited );
|
465 |
+
}
|
466 |
+
|
467 |
+
if ( !in_array( $parent->term_id, $exclude ) ) {
|
468 |
+
$chain .= $name . $separator;
|
469 |
+
}
|
470 |
+
|
471 |
+
return $chain;
|
472 |
+
}
|
473 |
+
|
474 |
+
/*
|
475 |
+
* Change default search query on the search results page
|
476 |
+
*
|
477 |
+
* @since 1.0.3
|
478 |
+
*
|
479 |
+
* @param object $query
|
480 |
+
*
|
481 |
+
* @return object
|
482 |
+
*/
|
483 |
+
|
484 |
+
public function set_search_results_query( $query ) {
|
485 |
+
|
486 |
+
if ( !$this->is_ajax_search() && $query->is_search ) {
|
487 |
+
|
488 |
+
if ( $this->is_search_page() ) {
|
489 |
+
|
490 |
+
$query->query_vars[ 'post_type' ] = DGWT_WCAS_WOO_PRODUCT_POST_TYPE;
|
491 |
+
|
492 |
+
$query->query_vars[ 'meta_query' ] = $this->get_meta_query();
|
493 |
+
}
|
494 |
+
}
|
495 |
+
|
496 |
+
return $query;
|
497 |
+
}
|
498 |
+
|
499 |
+
/**
|
500 |
+
* Check if is WooCommerce search results page
|
501 |
+
*
|
502 |
+
* @since 1.1.3
|
503 |
+
*
|
504 |
+
* @return bool
|
505 |
+
*/
|
506 |
+
public function is_search_page() {
|
507 |
+
if ( ! empty( $_GET['dgwt_wcas'] ) && ! empty( $_GET['s'] ) ) {
|
508 |
+
return true;
|
509 |
+
}
|
510 |
+
|
511 |
+
return false;
|
512 |
+
}
|
513 |
+
|
514 |
+
/**
|
515 |
+
* Check if is ajax search processing
|
516 |
+
*
|
517 |
+
* @since 1.1.3
|
518 |
+
*
|
519 |
+
* @return bool
|
520 |
+
*/
|
521 |
+
public function is_ajax_search() {
|
522 |
+
if ( defined( 'DGWT_WCAS_AJAX' ) && DGWT_WCAS_AJAX ) {
|
523 |
+
return true;
|
524 |
+
}
|
525 |
+
|
526 |
+
return false;
|
527 |
+
}
|
528 |
+
|
529 |
+
}
|
530 |
+
|
531 |
?>
|
includes/install.php
CHANGED
@@ -1,96 +1,96 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Installation related functions and actions.
|
5 |
-
*
|
6 |
-
*/
|
7 |
-
// Exit if accessed directly
|
8 |
-
if ( !defined( 'ABSPATH' ) ) {
|
9 |
-
exit;
|
10 |
-
}
|
11 |
-
|
12 |
-
class DGWT_WCAS_Install {
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Hook in tabs.
|
16 |
-
*/
|
17 |
-
public static function init() {
|
18 |
-
|
19 |
-
add_action( 'admin_init', array( __CLASS__, 'check_version' ), 5 );
|
20 |
-
}
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Install
|
24 |
-
*/
|
25 |
-
public static function install() {
|
26 |
-
|
27 |
-
|
28 |
-
if ( !defined( 'DGWT_WCAS_INSTALLING' ) ) {
|
29 |
-
define( 'DGWT_WCAS_INSTALLING', true );
|
30 |
-
}
|
31 |
-
|
32 |
-
self::create_options();
|
33 |
-
self::create_cron_jobs();
|
34 |
-
|
35 |
-
// Update plugin version
|
36 |
-
update_option( 'dgwt_wcas_version', DGWT_WCAS_VERSION );
|
37 |
-
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Default options
|
42 |
-
*/
|
43 |
-
private static function create_options() {
|
44 |
-
|
45 |
-
global $dgwt_wcas_settings;
|
46 |
-
|
47 |
-
$sections = DGWT_WCAS()->settings->settings_fields();
|
48 |
-
|
49 |
-
$settings = array();
|
50 |
-
|
51 |
-
if ( is_array( $sections ) && !empty( $sections ) ) {
|
52 |
-
foreach ( $sections as $options ) {
|
53 |
-
|
54 |
-
if ( is_array( $options ) && !empty( $options ) ) {
|
55 |
-
|
56 |
-
foreach ( $options as $option ) {
|
57 |
-
|
58 |
-
if ( isset( $option[ 'name' ] ) && !isset( $dgwt_wcas_settings[ $option[ 'name' ] ] ) ) {
|
59 |
-
|
60 |
-
$settings[ $option[ 'name' ] ] = isset( $option[ 'default' ] ) ? $option[ 'default' ] : '';
|
61 |
-
}
|
62 |
-
}
|
63 |
-
}
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
$update_options = array_merge( $settings, $dgwt_wcas_settings );
|
68 |
-
|
69 |
-
update_option( DGWT_WCAS_SETTINGS_KEY, $update_options );
|
70 |
-
}
|
71 |
-
|
72 |
-
/**
|
73 |
-
* Create cron jobs (clear them first)
|
74 |
-
*/
|
75 |
-
private static function create_cron_jobs() {
|
76 |
-
//@todo clear and init schedule
|
77 |
-
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Check version
|
82 |
-
*/
|
83 |
-
public static function check_version() {
|
84 |
-
|
85 |
-
if ( !defined( 'IFRAME_REQUEST' ) ) {
|
86 |
-
|
87 |
-
if ( get_option( 'dgwt_wcas_version' ) != DGWT_WCAS_VERSION ) {
|
88 |
-
self::install();
|
89 |
-
}
|
90 |
-
}
|
91 |
-
}
|
92 |
-
|
93 |
-
}
|
94 |
-
|
95 |
-
|
96 |
-
DGWT_WCAS_Install::init();
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Installation related functions and actions.
|
5 |
+
*
|
6 |
+
*/
|
7 |
+
// Exit if accessed directly
|
8 |
+
if ( !defined( 'ABSPATH' ) ) {
|
9 |
+
exit;
|
10 |
+
}
|
11 |
+
|
12 |
+
class DGWT_WCAS_Install {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Hook in tabs.
|
16 |
+
*/
|
17 |
+
public static function init() {
|
18 |
+
|
19 |
+
add_action( 'admin_init', array( __CLASS__, 'check_version' ), 5 );
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Install
|
24 |
+
*/
|
25 |
+
public static function install() {
|
26 |
+
|
27 |
+
|
28 |
+
if ( !defined( 'DGWT_WCAS_INSTALLING' ) ) {
|
29 |
+
define( 'DGWT_WCAS_INSTALLING', true );
|
30 |
+
}
|
31 |
+
|
32 |
+
self::create_options();
|
33 |
+
self::create_cron_jobs();
|
34 |
+
|
35 |
+
// Update plugin version
|
36 |
+
update_option( 'dgwt_wcas_version', DGWT_WCAS_VERSION );
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Default options
|
42 |
+
*/
|
43 |
+
private static function create_options() {
|
44 |
+
|
45 |
+
global $dgwt_wcas_settings;
|
46 |
+
|
47 |
+
$sections = DGWT_WCAS()->settings->settings_fields();
|
48 |
+
|
49 |
+
$settings = array();
|
50 |
+
|
51 |
+
if ( is_array( $sections ) && !empty( $sections ) ) {
|
52 |
+
foreach ( $sections as $options ) {
|
53 |
+
|
54 |
+
if ( is_array( $options ) && !empty( $options ) ) {
|
55 |
+
|
56 |
+
foreach ( $options as $option ) {
|
57 |
+
|
58 |
+
if ( isset( $option[ 'name' ] ) && !isset( $dgwt_wcas_settings[ $option[ 'name' ] ] ) ) {
|
59 |
+
|
60 |
+
$settings[ $option[ 'name' ] ] = isset( $option[ 'default' ] ) ? $option[ 'default' ] : '';
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
$update_options = array_merge( $settings, $dgwt_wcas_settings );
|
68 |
+
|
69 |
+
update_option( DGWT_WCAS_SETTINGS_KEY, $update_options );
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Create cron jobs (clear them first)
|
74 |
+
*/
|
75 |
+
private static function create_cron_jobs() {
|
76 |
+
//@todo clear and init schedule
|
77 |
+
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Check version
|
82 |
+
*/
|
83 |
+
public static function check_version() {
|
84 |
+
|
85 |
+
if ( !defined( 'IFRAME_REQUEST' ) ) {
|
86 |
+
|
87 |
+
if ( get_option( 'dgwt_wcas_version' ) != DGWT_WCAS_VERSION ) {
|
88 |
+
self::install();
|
89 |
+
}
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
DGWT_WCAS_Install::init();
|
readme.txt
CHANGED
@@ -1,115 +1,120 @@
|
|
1 |
-
=== Ajax Search for WooCommerce ===
|
2 |
-
Contributors: damian-gora
|
3 |
-
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LD2ALVRLXPZPC
|
4 |
-
Tags: AJAX, ajax search, autocomplete, category search, custom search, ecommerce, instant search, sive search, product search, products, search, search by sku, search highlight, search plugin, shop, woocommerce, woocommerce live search, WooCommerce Plugin, woocommerce product search, woocommerce search, wordpress search, wp ajax search, wp search, wp search plugin, wp tao
|
5 |
-
Requires at least: 3.8
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.1.
|
8 |
-
License: GPLv2 or later
|
9 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
-
|
11 |
-
Help users easily find and discover products in your store using Ajax Search for WooCommerce – a highly customizable live search plugin.
|
12 |
-
|
13 |
-
== Description ==
|
14 |
-
|
15 |
-
The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
|
16 |
-
|
17 |
-
Just enter a few letters and the products which best match your query will appear.
|
18 |
-
Suggestions can be displayed in a simple form (names of the products only) or in an extended form (includes photos, prices, descriptions, extended information etc.).
|
19 |
-
|
20 |
-
Ajax Search for WooCommerce has been designed to enhance user search experience to the maximum.
|
21 |
-
|
22 |
-
= Free =
|
23 |
-
This plugin is completely free of charge and provides the whole range of functions which are included in some paid plugins.
|
24 |
-
Initially, I created the plugin for my personal use, but I have decided to include new features and make it available to WordPress community.
|
25 |
-
|
26 |
-
= Demo =
|
27 |
-
See how it works on the [DEMO](http://damiangora.com/ajax-search-for-woocommerce) site.
|
28 |
-
|
29 |
-
|
30 |
-
= Features =
|
31 |
-
* Search in **products titles, descriptions, excerpt, categories, tags or SKU**.
|
32 |
-
* **Product image** can be displayed for each suggestion
|
33 |
-
* **Price** can be displayed for each suggestion
|
34 |
-
* **Description** can be displayed for each suggestion
|
35 |
-
* **SKU** can be displayed for each suggestion
|
36 |
-
* The **'add to cart' button and** and **extended information** displayed when you hover the mouse over the suggestion
|
37 |
-
* **Categories and tags** as suggestions
|
38 |
-
* **Limit** displayed suggestions – you can set your own
|
39 |
-
* **The minimum number of characters** required to display suggestions – you can set your own
|
40 |
-
* WPML compatible
|
41 |
-
* You can set your own **label on the 'search' button**
|
42 |
-
* You can set your own **preloader image**
|
43 |
-
* You can set your own **colour scheme** for the 10 main form elements and suggestions
|
44 |
-
* **[WP Tao](https://wordpress.org/plugins/wp-tao) integration** - allows you to track and analyze search results of a website users. Each click on the suggestion is logged. Read more on [wptao.org](http://wptao.org/documentation/user-guide/).
|
45 |
-
|
46 |
-
= How to use? =
|
47 |
-
1. Use shorcode [wcas-search-form] in page/post editor or <?php echo do_shortcode('[wcas-search-form]'); ?> in your Child Theme template files.
|
48 |
-
2. Go to the "Widgets Screen" and assign widget "Woo Ajax Search" to one of the widget area.
|
49 |
-
|
50 |
-
= Feedback =
|
51 |
-
|
52 |
-
Any suggestions or comments are welcome. Feel free to contact me using this [contact form](http://damiangora.com/ajax-search-for-woocommerce/contact).
|
53 |
-
|
54 |
-
== Installation ==
|
55 |
-
|
56 |
-
1. Install the plugin from within the Dashboard or upload the directory `ajax-search-for-woocommerce` and all its contents to the `/wp-content/plugins/` directory.
|
57 |
-
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
58 |
-
3. Go to Woo Ajax Search (admin menu) and set your preferences.
|
59 |
-
4. Use shorcode [wcas-search-form] or go to the Widgets Screen and choose "Woo Ajax Search"
|
60 |
-
|
61 |
-
== Screenshots ==
|
62 |
-
|
63 |
-
1. Basic suggestions
|
64 |
-
2. Extra elements
|
65 |
-
3. Extended suggestions
|
66 |
-
4. Settings page with colour schemes
|
67 |
-
|
68 |
-
== Changelog ==
|
69 |
-
|
70 |
-
= 1.1.
|
71 |
-
*
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
* FIX:
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
*
|
82 |
-
* FIX:
|
83 |
-
* FIX:
|
84 |
-
|
85 |
-
= 1.
|
86 |
-
*
|
87 |
-
* FIX:
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
*
|
92 |
-
*
|
93 |
-
|
94 |
-
= 1.0.
|
95 |
-
* FIX:
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
* FIX:
|
101 |
-
|
102 |
-
= 1.0, June
|
103 |
-
*
|
104 |
-
*
|
105 |
-
*
|
106 |
-
|
107 |
-
|
108 |
-
*
|
109 |
-
|
110 |
-
|
111 |
-
*
|
112 |
-
* FIX:
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Ajax Search for WooCommerce ===
|
2 |
+
Contributors: damian-gora
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LD2ALVRLXPZPC
|
4 |
+
Tags: AJAX, ajax search, autocomplete, category search, custom search, ecommerce, instant search, sive search, product search, products, search, search by sku, search highlight, search plugin, shop, woocommerce, woocommerce live search, WooCommerce Plugin, woocommerce product search, woocommerce search, wordpress search, wp ajax search, wp search, wp search plugin, wp tao
|
5 |
+
Requires at least: 3.8
|
6 |
+
Tested up to: 4.8
|
7 |
+
Stable tag: 1.1.3
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Help users easily find and discover products in your store using Ajax Search for WooCommerce – a highly customizable live search plugin.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
|
16 |
+
|
17 |
+
Just enter a few letters and the products which best match your query will appear.
|
18 |
+
Suggestions can be displayed in a simple form (names of the products only) or in an extended form (includes photos, prices, descriptions, extended information etc.).
|
19 |
+
|
20 |
+
Ajax Search for WooCommerce has been designed to enhance user search experience to the maximum.
|
21 |
+
|
22 |
+
= Free =
|
23 |
+
This plugin is completely free of charge and provides the whole range of functions which are included in some paid plugins.
|
24 |
+
Initially, I created the plugin for my personal use, but I have decided to include new features and make it available to WordPress community.
|
25 |
+
|
26 |
+
= Demo =
|
27 |
+
See how it works on the [DEMO](http://damiangora.com/ajax-search-for-woocommerce) site.
|
28 |
+
|
29 |
+
|
30 |
+
= Features =
|
31 |
+
* Search in **products titles, descriptions, excerpt, categories, tags or SKU**.
|
32 |
+
* **Product image** can be displayed for each suggestion
|
33 |
+
* **Price** can be displayed for each suggestion
|
34 |
+
* **Description** can be displayed for each suggestion
|
35 |
+
* **SKU** can be displayed for each suggestion
|
36 |
+
* The **'add to cart' button and** and **extended information** displayed when you hover the mouse over the suggestion
|
37 |
+
* **Categories and tags** as suggestions
|
38 |
+
* **Limit** displayed suggestions – you can set your own
|
39 |
+
* **The minimum number of characters** required to display suggestions – you can set your own
|
40 |
+
* WPML compatible
|
41 |
+
* You can set your own **label on the 'search' button**
|
42 |
+
* You can set your own **preloader image**
|
43 |
+
* You can set your own **colour scheme** for the 10 main form elements and suggestions
|
44 |
+
* **[WP Tao](https://wordpress.org/plugins/wp-tao) integration** - allows you to track and analyze search results of a website users. Each click on the suggestion is logged. Read more on [wptao.org](http://wptao.org/documentation/user-guide/).
|
45 |
+
|
46 |
+
= How to use? =
|
47 |
+
1. Use shorcode [wcas-search-form] in page/post editor or <?php echo do_shortcode('[wcas-search-form]'); ?> in your Child Theme template files.
|
48 |
+
2. Go to the "Widgets Screen" and assign widget "Woo Ajax Search" to one of the widget area.
|
49 |
+
|
50 |
+
= Feedback =
|
51 |
+
|
52 |
+
Any suggestions or comments are welcome. Feel free to contact me using this [contact form](http://damiangora.com/ajax-search-for-woocommerce/contact).
|
53 |
+
|
54 |
+
== Installation ==
|
55 |
+
|
56 |
+
1. Install the plugin from within the Dashboard or upload the directory `ajax-search-for-woocommerce` and all its contents to the `/wp-content/plugins/` directory.
|
57 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
58 |
+
3. Go to Woo Ajax Search (admin menu) and set your preferences.
|
59 |
+
4. Use shorcode [wcas-search-form] or go to the Widgets Screen and choose "Woo Ajax Search"
|
60 |
+
|
61 |
+
== Screenshots ==
|
62 |
+
|
63 |
+
1. Basic suggestions
|
64 |
+
2. Extra elements
|
65 |
+
3. Extended suggestions
|
66 |
+
4. Settings page with colour schemes
|
67 |
+
|
68 |
+
== Changelog ==
|
69 |
+
|
70 |
+
= 1.1.3, July 12, 2017 =
|
71 |
+
* ADD: New WordPress filters
|
72 |
+
* FIX: Repetitive search results
|
73 |
+
* FIX: Extra details when there are no results
|
74 |
+
|
75 |
+
= 1.1.2, June 7, 2017 =
|
76 |
+
* FIX: Replace deprecated methods and functions in WC 3.0.x
|
77 |
+
|
78 |
+
= 1.1.1, June 6, 2017 =
|
79 |
+
* ADD: Added Portable Object Template file
|
80 |
+
* ADD: Added partial polish translation
|
81 |
+
* FIX: WooCommerce 3.0.x compatible
|
82 |
+
* FIX: Menu items repeated in a search page
|
83 |
+
* FIX: Other minor bugs
|
84 |
+
|
85 |
+
= 1.1, October 5, 2016 =
|
86 |
+
* NEW: Add WPML compatibility
|
87 |
+
* FIX: Repeating search results for products in a admin dashboard
|
88 |
+
* FIX: Overwrite default input element rounding for Safari browser
|
89 |
+
|
90 |
+
= 1.0.3.1, July 24, 2016 =
|
91 |
+
* FIX: Disappearing widgets
|
92 |
+
* FIX: Trivial things in CSS
|
93 |
+
|
94 |
+
= 1.0.3, July 22, 2016 =
|
95 |
+
* FIX: Synchronization WP Query on a search page and ajax search query
|
96 |
+
* CHANGE: Disable auto select the first suggestion
|
97 |
+
* CHANGE: Change textdomain to ajax-search-for-woocommerce
|
98 |
+
|
99 |
+
= 1.0.2, June 30, 2016 =
|
100 |
+
* FIX: PHP syntax error with PHP version < 5.3
|
101 |
+
|
102 |
+
= 1.0.1, June 30, 2016 =
|
103 |
+
* FIX: Excess AJAX requests in a detail mode
|
104 |
+
* FIX: Optimization JS mouseover event in a detail mode
|
105 |
+
* FIX: Trivial things in CSS
|
106 |
+
|
107 |
+
= 1.0, June 24, 2016 =
|
108 |
+
* NEW: [Option] Exclude out of stock products from suggestions
|
109 |
+
* NEW: [Option] Overwrite a suggestion container width
|
110 |
+
* NEW: [Option] Show/hide SKU in suggestions
|
111 |
+
* NEW: Add no results note
|
112 |
+
* FIX: Search in products SKU
|
113 |
+
* FIX: Trivial things in CSS and JS files
|
114 |
+
|
115 |
+
= 0.9.1, June 5, 2016 =
|
116 |
+
* ADD: Javascript and CSS dynamic compression
|
117 |
+
* FIX: Incorrect dimensions of the custom preloader
|
118 |
+
|
119 |
+
= 0.9, May 17, 2016 =
|
120 |
+
* First public release
|