WooCommerce Wishlist Plugin - Version 1.41.1

Version Description

Release Date - 20 February 2022

  • Added feature to automatically close add to wishlist popup after few seconds if redirect disabled
  • Added filter tinvwl_addtowishlist_redirect
  • Fixed WPML plugin issue
  • Fixed add to wishlist issue for guests
Download this release

Release Info

Developer templateinvaders
Plugin Icon 128x128 WooCommerce Wishlist Plugin
Version 1.41.1
Comparing to
See all releases

Code changes from version 1.41.0 to 1.41.1

assets/css/admin-form-rtl.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tiwlform-number-container{display:inline-block;margin:2px;position:relative;vertical-align:middle}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tiwlform-number-container{display:inline-block;margin:2px;position:relative;vertical-align:middle}
assets/css/admin-form.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tiwlform-number-container{display:inline-block;margin:2px;position:relative;vertical-align:middle}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tiwlform-number-container{display:inline-block;margin:2px;position:relative;vertical-align:middle}
assets/css/admin-rtl.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  *{-webkit-box-sizing:border-box;box-sizing:border-box}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  *{-webkit-box-sizing:border-box;box-sizing:border-box}
assets/css/admin-setup-rtl.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  html{background:#f6f3ed}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  html{background:#f6f3ed}
assets/css/admin-setup.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  html{background:#f6f3ed}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  html{background:#f6f3ed}
assets/css/admin.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  *{-webkit-box-sizing:border-box;box-sizing:border-box}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  *{-webkit-box-sizing:border-box;box-sizing:border-box}
assets/css/public-rtl.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist form,.tinv-wishlist p:last-child,.tinv-wishlist table{margin-bottom:0}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist form,.tinv-wishlist p:last-child,.tinv-wishlist table{margin-bottom:0}
assets/css/public.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist form,.tinv-wishlist p:last-child,.tinv-wishlist table{margin-bottom:0}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist form,.tinv-wishlist p:last-child,.tinv-wishlist table{margin-bottom:0}
assets/css/theme-rtl.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist,.tinv-wishlist input,.tinv-wishlist select,.tinv-wishlist textarea,.tinv-wishlist button,.tinv-wishlist input[type=button],.tinv-wishlist input[type=reset],.tinv-wishlist input[type=submit]{font-family:Georgia,serif;font-size:14px;font-weight:400;text-transform:none;line-height:1.75}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist,.tinv-wishlist input,.tinv-wishlist select,.tinv-wishlist textarea,.tinv-wishlist button,.tinv-wishlist input[type=button],.tinv-wishlist input[type=reset],.tinv-wishlist input[type=submit]{font-family:Georgia,serif;font-size:14px;font-weight:400;text-transform:none;line-height:1.75}
assets/css/theme.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist,.tinv-wishlist input,.tinv-wishlist select,.tinv-wishlist textarea,.tinv-wishlist button,.tinv-wishlist input[type=button],.tinv-wishlist input[type=reset],.tinv-wishlist input[type=submit]{font-family:Georgia,serif;font-size:14px;font-weight:400;text-transform:none;line-height:1.75}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  .tinv-wishlist,.tinv-wishlist input,.tinv-wishlist select,.tinv-wishlist textarea,.tinv-wishlist button,.tinv-wishlist input[type=button],.tinv-wishlist input[type=reset],.tinv-wishlist input[type=submit]{font-family:Georgia,serif;font-size:14px;font-weight:400;text-transform:none;line-height:1.75}
assets/css/webfont-rtl.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:"tinvwl-webfont";font-display:block;src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi");src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.woff2?ver=xu2uyi") format("woff2"),url("../fonts/tinvwl-webfont.woff?ver=xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.ttf?ver=xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.svg?ver=xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:"tinvwl-webfont";font-display:block;src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi");src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.woff2?ver=xu2uyi") format("woff2"),url("../fonts/tinvwl-webfont.woff?ver=xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.ttf?ver=xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.svg?ver=xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
assets/css/webfont.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:"tinvwl-webfont";font-display:block;src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi");src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.woff2?ver=xu2uyi") format("woff2"),url("../fonts/tinvwl-webfont.woff?ver=xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.ttf?ver=xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.svg?ver=xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:"tinvwl-webfont";font-display:block;src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi");src:url("../fonts/tinvwl-webfont.eot?ver=xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.woff2?ver=xu2uyi") format("woff2"),url("../fonts/tinvwl-webfont.woff?ver=xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.ttf?ver=xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.svg?ver=xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
assets/js/admin.min.js CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  "use strict";function TInvWL($,h){this.pf="tinvwl",this.g="_",this.ho=h||!1,this.n="TInvWL",this.aj_act=function(t){return[this.pf,t].join(this.g)},this._csel=function(t,n){n=n||".";return"{0}{1}{2}".format(n,this.pf,t)},this._tm=function(t){t=$("script#{0}[type='text/template']".format(t));return t.length?t.html():""},this.formElm=function(){var e,n;$(this._csel("-form-onoff")).tiwl_onoff(),$("input[type=checkbox][tiwl-show], input[type=checkbox][tiwl-hide]").tiwl_onoffblock(),$("[tiwl-value][tiwl-show], [tiwl-value][tiwl-hide]").tiwl_byvalueblock(),void 0!==$.fn.wpColorPicker&&(e=function(t){t=t.substring(1),t=parseInt(t,16);return.2126*(t>>16&255)+.7152*(t>>8&255)+.0722*(t>>0&255)},n=this._csel("-form-color"),$(n).each(function(){var n=$(this),t=$(this).closest(".tinvwl-color-picker"),i=t.find(".tinvwl-eyedropper");n.css("background-color",n.val()),175<e(n.val())&&n.css("color","#000000"),n.iris({mode:"hsv",target:$(this).parent().parent(),change:function(t,n){175<e(n.color.toCSS())?$(this).css("color","#000000"):$(this).css("color",""),$(this).css("background-color",n.color.toCSS())}}),t.on("click",".iris-square-value",function(t){t.preventDefault(),n.iris("toggle")}),i.on("click",function(t){t.preventDefault(),n.iris("show")}),n.on("focusin",function(){n.iris("show")})}),$(document).on("click",function(t){($(t.target).is(n+", .iris-picker, .iris-picker-inner, .iris-slider-offset, .tinvwl-eyedropper, .tinvwl-eyedropper .ftinvwl-eyedropper")?$(n).not($(t.target).closest(".tinvwl-color-picker").find(n)):$(n)).iris("hide")}))},this.wizard_page=function(t){$(t).find("select").change(this._wizard_page_ch),this.wizard_page_ch($(t).find("select"))},this.wizard_page_ch=function(t){var n=(t=$(t)).parent(this._csel("-page-select")),i=n.find("input[type=hidden]").val(),e=n.find(this._csel("-error-icon")),o=n.find(this._csel("-error-desc"));""!==t.val()?(n.removeClass("tinvwl-error"),e.hide(),o.hide()):0==i&&(n.addClass("tinvwl-error"),e.show(),o.show())},this.pageElm=function(){$(this._csel("-header","div.")).prependTo("#wpbody-content"),$(this._csel("-page-select")).each(this._wizard_page),$(".bulkactions [type=submit]").each(this._control_bulkactions),$(".action-search [type=submit]").each(this._control_search)},this.control_bulkactions=function(t){$(t).on("click",this._control_bulkactions_ck)},this.control_bulkactions_ck=function(t,n){var i=(t=$(t)).parents(".bulkactions").eq(0).find("[name=action]"),t=t.parents("form").eq(0);i&&("-1"!==i.val()&&t.find("input[type=checkbox]:checked").length||n.preventDefault())},this.control_search=function(t){$(t).on("click",this._control_search_ck)},this.control_search_ck=function(t,n){t=(t=$(t)).parents(".action-search").eq(0).find("[name=s]");t&&""===t.val()&&n.preventDefault()},this.Run=function(){this.formElm(),this.pageElm()},this.cg=function(){var t,n=this.n;this.ho&&(n=n+(t=new Date).getFullYear()+t.getMonth()+t.getDate()),window[n]=this},this.cg(),String.prototype.format||(String.prototype.format=function(){var i=arguments;return this.replace(/{(\d+)}/g,function(t,n){return void 0!==i[n]?i[n]:t})});var o=this,n=o.n,ho=o.ho,c=ho?"t=new Date(),n=n+t.getFullYear()+t.getMonth()+t.getDate(),":"",i;for(i in o)"function"!=typeof o[i]||"_"===i[0]||o.hasOwnProperty("_"+i)||eval("o._"+i+"=function(a,b,c,d){var n='"+n+"',"+c+"o=window[n]||null;if (o) {return o."+i+"(this,a,b,c,d);};};")}!function(s){s.fn.tiwl_onoff=function(t){var o=s.extend(!0,{},{value:{on:"",off:""},class:"tiwlform-onoff",wrap:"container",button:"button"},t);return s(this).each(function(){var n=s(this),t=s("<div>").attr({class:o.class+"-"+o.button}),i=o.class+"-"+o.wrap,e=s("<div>").attr({id:n.attr("id")+"_"+o.wrap,class:i});return n.is("input")&&(e.attr("class",e.attr("class")+" "+n.attr("class")),n.is(":disabled")&&(e.toggleClass("disabled",n.is(":disabled")),n.prop("disabled",!1)),e.toggleClass("checked",n.is(":checked")),n.hide().removeAttr("class").wrap(e).before(t),e=n.parent(),n.on("change",function(t){if(e.hasClass("disabled"))return t.preventDefault();e.toggleClass("checked",s(this).is(":checked"))}),e.on("click",function(t){if(e.hasClass("disabled"))return t.preventDefault();n.is(":enabled")&&e.hasClass("checked")===n.is(":checked")&&n.click()})),n})},s.fn.tiwl_onoffblock=function(t){var c=s.extend(!0,{},{onEachElm:function(){},isChecked:function(){return s(this).is(":checked")}},t);return s(this).each(function(){function t(){function t(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){c.onEachElm.call(s(n).toggle(i))})}var n=s(this),i=n.attr("tiwl-show"),e=n.attr("tiwl-hide"),o=c.isChecked.call(n);return"string"==typeof i&&t(i,o),"string"==typeof e&&t(e,!o),n}var n=s(this);return n.is("input")&&"checkbox"==n.attr("type")?(s(this).on("change",t),t.call(n)):n})},s.fn.tiwl_byvalueblock=function(t){var i=s.extend(!0,{},{onEachElm:function(){},onClick:function(){return s(this).val()==s(this).attr("tiwl-value")}},t);return s(this).each(function(){function t(e){function t(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){e.onEachElm.call(s(n).toggle(i))})}var n=s(this),i=n.attr("tiwl-show"),o=n.attr("tiwl-hide"),c=e.onClick.call(n);return"string"==typeof i&&t(i,c),"string"==typeof o&&t(o,!c),n}var n=s(this);return n.is("input")||n.is("select")?(s(this).on("change",function(){t.call(this,i)}),t.call(n,i)):n})};var n=new TInvWL(s);s(document).ready(function(){var t;n.Run(),jQuery('input[name="general-show_notice"]').change(function(){var t=!jQuery(this).is(":checked"),n=jQuery('input[name="general-redirect_require_login"]');t&&!n.is(":checked")&&n.click().trigger("change"),n.closest(".tiwlform-onoff-container").toggleClass("disabled",t)}).change(),s(".tablenav").each(function(){var t=s(this);s.trim(t.find(".alignleft").html()).length||t.find(".alignleft").remove(),s.trim(t.find(".alignright").html()).length&&!t.find(".tablenav-pages").hasClass("one-page")||(t.find(".alignright").remove(),t.find(".tinv-wishlist-clear").remove()),s.trim(t.html()).length||t.remove()}),s(".tablenav .bulkactions select").addClass("tinvwl-select grey").wrap('<span class="tinvwl-select-wrap">').parent().append('<span class="tinvwl-caret"><span></span></span>'),s(".tablenav .bulkactions .button.action, .tablenav #search-submit").removeClass("button").addClass("tinvwl-btn grey"),s(".tinvwl-modal-btn").on("click",function(){s(this).next(".tinvwl-modal").addClass("tinvwl-modal-open")}),s(".tinvwl-overlay, .tinvwl-close-modal, .tinvwl_button_close").on("click",function(t){t.preventDefault(),s(this).parents(".tinvwl-modal:first").removeClass("tinvwl-modal-open")}),void 0!==s.fn.popover&&((t=s(".tinvwl-help")).popover({content:function(){return s(this).closest(".tinvwl-info-wrap").find(".tinvwl-info-desc").html()}}),t.on("click",function(){s(this).popover("toggle")}),t.on("focusout",function(){s(this).popover("hide")}),s(window).on("resize",function(){t.popover("hide")})),s("body").on("click",".tinvwl-confirm-reset",function(t){t.preventDefault(),confirm(tinvwl_comfirm.text_comfirm_reset)&&s(this).removeClass("tinvwl-confirm-reset").trigger("click")})}),s(document).on("click",".tinvwl-chat-notice .notice-dismiss",function(t){s.post(tinvwl_comfirm.ajax_url,{action:"tinvwl_admin_chat_notice"})})}(jQuery);
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  "use strict";function TInvWL($,h){this.pf="tinvwl",this.g="_",this.ho=h||!1,this.n="TInvWL",this.aj_act=function(t){return[this.pf,t].join(this.g)},this._csel=function(t,n){n=n||".";return"{0}{1}{2}".format(n,this.pf,t)},this._tm=function(t){t=$("script#{0}[type='text/template']".format(t));return t.length?t.html():""},this.formElm=function(){var e,n;$(this._csel("-form-onoff")).tiwl_onoff(),$("input[type=checkbox][tiwl-show], input[type=checkbox][tiwl-hide]").tiwl_onoffblock(),$("[tiwl-value][tiwl-show], [tiwl-value][tiwl-hide]").tiwl_byvalueblock(),void 0!==$.fn.wpColorPicker&&(e=function(t){t=t.substring(1),t=parseInt(t,16);return.2126*(t>>16&255)+.7152*(t>>8&255)+.0722*(t>>0&255)},n=this._csel("-form-color"),$(n).each(function(){var n=$(this),t=$(this).closest(".tinvwl-color-picker"),i=t.find(".tinvwl-eyedropper");n.css("background-color",n.val()),175<e(n.val())&&n.css("color","#000000"),n.iris({mode:"hsv",target:$(this).parent().parent(),change:function(t,n){175<e(n.color.toCSS())?$(this).css("color","#000000"):$(this).css("color",""),$(this).css("background-color",n.color.toCSS())}}),t.on("click",".iris-square-value",function(t){t.preventDefault(),n.iris("toggle")}),i.on("click",function(t){t.preventDefault(),n.iris("show")}),n.on("focusin",function(){n.iris("show")})}),$(document).on("click",function(t){($(t.target).is(n+", .iris-picker, .iris-picker-inner, .iris-slider-offset, .tinvwl-eyedropper, .tinvwl-eyedropper .ftinvwl-eyedropper")?$(n).not($(t.target).closest(".tinvwl-color-picker").find(n)):$(n)).iris("hide")}))},this.wizard_page=function(t){$(t).find("select").change(this._wizard_page_ch),this.wizard_page_ch($(t).find("select"))},this.wizard_page_ch=function(t){var n=(t=$(t)).parent(this._csel("-page-select")),i=n.find("input[type=hidden]").val(),e=n.find(this._csel("-error-icon")),o=n.find(this._csel("-error-desc"));""!==t.val()?(n.removeClass("tinvwl-error"),e.hide(),o.hide()):0==i&&(n.addClass("tinvwl-error"),e.show(),o.show())},this.pageElm=function(){$(this._csel("-header","div.")).prependTo("#wpbody-content"),$(this._csel("-page-select")).each(this._wizard_page),$(".bulkactions [type=submit]").each(this._control_bulkactions),$(".action-search [type=submit]").each(this._control_search)},this.control_bulkactions=function(t){$(t).on("click",this._control_bulkactions_ck)},this.control_bulkactions_ck=function(t,n){var i=(t=$(t)).parents(".bulkactions").eq(0).find("[name=action]"),t=t.parents("form").eq(0);i&&("-1"!==i.val()&&t.find("input[type=checkbox]:checked").length||n.preventDefault())},this.control_search=function(t){$(t).on("click",this._control_search_ck)},this.control_search_ck=function(t,n){t=(t=$(t)).parents(".action-search").eq(0).find("[name=s]");t&&""===t.val()&&n.preventDefault()},this.Run=function(){this.formElm(),this.pageElm()},this.cg=function(){var t,n=this.n;this.ho&&(n=n+(t=new Date).getFullYear()+t.getMonth()+t.getDate()),window[n]=this},this.cg(),String.prototype.format||(String.prototype.format=function(){var i=arguments;return this.replace(/{(\d+)}/g,function(t,n){return void 0!==i[n]?i[n]:t})});var o=this,n=o.n,ho=o.ho,c=ho?"t=new Date(),n=n+t.getFullYear()+t.getMonth()+t.getDate(),":"",i;for(i in o)"function"!=typeof o[i]||"_"===i[0]||o.hasOwnProperty("_"+i)||eval("o._"+i+"=function(a,b,c,d){var n='"+n+"',"+c+"o=window[n]||null;if (o) {return o."+i+"(this,a,b,c,d);};};")}!function(s){s.fn.tiwl_onoff=function(t){var o=s.extend(!0,{},{value:{on:"",off:""},class:"tiwlform-onoff",wrap:"container",button:"button"},t);return s(this).each(function(){var n=s(this),t=s("<div>").attr({class:o.class+"-"+o.button}),i=o.class+"-"+o.wrap,e=s("<div>").attr({id:n.attr("id")+"_"+o.wrap,class:i});return n.is("input")&&(e.attr("class",e.attr("class")+" "+n.attr("class")),n.is(":disabled")&&(e.toggleClass("disabled",n.is(":disabled")),n.prop("disabled",!1)),e.toggleClass("checked",n.is(":checked")),n.hide().removeAttr("class").wrap(e).before(t),e=n.parent(),n.on("change",function(t){if(e.hasClass("disabled"))return t.preventDefault();e.toggleClass("checked",s(this).is(":checked"))}),e.on("click",function(t){if(e.hasClass("disabled"))return t.preventDefault();n.is(":enabled")&&e.hasClass("checked")===n.is(":checked")&&n.click()})),n})},s.fn.tiwl_onoffblock=function(t){var c=s.extend(!0,{},{onEachElm:function(){},isChecked:function(){return s(this).is(":checked")}},t);return s(this).each(function(){function t(){function t(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){c.onEachElm.call(s(n).toggle(i))})}var n=s(this),i=n.attr("tiwl-show"),e=n.attr("tiwl-hide"),o=c.isChecked.call(n);return"string"==typeof i&&t(i,o),"string"==typeof e&&t(e,!o),n}var n=s(this);return n.is("input")&&"checkbox"==n.attr("type")?(s(this).on("change",t),t.call(n)):n})},s.fn.tiwl_byvalueblock=function(t){var i=s.extend(!0,{},{onEachElm:function(){},onClick:function(){return s(this).val()==s(this).attr("tiwl-value")}},t);return s(this).each(function(){function t(e){function t(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){e.onEachElm.call(s(n).toggle(i))})}var n=s(this),i=n.attr("tiwl-show"),o=n.attr("tiwl-hide"),c=e.onClick.call(n);return"string"==typeof i&&t(i,c),"string"==typeof o&&t(o,!c),n}var n=s(this);return n.is("input")||n.is("select")?(s(this).on("change",function(){t.call(this,i)}),t.call(n,i)):n})};var n=new TInvWL(s);s(document).ready(function(){var t;n.Run(),jQuery('input[name="general-show_notice"]').change(function(){var t=!jQuery(this).is(":checked"),n=jQuery('input[name="general-redirect_require_login"]');t&&!n.is(":checked")&&n.click().trigger("change"),n.closest(".tiwlform-onoff-container").toggleClass("disabled",t)}).change(),s(".tablenav").each(function(){var t=s(this);s.trim(t.find(".alignleft").html()).length||t.find(".alignleft").remove(),s.trim(t.find(".alignright").html()).length&&!t.find(".tablenav-pages").hasClass("one-page")||(t.find(".alignright").remove(),t.find(".tinv-wishlist-clear").remove()),s.trim(t.html()).length||t.remove()}),s(".tablenav .bulkactions select").addClass("tinvwl-select grey").wrap('<span class="tinvwl-select-wrap">').parent().append('<span class="tinvwl-caret"><span></span></span>'),s(".tablenav .bulkactions .button.action, .tablenav #search-submit").removeClass("button").addClass("tinvwl-btn grey"),s(".tinvwl-modal-btn").on("click",function(){s(this).next(".tinvwl-modal").addClass("tinvwl-modal-open")}),s(".tinvwl-overlay, .tinvwl-close-modal, .tinvwl_button_close").on("click",function(t){t.preventDefault(),s(this).parents(".tinvwl-modal:first").removeClass("tinvwl-modal-open")}),void 0!==s.fn.popover&&((t=s(".tinvwl-help")).popover({content:function(){return s(this).closest(".tinvwl-info-wrap").find(".tinvwl-info-desc").html()}}),t.on("click",function(){s(this).popover("toggle")}),t.on("focusout",function(){s(this).popover("hide")}),s(window).on("resize",function(){t.popover("hide")})),s("body").on("click",".tinvwl-confirm-reset",function(t){t.preventDefault(),confirm(tinvwl_comfirm.text_comfirm_reset)&&s(this).removeClass("tinvwl-confirm-reset").trigger("click")})}),s(document).on("click",".tinvwl-chat-notice .notice-dismiss",function(t){s.post(tinvwl_comfirm.ajax_url,{action:"tinvwl_admin_chat_notice"})})}(jQuery);
assets/js/public.js CHANGED
@@ -135,6 +135,17 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
135
 
136
  $('body > .tinv-wishlist').append($msg);
137
  FocusTrap('body > .tinv-wishlist');
 
 
 
 
 
 
 
 
 
 
 
138
  $msg.on('click', '.tinv-close-modal, .tinvwl_button_close, .tinv-overlay', function (e) {
139
  e.preventDefault();
140
  $msg.remove();
@@ -142,6 +153,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
142
  if (s.redirectTimer) {
143
  clearTimeout(s.redirectTimer);
144
  }
 
 
 
 
145
  });
146
  },
147
  status: function status(_status) {
135
 
136
  $('body > .tinv-wishlist').append($msg);
137
  FocusTrap('body > .tinv-wishlist');
138
+
139
+ if (!s.redirectTimer) {
140
+ s.removeTimer = window.setTimeout(function () {
141
+ $msg.remove();
142
+
143
+ if (s.redirectTimer) {
144
+ clearTimeout(s.redirectTimer);
145
+ }
146
+ }, 6000);
147
+ }
148
+
149
  $msg.on('click', '.tinv-close-modal, .tinvwl_button_close, .tinv-overlay', function (e) {
150
  e.preventDefault();
151
  $msg.remove();
153
  if (s.redirectTimer) {
154
  clearTimeout(s.redirectTimer);
155
  }
156
+
157
+ if (s.removeTimer) {
158
+ clearTimeout(s.removeTimer);
159
+ }
160
  });
161
  },
162
  status: function status(_status) {
assets/js/public.min.js CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
- * @version 1.41.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
- "use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function showTooltip(t,i){t.setAttribute("class","social social-clipboard tooltipped tooltipped-s"),t.setAttribute("aria-label",i)}function clearTooltip(t){t.currentTarget.setAttribute("class","social social-clipboard "),t.currentTarget.removeAttribute("aria-label")}!function(c){c.fn.tinvwl_to_wishlist=function(t){var i={api_url:window.location.href.split("?")[0],text_create:window.tinvwl_add_to_wishlist.text_create,text_already_in:window.tinvwl_add_to_wishlist.text_already_in,class:{dialogbox:".tinvwl_add_to_select_wishlist",select:".tinvwl_wishlist",newtitle:".tinvwl_new_input",dialogbutton:".tinvwl_button_add"},redirectTimer:null,onPrepareList:function(){},onGetDialogBox:function(){},onPrepareDialogBox:function(){c("body > .tinv-wishlist").length||c("body").append(c("<div>").addClass("tinv-wishlist")),c(this).appendTo("body > .tinv-wishlist")},onCreateWishList:function(t){c(this).append(c("<option>").html(t.title).val(t.ID).toggleClass("tinv_in_wishlist",t.in))},onSelectWishList:function(){},onDialogShow:function(t){c(t).addClass("tinv-modal-open"),c(t).removeClass("ftinvwl-pulse")},onDialogHide:function(t){c(t).removeClass("tinv-modal-open"),c(t).removeClass("ftinvwl-pulse")},onInited:function(){},onClick:function(){if(c(this).is(".disabled-add-wishlist"))return!1;c(this).is(".ftinvwl-animated")&&c(this).addClass("ftinvwl-pulse"),(this.tinvwl_dialog?this.tinvwl_dialog.show_list:e.onActionProduct).call(this)},onPrepareDataAction:function(t,i){c("body").trigger("tinvwl_wishlist_button_clicked",[t,i])},filterProductAlreadyIn:function(t){var t=t||[],o={};return c("form.cart[method=post], .woocommerce-variation-add-to-cart, form.vtajaxform[method=post]").find("input, select").each(function(){var t=c(this).attr("name"),i=c(this).attr("type"),n=c(this).val();("checkbox"!==i&&"radio"!==i||c(this).is(":checked"))&&(o["form"+t]=n)}),o=o.formvariation_id,t.filter(function(t){var i;return"object"===_typeof(t.in)&&"string"==typeof o?(i=parseInt(o),0<=t.in.indexOf(i)):t.in})},onMultiProductAlreadyIn:function(t){var t=t||[],n=(t=e.onPrepareList.call(t)||t,t=e.filterProductAlreadyIn.call(this,t)||t,c(this).parent().parent().find(".already-in").remove(),"");0===t.length||(n=c("<ul>"),c.each(t,function(t,i){n.append(c("<li>").html(c("<a>").html(i.title).attr({href:i.url})).val(i.ID))})),n.length&&c(this).closest(".tinv-modal-inner").find("img").after(c("<div>").addClass("already-in").html(e.text_already_in+" ").append(n))},onAction:{redirect:function(t){e.redirectTimer&&clearTimeout(e.redirectTimer),e.redirectTimer=window.setTimeout(function(){window.location.href=t},4e3)},force_redirect:function(t){window.location.href=t},wishlists:function(t){},msg:function(t){if(!t)return!1;var i,n,o=c(t).eq(0);c("body > .tinv-wishlist").length||c("body").append(c("<div>").addClass("tinv-wishlist")),c("body > .tinv-wishlist").append(o),t=c(t="body > .tinv-wishlist").find("select, input, textarea, button, a").filter(":visible"),i=t.first(),n=t.last(),i.focus().blur(),n.on("keydown",function(t){9!==t.which||t.shiftKey||(t.preventDefault(),i.focus())}),i.on("keydown",function(t){9===t.which&&t.shiftKey&&(t.preventDefault(),n.focus())}),o.on("click",".tinv-close-modal, .tinvwl_button_close, .tinv-overlay",function(t){t.preventDefault(),o.remove(),e.redirectTimer&&clearTimeout(e.redirectTimer)})},status:function(t){c("body").trigger("tinvwl_wishlist_added_status",[this,t])},removed:function(t){},make_remove:function(t){},wishlists_data:function(t){d(JSON.stringify(t))}}},e=(i.onActionProduct=function(t,i){var r={form:{},tinv_wishlist_id:t||"",tinv_wishlist_name:i||"",product_type:c(this).attr("data-tinv-wl-producttype"),product_id:c(this).attr("data-tinv-wl-product")||0,product_variation:c(this).attr("data-tinv-wl-productvariation")||0,product_action:c(this).attr("data-tinv-wl-action")||"addto",redirect:window.location.href},n=this,o=[],d=new FormData;tinvwl_add_to_wishlist.wpml&&(r.lang=tinvwl_add_to_wishlist.wpml),tinvwl_add_to_wishlist.wpml_default&&(r.lang_default=tinvwl_add_to_wishlist.wpml_default),c('form.cart[method=post][data-product_id="'+c(this).attr("data-tinv-wl-product")+'"], form.vtajaxform[method=post][data-product_id="'+c(this).attr("data-tinv-wl-product")+'"]').each(function(){o.push(c(this))}),o.length||(c(n).closest("form.cart[method=post], form.vtajaxform[method=post]").each(function(){o.push(c(this))}),o.length||o.push(c("form.cart[method=post]"))),c('.tinv-wraper[data-product_id="'+c(this).attr("data-tinv-wl-product")+'"]').each(function(){o.push(c(this))}),c.each(o,function(t,i){c(i).find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").each(function(){function e(t,i){if("object"!==_typeof(i))return i;for(var n in void 0===t&&(t={}),i)if(""===n){var o=-1;for(o in t);t[o=parseInt(o)+1]=e(t[n],i[n])}else t[n]=e(t[n],i[n]);return t}var t,i=c(this).attr("name"),n=c(this).attr("type"),o=c(this).val(),l=10;if("button"!==n&&void 0!==i){for(;/^(.+)\[([^\[\]]*?)\]$/.test(i)&&0<l;){var a,s=i.match(/^(.+)\[([^\[\]]*?)\]$/);3===s.length&&((a={})[s[2]]=o,o=a),i=s[1],l--}"file"!==n||(t=c(this)[0].files)&&d.append(i,t[0]),"checkbox"===n||"radio"===n?c(this).is(":checked")&&(o.length||"object"===_typeof(o)||(o=!0),r.form[i]=e(r.form[i],o)):r.form[i]=e(r.form[i],o)}})}),r=e.onPrepareDataAction.call(n,n,r)||r,c.each(r,function(n,t){"form"===n?c.each(t,function(t,i){"object"===_typeof(i)&&(i=JSON.stringify(i)),d.append(n+"["+t+"]",i)}):d.append(n,t)}),c.ajax({url:e.api_url,method:"POST",contentType:!1,processData:!1,data:d}).done(function(t){if(e.onDialogHide.call(n.tinvwl_dialog,n),"object"===_typeof(t))for(var i in t)"function"==typeof e.onAction[i]&&e.onAction[i].call(n,t[i]);else"function"==typeof e.onAction.msg&&e.onAction.msg.call(n,t)})},c.extend(!0,{},i,t));return c(this).each(function(){if(!c(this).attr("data-tinv-wl-list"))return!1;var t,o;e.dialogbox&&e.dialogbox.length&&(this.tinvwl_dialog=e.dialogbox),this.tinvwl_dialog||(this.tinvwl_dialog=e.onGetDialogBox.call(this)),this.tinvwl_dialog||(t=c(this).nextAll(e.class.dialogbox).eq(0)).length&&(this.tinvwl_dialog=t),this.tinvwl_dialog&&(e.onPrepareDialogBox.call(this.tinvwl_dialog),"function"!=typeof this.tinvwl_dialog.update_list&&(this.tinvwl_dialog.update_list=function(t){var n=c(this).find(e.class.select).eq(0);c(this).find(e.class.newtitle).hide().val(""),n.html(""),c.each(t,function(t,i){e.onCreateWishList.call(n,i)}),e.text_create&&e.onCreateWishList.call(n,{ID:"",title:e.text_create,in:!1}),e.onMultiProductAlreadyIn.call(n,t),e.onSelectWishList.call(n,t),c(this).find(e.class.newtitle).toggle(""===n.val())}),"function"!=typeof this.tinvwl_dialog.show_list&&(this.tinvwl_dialog.show_list=function(){var t=JSON.parse(c(this).attr("data-tinv-wl-list"))||[];t.length?(t=e.onPrepareList.call(t)||t,this.tinvwl_dialog.update_list(t),e.onDialogShow.call(this.tinvwl_dialog,this)):e.onActionProduct.call(this)}),c((o=this).tinvwl_dialog).find(e.class.dialogbutton).off("click").on("click",function(){var t,i=c(o.tinvwl_dialog).find(e.class.select),n=c(o.tinvwl_dialog).find(e.class.newtitle);i.val()||n.val()?e.onActionProduct.call(o,i.val(),n.val()):((t=n.is(":visible")?n:i).addClass("empty-name-wishlist"),window.setTimeout(function(){t.removeClass("empty-name-wishlist")},1e3))})),c(this).off("click").on("click",e.onClick),e.onInited.call(this,e)})},c(document).ready(function(){c("body").on("click keydown",".tinvwl_add_to_wishlist_button",function(t){if("keydown"===t.type){var i=void 0!==t.key?t.key:t.keyCode;if(!("Enter"===i||13===i||0<=["Spacebar"," "].indexOf(i)||32===i))return;t.preventDefault()}if(c("body").trigger("tinvwl_add_to_wishlist_button_click",[this]),c(this).is(".disabled-add-wishlist"))return t.preventDefault(),void window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);c(this).is(".inited-add-wishlist")||c(this).tinvwl_to_wishlist({onInited:function(t){c(this).addClass("inited-add-wishlist"),t.onClick.call(this)}})}),c(document).on("hide_variation",".variations_form",function(t){var i=c('.tinvwl_add_to_wishlist_button:not(.tinvwl-loop)[data-tinv-wl-product="'+c(this).data("product_id")+'"]');if(i.attr("data-tinv-wl-productvariation",0),i.length&&i.attr("data-tinv-wl-list")){var n,o=JSON.parse(i.attr("data-tinv-wl-list")),e=!1,l="1"==window.tinvwl_add_to_wishlist.simple_flow;for(n in o)o[n].hasOwnProperty("in")&&Array.isArray(o[n].in)&&-1<(o[n].in||[]).indexOf(0)&&(e=!0);i.toggleClass("tinvwl-product-in-list",e).toggleClass("tinvwl-product-make-remove",e&&l).attr("data-tinv-wl-action",e&&l?"remove":"addto")}i.length&&!tinvwl_add_to_wishlist.allow_parent_variable&&(t.preventDefault(),i.addClass("disabled-add-wishlist"))}),c(document).on("show_variation",".variations_form",function(t,i,n){var o=c('.tinvwl_add_to_wishlist_button:not(.tinvwl-loop)[data-tinv-wl-product="'+c(this).data("product_id")+'"]');if(o.attr("data-tinv-wl-productvariation",i.variation_id),o.length&&o.attr("data-tinv-wl-list")){var e,l=JSON.parse(o.attr("data-tinv-wl-list")),a=!1,s="1"==window.tinvwl_add_to_wishlist.simple_flow;for(e in l)l[e].hasOwnProperty("in")&&Array.isArray(l[e].in)&&-1<(l[e].in||[]).indexOf(i.variation_id)&&(a=!0);o.toggleClass("tinvwl-product-in-list",a).toggleClass("tinvwl-product-make-remove",a&&s).attr("data-tinv-wl-action",a&&s?"remove":"addto")}t.preventDefault(),o.removeClass("disabled-add-wishlist")}),c(window).on("storage onstorage",function(t){s===t.originalEvent.key&&localStorage.getItem(s)!==sessionStorage.getItem(s)&&(!localStorage.getItem(s)||"object"===_typeof(t=JSON.parse(localStorage.getItem(s)))&&null!==t&&(t.hasOwnProperty("products")||t.hasOwnProperty("counter"))&&d(localStorage.getItem(s)))});function i(){if(a&&(tinvwl_add_to_wishlist.update_wishlists_data&&localStorage.setItem(s,""),localStorage.getItem(s))){var t=JSON.parse(localStorage.getItem(s));if("object"===_typeof(t)&&null!==t&&(t.hasOwnProperty("products")||t.hasOwnProperty("counter"))&&(!t.hasOwnProperty("lang")&&!tinvwl_add_to_wishlist.wpml||tinvwl_add_to_wishlist.wpml&&t.lang===tinvwl_add_to_wishlist.wpml))return r(t),0}tinvwl_add_to_wishlist.block_ajax_wishlists_data||(n.length||o)&&(t={},tinvwl_add_to_wishlist.wpml&&(t.lang=tinvwl_add_to_wishlist.wpml),tinvwl_add_to_wishlist.wpml_default&&(t.lang_default=tinvwl_add_to_wishlist.wpml_default),c.ajax({url:tinvwl_add_to_wishlist.plugin_url+"includes/api/ajax.php",method:"POST",data:t,beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",tinvwl_add_to_wishlist.nonce)}}).done(function(t){d(JSON.stringify(t)),r(t)}).fail(function(){e()}))}var n=[],o=!1,e=(c("a.tinvwl_add_to_wishlist_button").each(function(){"undefined"!==c(this).data("tinv-wl-product")&&c(this).data("tinv-wl-product")&&n.push(c(this).data("tinv-wl-product"))}),c(".wishlist_products_counter_number").each(function(){o=!0}),function(){var t;(n.length||o)&&(t={ids:n,counter:o,tinvwl_request:!0},tinvwl_add_to_wishlist.wpml&&(t.lang=tinvwl_add_to_wishlist.wpml),tinvwl_add_to_wishlist.wpml_default&&(t.lang_default=tinvwl_add_to_wishlist.wpml_default),c.ajax({url:tinvwl_add_to_wishlist.rest_root+"wishlist/v1/products",method:"POST",data:t,beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",tinvwl_add_to_wishlist.nonce)}}).done(function(t){d(JSON.stringify(t)),r(t)}))}),t=(i(),new MutationObserver(function(t){n=[],t.forEach(function(t){t=t.addedNodes;null!==t&&c(t).each(function(){var t=c(this).find(".tinvwl_add_to_wishlist_button");t.length&&t.each(function(){"undefined"!==c(this).data("tinv-wl-product")&&c(this).data("tinv-wl-product")&&n.push(c(this).data("tinv-wl-product"))})})}),n.length&&i()})),l=document.body;t.observe(l,{childList:!0,subtree:!0})});var a=!0,s=tinvwl_add_to_wishlist.hash_key;try{a="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("ti","test"),window.sessionStorage.removeItem("ti"),window.localStorage.setItem("ti","test"),window.localStorage.removeItem("ti")}catch(t){a=!1}function r(t){var a="1"==window.tinvwl_add_to_wishlist.simple_flow,t=(a&&c("a.tinvwl_add_to_wishlist_button").each(function(){c(this).removeClass("tinvwl-product-make-remove").removeClass("tinvwl-product-already-on-wishlist").removeClass("tinvwl-product-in-list").attr("data-tinv-wl-action","addto").attr("data-tinv-wl-list","[]")}),c("body").trigger("tinvwl_wishlist_mark_products",[t]),c.each(t.products,function(t,e){var l=t;c('a.tinvwl_add_to_wishlist_button[data-tinv-wl-product="'+l+'"]').each(function(){var i,t=parseInt(c(this).attr("data-tinv-wl-productvariation")),n=c(this).data("tinv-wl-productvariations")||[],o=!1;for(i in e)e[i].hasOwnProperty("in")&&Array.isArray(e[i].in)&&(-1<(e[i].in||[]).indexOf(l)||-1<(e[i].in||[]).indexOf(t)||n.some(function(t){return 0<=(e[i].in||[]).indexOf(t)}))&&(o=!0);c("body").trigger("tinvwl_wishlist_product_marked",[this,o]),c(this).attr("data-tinv-wl-list",JSON.stringify(e)).toggleClass("tinvwl-product-in-list",o).toggleClass("tinvwl-product-make-remove",o&&a).attr("data-tinv-wl-action",o&&a?"remove":"addto")})}),t.counter);"1"==window.tinvwl_add_to_wishlist.hide_zero_counter&&0===t&&(t="false"),jQuery("i.wishlist-icon").addClass("added"),"false"!==t?(jQuery(".wishlist_products_counter_number, body.theme-woostify .wishlist-item-count").html(t),jQuery("i.wishlist-icon").attr("data-icon-label",t)):(jQuery(".wishlist_products_counter_number, body.theme-woostify .wishlist-item-count").html("").closest("span.wishlist-counter-with-products").removeClass("wishlist-counter-with-products"),jQuery("i.wishlist-icon").removeAttr("data-icon-label")),t=!("0"==t||"false"==t),jQuery(".wishlist_products_counter").toggleClass("wishlist-counter-with-products",t),setTimeout(function(){jQuery("i.wishlist-icon").removeClass("added")},500)}function d(t){a&&(localStorage.setItem(s,t),sessionStorage.setItem(s,t),r(JSON.parse(t)))}}(jQuery),function(o){o(document).ready(function(){if(o("#tinvwl_manage_actions, #tinvwl_product_actions").addClass("form-control").parent().wrapInner('<div class="tinvwl-input-group tinvwl-no-full">').find("button").wrap('<span class="tinvwl-input-group-btn">'),o(".tinv-lists-nav").each(function(){o(this).html().trim().length||o(this).remove()}),o("body").on("click",".social-buttons .social:not(.social-email,.social-whatsapp,.social-clipboard)",function(t){var i=window.open(o(this).attr("href"),o(this).attr("title"),"width=420,height=320,resizable=yes,scrollbars=yes,status=yes");i&&(i.focus(),t.preventDefault())}),"undefined"!=typeof ClipboardJS){new ClipboardJS(".social-buttons .social.social-clipboard",{text:function(t){return t.getAttribute("href")}}).on("success",function(t){showTooltip(t.trigger,tinvwl_add_to_wishlist.tinvwl_clipboard)});for(var t=document.querySelectorAll(".social-buttons .social.social-clipboard"),i=0;i<t.length;i++)t[i].addEventListener("mouseleave",clearTooltip),t[i].addEventListener("blur",clearTooltip)}o("body").on("click",".social-buttons .social.social-clipboard",function(t){t.preventDefault()}),o("body").on("click",".tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close",function(t){t.preventDefault(),o(this).parents(".tinv-modal:first").removeClass("tinv-modal-open"),o("body").trigger("tinvwl_modal_closed",[this])}),o("body").on("click",".tinv-wishlist .tinvwl-btn-onclick",function(t){o(this).data("url")&&(t.preventDefault(),window.location=o(this).data("url"))});var n=o(".tinv-wishlist .navigation-button");n.length&&n.each(function(){var t=o(this).find("> li");t.length<5&&t.parent().addClass("tinvwl-btns-count-"+t.length)}),o(".tinv-login .showlogin").off("click").on("click",function(t){t.preventDefault(),o(this).closest(".tinv-login").find(".login").toggle()}),o(".tinv-wishlist table.tinvwl-table-manage-list tfoot td").each(function(){o(this).toggle(!!o(this).children().not(".look_in").length||!!o(this).children(".look_in").children().length)})})}(jQuery),function(o){o.fn.tinvwl_break_submit=function(t){var n=o.extend(!0,{},{selector:"input, select, textarea",ifempty:!0,invert:!1,validate:function(){return o(this).val()},rule:function(){var t=o(this).parents("form").eq(0).find(n.selector),i=n.invert;return 0===t.length?n.ifempty:(t.each(function(){i&&!n.invert||!i&&n.invert||(i=Boolean(n.validate.call(o(this))))}),i)}},t);return o(this).each(function(){o(this).on("click",function(t){var i=[];void 0!==o(this).attr("tinvwl_break_submit")&&(i=o(this).attr("tinvwl_break_submit").split(",")),-1!==jQuery.inArray(n.selector,i)&&(i=[]),n.rule.call(o(this))||0!==i.length||(alert(window.tinvwl_add_to_wishlist.tinvwl_break_submit),t.preventDefault()),i.push(n.selector),o(this).attr("tinvwl_break_submit",i),n.rule.call(o(this))&&o(this).removeAttr("tinvwl_break_submit")})})},o(document).ready(function(){o(".tinvwl-break-input").tinvwl_break_submit({selector:".tinvwl-break-input-filed"}),o(".tinvwl-break-checkbox").tinvwl_break_submit({selector:"table td input[type=checkbox]",validate:function(){return o(this).is(":checked")}}),o(".global-cb").on("click",function(){o(this).closest("table").eq(0).find(".product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]").prop("checked",o(this).is(":checked"))})})}(jQuery);
1
  /**
2
  * TI WooCommerce Wishlist Plugin - Allow your store guests and customers to add products to Wishlist. Add Wishlist functionality to your store for free.
3
+ * @version 1.41.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
+ "use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function showTooltip(t,i){t.setAttribute("class","social social-clipboard tooltipped tooltipped-s"),t.setAttribute("aria-label",i)}function clearTooltip(t){t.currentTarget.setAttribute("class","social social-clipboard "),t.currentTarget.removeAttribute("aria-label")}!function(c){c.fn.tinvwl_to_wishlist=function(t){var i={api_url:window.location.href.split("?")[0],text_create:window.tinvwl_add_to_wishlist.text_create,text_already_in:window.tinvwl_add_to_wishlist.text_already_in,class:{dialogbox:".tinvwl_add_to_select_wishlist",select:".tinvwl_wishlist",newtitle:".tinvwl_new_input",dialogbutton:".tinvwl_button_add"},redirectTimer:null,onPrepareList:function(){},onGetDialogBox:function(){},onPrepareDialogBox:function(){c("body > .tinv-wishlist").length||c("body").append(c("<div>").addClass("tinv-wishlist")),c(this).appendTo("body > .tinv-wishlist")},onCreateWishList:function(t){c(this).append(c("<option>").html(t.title).val(t.ID).toggleClass("tinv_in_wishlist",t.in))},onSelectWishList:function(){},onDialogShow:function(t){c(t).addClass("tinv-modal-open"),c(t).removeClass("ftinvwl-pulse")},onDialogHide:function(t){c(t).removeClass("tinv-modal-open"),c(t).removeClass("ftinvwl-pulse")},onInited:function(){},onClick:function(){if(c(this).is(".disabled-add-wishlist"))return!1;c(this).is(".ftinvwl-animated")&&c(this).addClass("ftinvwl-pulse"),(this.tinvwl_dialog?this.tinvwl_dialog.show_list:e.onActionProduct).call(this)},onPrepareDataAction:function(t,i){c("body").trigger("tinvwl_wishlist_button_clicked",[t,i])},filterProductAlreadyIn:function(t){var t=t||[],o={};return c("form.cart[method=post], .woocommerce-variation-add-to-cart, form.vtajaxform[method=post]").find("input, select").each(function(){var t=c(this).attr("name"),i=c(this).attr("type"),n=c(this).val();("checkbox"!==i&&"radio"!==i||c(this).is(":checked"))&&(o["form"+t]=n)}),o=o.formvariation_id,t.filter(function(t){var i;return"object"===_typeof(t.in)&&"string"==typeof o?(i=parseInt(o),0<=t.in.indexOf(i)):t.in})},onMultiProductAlreadyIn:function(t){var t=t||[],n=(t=e.onPrepareList.call(t)||t,t=e.filterProductAlreadyIn.call(this,t)||t,c(this).parent().parent().find(".already-in").remove(),"");0===t.length||(n=c("<ul>"),c.each(t,function(t,i){n.append(c("<li>").html(c("<a>").html(i.title).attr({href:i.url})).val(i.ID))})),n.length&&c(this).closest(".tinv-modal-inner").find("img").after(c("<div>").addClass("already-in").html(e.text_already_in+" ").append(n))},onAction:{redirect:function(t){e.redirectTimer&&clearTimeout(e.redirectTimer),e.redirectTimer=window.setTimeout(function(){window.location.href=t},4e3)},force_redirect:function(t){window.location.href=t},wishlists:function(t){},msg:function(t){if(!t)return!1;var i,n,o=c(t).eq(0);c("body > .tinv-wishlist").length||c("body").append(c("<div>").addClass("tinv-wishlist")),c("body > .tinv-wishlist").append(o),t=c(t="body > .tinv-wishlist").find("select, input, textarea, button, a").filter(":visible"),i=t.first(),n=t.last(),i.focus().blur(),n.on("keydown",function(t){9!==t.which||t.shiftKey||(t.preventDefault(),i.focus())}),i.on("keydown",function(t){9===t.which&&t.shiftKey&&(t.preventDefault(),n.focus())}),e.redirectTimer||(e.removeTimer=window.setTimeout(function(){o.remove(),e.redirectTimer&&clearTimeout(e.redirectTimer)},6e3)),o.on("click",".tinv-close-modal, .tinvwl_button_close, .tinv-overlay",function(t){t.preventDefault(),o.remove(),e.redirectTimer&&clearTimeout(e.redirectTimer),e.removeTimer&&clearTimeout(e.removeTimer)})},status:function(t){c("body").trigger("tinvwl_wishlist_added_status",[this,t])},removed:function(t){},make_remove:function(t){},wishlists_data:function(t){d(JSON.stringify(t))}}},e=(i.onActionProduct=function(t,i){var r={form:{},tinv_wishlist_id:t||"",tinv_wishlist_name:i||"",product_type:c(this).attr("data-tinv-wl-producttype"),product_id:c(this).attr("data-tinv-wl-product")||0,product_variation:c(this).attr("data-tinv-wl-productvariation")||0,product_action:c(this).attr("data-tinv-wl-action")||"addto",redirect:window.location.href},n=this,o=[],d=new FormData;tinvwl_add_to_wishlist.wpml&&(r.lang=tinvwl_add_to_wishlist.wpml),tinvwl_add_to_wishlist.wpml_default&&(r.lang_default=tinvwl_add_to_wishlist.wpml_default),c('form.cart[method=post][data-product_id="'+c(this).attr("data-tinv-wl-product")+'"], form.vtajaxform[method=post][data-product_id="'+c(this).attr("data-tinv-wl-product")+'"]').each(function(){o.push(c(this))}),o.length||(c(n).closest("form.cart[method=post], form.vtajaxform[method=post]").each(function(){o.push(c(this))}),o.length||o.push(c("form.cart[method=post]"))),c('.tinv-wraper[data-product_id="'+c(this).attr("data-tinv-wl-product")+'"]').each(function(){o.push(c(this))}),c.each(o,function(t,i){c(i).find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").each(function(){function e(t,i){if("object"!==_typeof(i))return i;for(var n in void 0===t&&(t={}),i)if(""===n){var o=-1;for(o in t);t[o=parseInt(o)+1]=e(t[n],i[n])}else t[n]=e(t[n],i[n]);return t}var t,i=c(this).attr("name"),n=c(this).attr("type"),o=c(this).val(),l=10;if("button"!==n&&void 0!==i){for(;/^(.+)\[([^\[\]]*?)\]$/.test(i)&&0<l;){var a,s=i.match(/^(.+)\[([^\[\]]*?)\]$/);3===s.length&&((a={})[s[2]]=o,o=a),i=s[1],l--}"file"!==n||(t=c(this)[0].files)&&d.append(i,t[0]),"checkbox"===n||"radio"===n?c(this).is(":checked")&&(o.length||"object"===_typeof(o)||(o=!0),r.form[i]=e(r.form[i],o)):r.form[i]=e(r.form[i],o)}})}),r=e.onPrepareDataAction.call(n,n,r)||r,c.each(r,function(n,t){"form"===n?c.each(t,function(t,i){"object"===_typeof(i)&&(i=JSON.stringify(i)),d.append(n+"["+t+"]",i)}):d.append(n,t)}),c.ajax({url:e.api_url,method:"POST",contentType:!1,processData:!1,data:d}).done(function(t){if(e.onDialogHide.call(n.tinvwl_dialog,n),"object"===_typeof(t))for(var i in t)"function"==typeof e.onAction[i]&&e.onAction[i].call(n,t[i]);else"function"==typeof e.onAction.msg&&e.onAction.msg.call(n,t)})},c.extend(!0,{},i,t));return c(this).each(function(){if(!c(this).attr("data-tinv-wl-list"))return!1;var t,o;e.dialogbox&&e.dialogbox.length&&(this.tinvwl_dialog=e.dialogbox),this.tinvwl_dialog||(this.tinvwl_dialog=e.onGetDialogBox.call(this)),this.tinvwl_dialog||(t=c(this).nextAll(e.class.dialogbox).eq(0)).length&&(this.tinvwl_dialog=t),this.tinvwl_dialog&&(e.onPrepareDialogBox.call(this.tinvwl_dialog),"function"!=typeof this.tinvwl_dialog.update_list&&(this.tinvwl_dialog.update_list=function(t){var n=c(this).find(e.class.select).eq(0);c(this).find(e.class.newtitle).hide().val(""),n.html(""),c.each(t,function(t,i){e.onCreateWishList.call(n,i)}),e.text_create&&e.onCreateWishList.call(n,{ID:"",title:e.text_create,in:!1}),e.onMultiProductAlreadyIn.call(n,t),e.onSelectWishList.call(n,t),c(this).find(e.class.newtitle).toggle(""===n.val())}),"function"!=typeof this.tinvwl_dialog.show_list&&(this.tinvwl_dialog.show_list=function(){var t=JSON.parse(c(this).attr("data-tinv-wl-list"))||[];t.length?(t=e.onPrepareList.call(t)||t,this.tinvwl_dialog.update_list(t),e.onDialogShow.call(this.tinvwl_dialog,this)):e.onActionProduct.call(this)}),c((o=this).tinvwl_dialog).find(e.class.dialogbutton).off("click").on("click",function(){var t,i=c(o.tinvwl_dialog).find(e.class.select),n=c(o.tinvwl_dialog).find(e.class.newtitle);i.val()||n.val()?e.onActionProduct.call(o,i.val(),n.val()):((t=n.is(":visible")?n:i).addClass("empty-name-wishlist"),window.setTimeout(function(){t.removeClass("empty-name-wishlist")},1e3))})),c(this).off("click").on("click",e.onClick),e.onInited.call(this,e)})},c(document).ready(function(){c("body").on("click keydown",".tinvwl_add_to_wishlist_button",function(t){if("keydown"===t.type){var i=void 0!==t.key?t.key:t.keyCode;if(!("Enter"===i||13===i||0<=["Spacebar"," "].indexOf(i)||32===i))return;t.preventDefault()}if(c("body").trigger("tinvwl_add_to_wishlist_button_click",[this]),c(this).is(".disabled-add-wishlist"))return t.preventDefault(),void window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);c(this).is(".inited-add-wishlist")||c(this).tinvwl_to_wishlist({onInited:function(t){c(this).addClass("inited-add-wishlist"),t.onClick.call(this)}})}),c(document).on("hide_variation",".variations_form",function(t){var i=c('.tinvwl_add_to_wishlist_button:not(.tinvwl-loop)[data-tinv-wl-product="'+c(this).data("product_id")+'"]');if(i.attr("data-tinv-wl-productvariation",0),i.length&&i.attr("data-tinv-wl-list")){var n,o=JSON.parse(i.attr("data-tinv-wl-list")),e=!1,l="1"==window.tinvwl_add_to_wishlist.simple_flow;for(n in o)o[n].hasOwnProperty("in")&&Array.isArray(o[n].in)&&-1<(o[n].in||[]).indexOf(0)&&(e=!0);i.toggleClass("tinvwl-product-in-list",e).toggleClass("tinvwl-product-make-remove",e&&l).attr("data-tinv-wl-action",e&&l?"remove":"addto")}i.length&&!tinvwl_add_to_wishlist.allow_parent_variable&&(t.preventDefault(),i.addClass("disabled-add-wishlist"))}),c(document).on("show_variation",".variations_form",function(t,i,n){var o=c('.tinvwl_add_to_wishlist_button:not(.tinvwl-loop)[data-tinv-wl-product="'+c(this).data("product_id")+'"]');if(o.attr("data-tinv-wl-productvariation",i.variation_id),o.length&&o.attr("data-tinv-wl-list")){var e,l=JSON.parse(o.attr("data-tinv-wl-list")),a=!1,s="1"==window.tinvwl_add_to_wishlist.simple_flow;for(e in l)l[e].hasOwnProperty("in")&&Array.isArray(l[e].in)&&-1<(l[e].in||[]).indexOf(i.variation_id)&&(a=!0);o.toggleClass("tinvwl-product-in-list",a).toggleClass("tinvwl-product-make-remove",a&&s).attr("data-tinv-wl-action",a&&s?"remove":"addto")}t.preventDefault(),o.removeClass("disabled-add-wishlist")}),c(window).on("storage onstorage",function(t){s===t.originalEvent.key&&localStorage.getItem(s)!==sessionStorage.getItem(s)&&(!localStorage.getItem(s)||"object"===_typeof(t=JSON.parse(localStorage.getItem(s)))&&null!==t&&(t.hasOwnProperty("products")||t.hasOwnProperty("counter"))&&d(localStorage.getItem(s)))});function i(){if(a&&(tinvwl_add_to_wishlist.update_wishlists_data&&localStorage.setItem(s,""),localStorage.getItem(s))){var t=JSON.parse(localStorage.getItem(s));if("object"===_typeof(t)&&null!==t&&(t.hasOwnProperty("products")||t.hasOwnProperty("counter"))&&(!t.hasOwnProperty("lang")&&!tinvwl_add_to_wishlist.wpml||tinvwl_add_to_wishlist.wpml&&t.lang===tinvwl_add_to_wishlist.wpml))return r(t),0}tinvwl_add_to_wishlist.block_ajax_wishlists_data||(n.length||o)&&(t={},tinvwl_add_to_wishlist.wpml&&(t.lang=tinvwl_add_to_wishlist.wpml),tinvwl_add_to_wishlist.wpml_default&&(t.lang_default=tinvwl_add_to_wishlist.wpml_default),c.ajax({url:tinvwl_add_to_wishlist.plugin_url+"includes/api/ajax.php",method:"POST",data:t,beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",tinvwl_add_to_wishlist.nonce)}}).done(function(t){d(JSON.stringify(t)),r(t)}).fail(function(){e()}))}var n=[],o=!1,e=(c("a.tinvwl_add_to_wishlist_button").each(function(){"undefined"!==c(this).data("tinv-wl-product")&&c(this).data("tinv-wl-product")&&n.push(c(this).data("tinv-wl-product"))}),c(".wishlist_products_counter_number").each(function(){o=!0}),function(){var t;(n.length||o)&&(t={ids:n,counter:o,tinvwl_request:!0},tinvwl_add_to_wishlist.wpml&&(t.lang=tinvwl_add_to_wishlist.wpml),tinvwl_add_to_wishlist.wpml_default&&(t.lang_default=tinvwl_add_to_wishlist.wpml_default),c.ajax({url:tinvwl_add_to_wishlist.rest_root+"wishlist/v1/products",method:"POST",data:t,beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",tinvwl_add_to_wishlist.nonce)}}).done(function(t){d(JSON.stringify(t)),r(t)}))}),t=(i(),new MutationObserver(function(t){n=[],t.forEach(function(t){t=t.addedNodes;null!==t&&c(t).each(function(){var t=c(this).find(".tinvwl_add_to_wishlist_button");t.length&&t.each(function(){"undefined"!==c(this).data("tinv-wl-product")&&c(this).data("tinv-wl-product")&&n.push(c(this).data("tinv-wl-product"))})})}),n.length&&i()})),l=document.body;t.observe(l,{childList:!0,subtree:!0})});var a=!0,s=tinvwl_add_to_wishlist.hash_key;try{a="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("ti","test"),window.sessionStorage.removeItem("ti"),window.localStorage.setItem("ti","test"),window.localStorage.removeItem("ti")}catch(t){a=!1}function r(t){var a="1"==window.tinvwl_add_to_wishlist.simple_flow,t=(a&&c("a.tinvwl_add_to_wishlist_button").each(function(){c(this).removeClass("tinvwl-product-make-remove").removeClass("tinvwl-product-already-on-wishlist").removeClass("tinvwl-product-in-list").attr("data-tinv-wl-action","addto").attr("data-tinv-wl-list","[]")}),c("body").trigger("tinvwl_wishlist_mark_products",[t]),c.each(t.products,function(t,e){var l=t;c('a.tinvwl_add_to_wishlist_button[data-tinv-wl-product="'+l+'"]').each(function(){var i,t=parseInt(c(this).attr("data-tinv-wl-productvariation")),n=c(this).data("tinv-wl-productvariations")||[],o=!1;for(i in e)e[i].hasOwnProperty("in")&&Array.isArray(e[i].in)&&(-1<(e[i].in||[]).indexOf(l)||-1<(e[i].in||[]).indexOf(t)||n.some(function(t){return 0<=(e[i].in||[]).indexOf(t)}))&&(o=!0);c("body").trigger("tinvwl_wishlist_product_marked",[this,o]),c(this).attr("data-tinv-wl-list",JSON.stringify(e)).toggleClass("tinvwl-product-in-list",o).toggleClass("tinvwl-product-make-remove",o&&a).attr("data-tinv-wl-action",o&&a?"remove":"addto")})}),t.counter);"1"==window.tinvwl_add_to_wishlist.hide_zero_counter&&0===t&&(t="false"),jQuery("i.wishlist-icon").addClass("added"),"false"!==t?(jQuery(".wishlist_products_counter_number, body.theme-woostify .wishlist-item-count").html(t),jQuery("i.wishlist-icon").attr("data-icon-label",t)):(jQuery(".wishlist_products_counter_number, body.theme-woostify .wishlist-item-count").html("").closest("span.wishlist-counter-with-products").removeClass("wishlist-counter-with-products"),jQuery("i.wishlist-icon").removeAttr("data-icon-label")),t=!("0"==t||"false"==t),jQuery(".wishlist_products_counter").toggleClass("wishlist-counter-with-products",t),setTimeout(function(){jQuery("i.wishlist-icon").removeClass("added")},500)}function d(t){a&&(localStorage.setItem(s,t),sessionStorage.setItem(s,t),r(JSON.parse(t)))}}(jQuery),function(o){o(document).ready(function(){if(o("#tinvwl_manage_actions, #tinvwl_product_actions").addClass("form-control").parent().wrapInner('<div class="tinvwl-input-group tinvwl-no-full">').find("button").wrap('<span class="tinvwl-input-group-btn">'),o(".tinv-lists-nav").each(function(){o(this).html().trim().length||o(this).remove()}),o("body").on("click",".social-buttons .social:not(.social-email,.social-whatsapp,.social-clipboard)",function(t){var i=window.open(o(this).attr("href"),o(this).attr("title"),"width=420,height=320,resizable=yes,scrollbars=yes,status=yes");i&&(i.focus(),t.preventDefault())}),"undefined"!=typeof ClipboardJS){new ClipboardJS(".social-buttons .social.social-clipboard",{text:function(t){return t.getAttribute("href")}}).on("success",function(t){showTooltip(t.trigger,tinvwl_add_to_wishlist.tinvwl_clipboard)});for(var t=document.querySelectorAll(".social-buttons .social.social-clipboard"),i=0;i<t.length;i++)t[i].addEventListener("mouseleave",clearTooltip),t[i].addEventListener("blur",clearTooltip)}o("body").on("click",".social-buttons .social.social-clipboard",function(t){t.preventDefault()}),o("body").on("click",".tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close",function(t){t.preventDefault(),o(this).parents(".tinv-modal:first").removeClass("tinv-modal-open"),o("body").trigger("tinvwl_modal_closed",[this])}),o("body").on("click",".tinv-wishlist .tinvwl-btn-onclick",function(t){o(this).data("url")&&(t.preventDefault(),window.location=o(this).data("url"))});var n=o(".tinv-wishlist .navigation-button");n.length&&n.each(function(){var t=o(this).find("> li");t.length<5&&t.parent().addClass("tinvwl-btns-count-"+t.length)}),o(".tinv-login .showlogin").off("click").on("click",function(t){t.preventDefault(),o(this).closest(".tinv-login").find(".login").toggle()}),o(".tinv-wishlist table.tinvwl-table-manage-list tfoot td").each(function(){o(this).toggle(!!o(this).children().not(".look_in").length||!!o(this).children(".look_in").children().length)})})}(jQuery),function(o){o.fn.tinvwl_break_submit=function(t){var n=o.extend(!0,{},{selector:"input, select, textarea",ifempty:!0,invert:!1,validate:function(){return o(this).val()},rule:function(){var t=o(this).parents("form").eq(0).find(n.selector),i=n.invert;return 0===t.length?n.ifempty:(t.each(function(){i&&!n.invert||!i&&n.invert||(i=Boolean(n.validate.call(o(this))))}),i)}},t);return o(this).each(function(){o(this).on("click",function(t){var i=[];void 0!==o(this).attr("tinvwl_break_submit")&&(i=o(this).attr("tinvwl_break_submit").split(",")),-1!==jQuery.inArray(n.selector,i)&&(i=[]),n.rule.call(o(this))||0!==i.length||(alert(window.tinvwl_add_to_wishlist.tinvwl_break_submit),t.preventDefault()),i.push(n.selector),o(this).attr("tinvwl_break_submit",i),n.rule.call(o(this))&&o(this).removeAttr("tinvwl_break_submit")})})},o(document).ready(function(){o(".tinvwl-break-input").tinvwl_break_submit({selector:".tinvwl-break-input-filed"}),o(".tinvwl-break-checkbox").tinvwl_break_submit({selector:"table td input[type=checkbox]",validate:function(){return o(this).is(":checked")}}),o(".global-cb").on("click",function(){o(this).closest("table").eq(0).find(".product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]").prop("checked",o(this).is(":checked"))})})}(jQuery);
includes/api/ajax.php CHANGED
@@ -179,7 +179,7 @@ JOIN {$table_languages} l ON
179
  $sql .= ' WHERE ' . $where;
180
  }
181
 
182
- $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
183
 
184
  if ( ! empty( $default['sql'] ) ) {
185
  $replacer = $replace = array();
@@ -242,5 +242,4 @@ if ( $lang_default ) {
242
  $response['lang_default'] = $lang_default;
243
  }
244
 
245
-
246
  wp_send_json( $response );
179
  $sql .= ' WHERE ' . $where;
180
  }
181
 
182
+ $sql .= sprintf( ' GROUP BY `%s`.ID ORDER BY `%s` %s LIMIT %d,%d;', $table, $default['order_by'], $default['order'], $default['offset'], $default['count'] );
183
 
184
  if ( ! empty( $default['sql'] ) ) {
185
  $replacer = $replace = array();
242
  $response['lang_default'] = $lang_default;
243
  }
244
 
 
245
  wp_send_json( $response );
includes/product.helper.php CHANGED
@@ -7,15 +7,14 @@
7
  */
8
 
9
  // If this file is called directly, abort.
10
- if (!defined('ABSPATH')) {
11
  die;
12
  }
13
 
14
  /**
15
  * Product function class
16
  */
17
- class TInvWL_Product
18
- {
19
 
20
  /**
21
  * Table name
@@ -51,22 +50,21 @@ class TInvWL_Product
51
  * @global wpdb $wpdb
52
  *
53
  */
54
- function __construct($wishlist = array(), $plugin_name = TINVWL_PREFIX)
55
- {
56
  global $wpdb;
57
 
58
- $this->wishlist = (array)$wishlist;
59
- $this->_name = $plugin_name;
60
- $this->table = sprintf('%s%s_%s', $wpdb->prefix, $this->_name, 'items');
61
- $this->user = $this->wishlist_author();
62
- if (empty($this->user)) {
63
  $user = wp_get_current_user();
64
- if ($user->exists()) {
65
  $this->user = $user->ID;
66
  }
67
  }
68
 
69
- add_filter('tinvwl_addtowishlist_add_form', array($this, 'clean_meta'), 10, 1);
70
  }
71
 
72
  /**
@@ -74,9 +72,8 @@ class TInvWL_Product
74
  *
75
  * @return int
76
  */
77
- function wishlist_id()
78
- {
79
- if (is_array($this->wishlist) && array_key_exists('ID', $this->wishlist)) {
80
  return $this->wishlist['ID'];
81
  }
82
 
@@ -88,9 +85,8 @@ class TInvWL_Product
88
  *
89
  * @return int
90
  */
91
- function wishlist_author()
92
- {
93
- if (is_array($this->wishlist) && array_key_exists('author', $this->wishlist)) {
94
  return $this->wishlist['author'];
95
  }
96
 
@@ -105,28 +101,27 @@ class TInvWL_Product
105
  *
106
  * @return boolean
107
  */
108
- function add_product($data = array(), $meta = array())
109
- {
110
- $_data = filter_var_array($data, array(
111
- 'product_id' => FILTER_VALIDATE_INT,
112
  'variation_id' => FILTER_VALIDATE_INT,
113
- 'wishlist_id' => FILTER_VALIDATE_INT,
114
- 'quantity' => FILTER_VALIDATE_INT,
115
- ));
116
- if (empty($_data['quantity'])) {
117
  $_data['quantity'] = 1;
118
  }
119
- if (empty($_data['wishlist_id'])) {
120
  $_data['wishlist_id'] = $this->wishlist_id();
121
  }
122
- $product_data = $this->check_product($_data['product_id'], $_data['variation_id'], $_data['wishlist_id'], $meta);
123
- if (false === $product_data) {
124
  return false;
125
  }
126
- if ($product_data) {
127
- return $this->update($data, $meta, $product_data['ID']);
128
  } else {
129
- return $this->add($data, $meta);
130
  }
131
  }
132
 
@@ -140,65 +135,64 @@ class TInvWL_Product
140
  * @global wpdb $wpdb
141
  *
142
  */
143
- function add($data = array(), $meta = array())
144
- {
145
 
146
  $default = array(
147
- 'wishlist_id' => $this->wishlist_id(),
148
- 'product_id' => 0,
149
  'variation_id' => 0,
150
- 'formdata' => '',
151
- 'author' => $this->user,
152
- 'date' => current_time('Y-m-d H:i:s'),
153
- 'quantity' => 1,
154
- 'price' => 0,
155
- 'in_stock' => 1,
156
  );
157
- $data = filter_var_array($data, apply_filters('tinvwl_wishlist_product_add_field', array(
158
- 'author' => FILTER_VALIDATE_INT,
159
- 'product_id' => FILTER_VALIDATE_INT,
160
- 'quantity' => FILTER_VALIDATE_INT,
161
  'variation_id' => FILTER_VALIDATE_INT,
162
- 'wishlist_id' => FILTER_VALIDATE_INT,
163
- )));
164
- $data = array_filter($data);
165
 
166
- $data = tinv_array_merge($default, $data);
167
 
168
- if (empty($data['wishlist_id']) || empty($data['product_id'])) {
169
  return false;
170
  }
171
 
172
- $product_data = $this->product_data($data['product_id'], $data['variation_id']);
173
 
174
- if ($data['quantity'] <= 0 || !$product_data) {
175
  return false;
176
  }
177
 
178
- if ($product_data->is_sold_individually()) {
179
  $data['quantity'] = 1;
180
  }
181
 
182
- $data = apply_filters('tinvwl_wishlist_product_add', $data);
183
  $data['in_stock'] = $product_data->is_in_stock();
184
 
185
- $data['formdata'] = $this->prepare_save_meta($meta, $data['product_id'], $data['variation_id']);
186
 
187
- if ($product_data->is_type('variable')) {
188
- $data['price'] = filter_var($product_data->get_variation_price('max', false), FILTER_VALIDATE_FLOAT);
189
  } else {
190
- $data['price'] = filter_var(($product_data->get_price()), FILTER_VALIDATE_FLOAT);
191
  }
192
 
193
  global $wpdb;
194
- if ($wpdb->insert($this->table, $data)) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
195
  $id = $wpdb->insert_id;
196
 
197
  /* Run a 3rd party code when product added to a wishlist.
198
  *
199
  * @param array $data product data including author and wishlist IDs.
200
  * */
201
- do_action('tinvwl_product_added', $data);
202
 
203
  return $id;
204
  }
@@ -213,16 +207,15 @@ class TInvWL_Product
213
  *
214
  * @return array
215
  */
216
- function get_wishlist($data = array(), $count = false)
217
- {
218
- if (!array_key_exists('wishlist_id', $data)) {
219
  $data['wishlist_id'] = $this->wishlist_id();
220
  }
221
- if (empty($data['wishlist_id'])) {
222
  return array();
223
  }
224
 
225
- return $this->get($data, $count);
226
  }
227
 
228
  /**
@@ -235,38 +228,37 @@ class TInvWL_Product
235
  *
236
  * @return mixed
237
  */
238
- function check_product($product_id, $variation_id = 0, $wishlist_id = 0, $meta = array())
239
- {
240
- $product_id = absint($product_id);
241
- $variation_id = absint($variation_id);
242
- $wishlist_id = absint($wishlist_id);
243
 
244
- if (empty($wishlist_id)) {
245
  $wishlist_id = $this->wishlist_id();
246
  }
247
- if (empty($wishlist_id) || empty($product_id)) {
248
  return false;
249
  }
250
 
251
- $product_data = $this->product_data($product_id, $variation_id);
252
 
253
- if (!$product_data) {
254
  return false;
255
  }
256
 
257
- $product_id = $product_data->is_type('variation') ? $product_data->get_parent_id() : $product_data->get_id();
258
- $variation_id = $product_data->is_type('variation') ? $product_data->get_id() : 0;
259
 
260
- $products = $this->get(array(
261
- 'product_id' => $product_id,
262
  'variation_id' => $variation_id,
263
- 'wishlist_id' => $wishlist_id,
264
- 'formdata' => $this->prepare_save_meta($meta, $product_id, $variation_id),
265
- 'count' => 1,
266
- 'external' => false,
267
- ));
268
 
269
- return array_shift($products);
270
  }
271
 
272
  /**
@@ -279,166 +271,165 @@ class TInvWL_Product
279
  * @global wpdb $wpdb
280
  *
281
  */
282
- function get($data = array(), $count = false)
283
- {
284
  global $wpdb;
285
 
286
  $default = array(
287
- 'count' => 10,
288
- 'field' => null,
289
- 'offset' => 0,
290
- 'order' => 'DESC',
291
  'order_by' => 'date',
292
  'external' => true,
293
- 'sql' => '',
294
  );
295
 
296
- foreach ($default as $_k => $_v) {
297
- if (array_key_exists($_k, $data)) {
298
- $default[$_k] = $data[$_k];
299
- unset($data[$_k]);
300
  }
301
  }
302
 
303
- $default['offset'] = absint($default['offset']);
304
- $default['count'] = absint($default['count']);
305
- if (is_array($default['field'])) {
306
- $default['field'] = '`' . implode('`,`', $default['field']) . '`';
307
- } elseif (is_string($default['field'])) {
308
- $default['field'] = array('ID', $default['field']);
309
- $default['field'] = '`' . implode('`,`', $default['field']) . '`';
310
  } else {
311
  $default['field'] = '*';
312
  }
313
- if ($count) {
314
  $default['field'] = 'COUNT(`ID`) as `count`';
315
  }
316
 
317
- $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
318
  $where = '1';
319
- if (!empty($data) && is_array($data)) {
320
- if (array_key_exists('meta', $data)) {
321
  $product_id = $variation_id = 0;
322
- if (array_key_exists('product_id', $data)) {
323
  $product_id = $data['product_id'];
324
  }
325
- if (array_key_exists('variation_id', $data)) {
326
  $variation_id = $data['variation_id'];
327
  }
328
- $data['formdata'] = trim($this->prepare_save_meta($data['meta'], $product_id, $variation_id), "'");
329
- unset($data['meta']);
330
  }
331
- foreach ($data as $f => $v) {
332
- $s = is_array($v) ? ' IN ' : '=';
333
- if (is_array($v)) {
334
- foreach ($v as $_f => $_v) {
335
- $v[$_f] = $wpdb->prepare('%s', $_v);
336
  }
337
- $v = implode(',', $v);
338
  $v = "($v)";
339
  } else {
340
- $v = $wpdb->prepare('%s', $v);
341
  }
342
- $data[$f] = sprintf('`%s`%s%s', $f, $s, $v);
343
  }
344
- $where = implode(' AND ', $data);
345
- $sql .= ' WHERE ' . $where;
346
  }
347
 
348
- $sql .= sprintf(' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count']);
349
- if (!empty($default['sql'])) {
350
- $replacer = $replace = array();
351
- $replace[0] = '{table}';
352
  $replacer[0] = $this->table;
353
- $replace[1] = '{where}';
354
  $replacer[1] = $where;
355
 
356
- foreach ($default as $key => $value) {
357
- $i = count($replace);
358
 
359
- $replace[$i] = '{' . $key . '}';
360
- $replacer[$i] = $value;
361
  }
362
 
363
- $sql = str_replace($replace, $replacer, $default['sql']);
364
  }
365
- $products = $wpdb->get_results($sql, ARRAY_A); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
366
 
367
- if (empty($products) || is_wp_error($products)) {
368
  return array();
369
  }
370
 
371
- if ($count) {
372
  return $products[0]['count'];
373
  }
374
  $ids = array();
375
- foreach ($products as $k => $product) {
376
- if (empty($default['sql'])) {
377
- $product = filter_var_array($product, array(
378
- 'ID' => FILTER_VALIDATE_INT,
379
- 'wishlist_id' => FILTER_VALIDATE_INT,
380
- 'product_id' => FILTER_VALIDATE_INT,
381
  'variation_id' => FILTER_VALIDATE_INT,
382
- 'author' => FILTER_VALIDATE_INT,
383
- 'date' => FILTER_DEFAULT,
384
- 'formdata' => FILTER_DEFAULT,
385
- 'quantity' => FILTER_VALIDATE_INT,
386
- 'price' => FILTER_SANITIZE_NUMBER_FLOAT,
387
- 'in_stock' => FILTER_VALIDATE_BOOLEAN,
388
- ));
389
  $product['quantity'] = 1;
390
  }
391
 
392
- if ($default['external']) {
393
- if (isset($product['product_id'])) {
394
- $ids[] = (apply_filters('wpml_object_id', $product['product_id'], 'product', false)) ? apply_filters('wpml_object_id', $product['product_id'], 'product', false) : $product['product_id'];
395
  }
396
  }
397
  $product['meta'] = array();
398
- if (array_key_exists('formdata', $product)) {
399
  $meta = $product['formdata'];
400
- unset($product['formdata']);
401
 
402
- $product['meta'] = $this->prepare_retrun_meta($meta, $product['product_id'], $product['variation_id'], $product['quantity']);
403
  }
404
- $products[$k] = apply_filters('tinvwl_wishlist_product_get', $product);
405
  }
406
 
407
- if (!empty($ids)) {
408
- $args = array(
409
  'include' => $ids,
410
- 'limit' => count($ids),
411
  );
412
- $_products = wc_get_products($args);
413
- foreach ($_products as $_product) {
414
 
415
- foreach ($products as $key => $wlproduct) {
416
- if (!isset($wlproduct['product_id'])) {
417
  continue;
418
  }
419
 
420
- if ($_product->get_id() === absint((apply_filters('wpml_object_id', $wlproduct['product_id'], 'product', false)) ? apply_filters('wpml_object_id', $wlproduct['product_id'], 'product', false) : $wlproduct['product_id'])) {
421
- if (in_array($_product->get_type(), array('variable', 'grouped'))) {
422
  $use_original_id = false;
423
 
424
- if (function_exists('pll_is_translated_post_type')) {
425
  $use_original_id = true;
426
  }
427
 
428
- $products[$key]['data'] = $wlproduct['variation_id'] ? wc_get_product(apply_filters('wpml_object_id', $wlproduct['variation_id'], 'product_variation', $use_original_id)) : $_product;
429
  } else {
430
- $products[$key]['data'] = $_product;
431
  }
432
  }
433
  }
434
  }
435
 
436
  // remove deleted products from database
437
- if ($default['external']) {
438
- foreach ($products as $key => $product) {
439
- if (empty($product['data'])) {
440
- unset($products[$key]);
441
- $this->remove($product);
442
  }
443
  }
444
  }
@@ -455,18 +446,17 @@ class TInvWL_Product
455
  *
456
  * @return mixed
457
  */
458
- function product_data($product_id, $variation_id = 0)
459
- {
460
- $product_id = absint($product_id);
461
- $variation_id = absint($variation_id);
462
 
463
- $product_data = apply_filters('tinvwl_product_data', wc_get_product($variation_id ? $variation_id : $product_id), $product_id, $variation_id);
464
 
465
- if (!$product_data || 'trash' === get_post($product_data->get_id())->post_status) {
466
  return null;
467
  }
468
 
469
- $product_data->variation_id = absint(($product_data->is_type('variation') ? $product_data->get_id() : 0));
470
 
471
  return $product_data;
472
  }
@@ -482,67 +472,66 @@ class TInvWL_Product
482
  * @global wpdb $wpdb
483
  *
484
  */
485
- function update($data = array(), $meta = array(), $id = 0)
486
- {
487
- if (empty($meta) && array_key_exists('meta', $data) && !empty($data['meta'])) {
488
  $meta = $data['meta'];
489
  }
490
 
491
- $data = filter_var_array($data, apply_filters('tinvwl_wishlist_product_update_field', array(
492
- 'product_id' => FILTER_VALIDATE_INT,
493
- 'quantity' => FILTER_VALIDATE_INT,
494
  'variation_id' => FILTER_VALIDATE_INT,
495
- 'wishlist_id' => FILTER_VALIDATE_INT,
496
- 'author' => FILTER_VALIDATE_INT,
497
- )));
498
- $data = array_filter($data);
499
 
500
- if (!array_key_exists('wishlist_id', $data)) {
501
  $data['wishlist_id'] = $this->wishlist_id();
502
  }
503
- if (!array_key_exists('variation_id', $data)) {
504
  $data['variation_id'] = 0;
505
  }
506
 
507
- if (empty($data['wishlist_id']) || empty($data['product_id'])) {
508
  return false;
509
  }
510
- $product_data = $this->product_data($data['product_id'], $data['variation_id']);
511
- if (!$product_data) {
512
  return false;
513
  }
514
 
515
- if ($product_data->is_sold_individually()) {
516
  $data['quantity'] = 1;
517
  }
518
 
519
- $data = apply_filters('tinvwl_wishlist_product_update', $data);
520
  $data['in_stock'] = $product_data->is_in_stock();
521
 
522
- if ($product_data->is_type('variable')) {
523
- $data['price'] = filter_var($product_data->get_variation_price('max', false), FILTER_VALIDATE_FLOAT);
524
  } else {
525
- $data['price'] = filter_var($product_data->get_price(), FILTER_VALIDATE_FLOAT);
526
  }
527
 
528
  global $wpdb;
529
 
530
- $res_update = $wpdb->update($this->table, $data, array(
531
- 'product_id' => $data['product_id'],
532
  'variation_id' => $data['variation_id'],
533
- 'wishlist_id' => $data['wishlist_id'],
534
- 'formdata' => $this->prepare_save_meta($meta, $data['product_id'], $data['variation_id']),
535
- ));
536
 
537
- if ($res_update !== false) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
538
 
539
  /* Run a 3rd party code when product updated on a wishlist.
540
  *
541
  * @param array $data product data including author and wishlist IDs.
542
  * */
543
- do_action('tinvwl_product_updated', $data);
544
 
545
- return ($id) ? $id : true;
546
  }
547
 
548
  return false;
@@ -560,30 +549,29 @@ class TInvWL_Product
560
  * @global wpdb $wpdb
561
  *
562
  */
563
- function remove_product_from_wl($wishlist_id = 0, $product_id = 0, $variation_id = 0, $meta = array())
564
- {
565
  global $wpdb;
566
- if (empty($wishlist_id)) {
567
  $wishlist_id = $this->wishlist_id();
568
  }
569
- if (empty($wishlist_id)) {
570
  return false;
571
  }
572
- if (empty($product_id)) {
573
- return false !== $wpdb->delete($this->table, array('wishlist_id' => $wishlist_id)); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
574
  }
575
 
576
- $data = array(
577
- 'wishlist_id' => $wishlist_id,
578
- 'product_id' => $product_id,
579
  'variation_id' => $variation_id,
580
  );
581
- $data['formdata'] = $this->prepare_save_meta($meta, $data['product_id'], $data['variation_id']);
582
 
583
- $result = false !== $wpdb->delete($this->table, $data); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
584
- if ($result) {
585
- do_action('tinvwl_wishlist_product_removed_from_wishlist', $wishlist_id, $product_id, $variation_id);
586
- set_transient('_tinvwl_update_wishlists_data', '1');
587
  }
588
 
589
  return $result;
@@ -598,17 +586,16 @@ class TInvWL_Product
598
  * @global wpdb $wpdb
599
  *
600
  */
601
- function remove_product($product_id = 0)
602
- {
603
- if (empty($product_id)) {
604
  return false;
605
  }
606
 
607
  global $wpdb;
608
- $result = false !== $wpdb->delete($this->table, array('product_id' => $product_id)); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
609
- if ($result) {
610
- do_action('tinvwl_wishlist_product_removed_by_product', $product_id);
611
- set_transient('_tinvwl_update_wishlists_data', '1');
612
  }
613
 
614
  return $result;
@@ -623,23 +610,22 @@ class TInvWL_Product
623
  * @global wpdb $wpdb
624
  *
625
  */
626
- function get_wishlist_by_product_id($product_id = 0)
627
- {
628
- if (empty($product_id)) {
629
  return false;
630
  }
631
 
632
  global $wpdb;
633
- $sql = "SELECT `wishlist_id` FROM `{$this->table}` WHERE `ID`={$product_id}";
634
- $result = $wpdb->get_results($sql, ARRAY_A);
635
 
636
- if (!$result) {
637
  return false;
638
  }
639
 
640
  $wl = new TInvWL_Wishlist();
641
 
642
- $wishlist = $wl->get_by_id($result[0]['wishlist_id']);
643
 
644
  return $wishlist;
645
  }
@@ -653,21 +639,20 @@ class TInvWL_Product
653
  * @global wpdb $wpdb
654
  *
655
  */
656
- function remove($data)
657
- {
658
- if (!isset($data['ID']) || empty($data['ID'])) {
659
  return false;
660
  }
661
 
662
  global $wpdb;
663
- $result = false !== $wpdb->delete($this->table, array('ID' => $data['ID'])); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
664
- if ($result) {
665
  /* Run a 3rd party code when product removed from a wishlist.
666
  *
667
  * @param array $data product data including author and wishlist IDs.
668
  * */
669
- do_action('tinvwl_product_removed', $data);
670
- set_transient('_tinvwl_update_wishlists_data', '1');
671
  }
672
 
673
  return $result;
@@ -680,8 +665,7 @@ class TInvWL_Product
680
  *
681
  * @return array
682
  */
683
- function clean_meta($meta)
684
- {
685
 
686
  foreach (
687
  array(
@@ -693,11 +677,11 @@ class TInvWL_Product
693
  'product_sku',
694
  ) as $field
695
  ) {
696
- if (array_key_exists($field, $meta)) {
697
- unset($meta[$field]);
698
  }
699
  }
700
- $meta = array_filter($meta);
701
 
702
  return $meta;
703
  }
@@ -711,12 +695,11 @@ class TInvWL_Product
711
  *
712
  * @return string
713
  */
714
- function prepare_save_meta($meta = array(), $product_id = 0, $variation_id = 0)
715
- {
716
- if (!is_array($meta)) {
717
  $meta = array();
718
  }
719
- $meta = apply_filters('tinvwl_product_prepare_meta', $meta, $product_id, $variation_id);
720
  foreach (
721
  array(
722
  'add-to-cart',
@@ -727,16 +710,16 @@ class TInvWL_Product
727
  'product_sku',
728
  ) as $field
729
  ) {
730
- if (array_key_exists($field, $meta)) {
731
- unset($meta[$field]);
732
  }
733
  }
734
- $meta = array_filter($meta);
735
- if (empty($meta)) {
736
  return '';
737
  }
738
 
739
- return json_encode($meta);
740
  }
741
 
742
  /**
@@ -749,24 +732,23 @@ class TInvWL_Product
749
  *
750
  * @return array
751
  */
752
- function prepare_retrun_meta($meta = '', $product_id = 0, $variation_id = 0, $quantity = 1)
753
- {
754
- if (empty($meta)) {
755
  return array();
756
  }
757
- $meta = @json_decode($meta, true);
758
- if (empty($meta) || !is_array($meta)) {
759
  return array();
760
  }
761
- if (!empty($product_id)) {
762
  $meta['add-to-cart'] = $product_id;
763
- $meta['product_id'] = $product_id;
764
- $meta['quantity'] = $quantity;
765
- if (!empty($variation_id)) {
766
  $meta['variation_id'] = $variation_id;
767
  }
768
  }
769
 
770
- return apply_filters('tinvwl_wishlist_product_unprepare_meta', $meta);
771
  }
772
  }
7
  */
8
 
9
  // If this file is called directly, abort.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
  die;
12
  }
13
 
14
  /**
15
  * Product function class
16
  */
17
+ class TInvWL_Product {
 
18
 
19
  /**
20
  * Table name
50
  * @global wpdb $wpdb
51
  *
52
  */
53
+ function __construct( $wishlist = array(), $plugin_name = TINVWL_PREFIX ) {
 
54
  global $wpdb;
55
 
56
+ $this->wishlist = (array) $wishlist;
57
+ $this->_name = $plugin_name;
58
+ $this->table = sprintf( '%s%s_%s', $wpdb->prefix, $this->_name, 'items' );
59
+ $this->user = $this->wishlist_author();
60
+ if ( empty( $this->user ) ) {
61
  $user = wp_get_current_user();
62
+ if ( $user->exists() ) {
63
  $this->user = $user->ID;
64
  }
65
  }
66
 
67
+ add_filter( 'tinvwl_addtowishlist_add_form', array( $this, 'clean_meta' ), 10, 1 );
68
  }
69
 
70
  /**
72
  *
73
  * @return int
74
  */
75
+ function wishlist_id() {
76
+ if ( is_array( $this->wishlist ) && array_key_exists( 'ID', $this->wishlist ) ) {
 
77
  return $this->wishlist['ID'];
78
  }
79
 
85
  *
86
  * @return int
87
  */
88
+ function wishlist_author() {
89
+ if ( is_array( $this->wishlist ) && array_key_exists( 'author', $this->wishlist ) ) {
 
90
  return $this->wishlist['author'];
91
  }
92
 
101
  *
102
  * @return boolean
103
  */
104
+ function add_product( $data = array(), $meta = array() ) {
105
+ $_data = filter_var_array( $data, array(
106
+ 'product_id' => FILTER_VALIDATE_INT,
 
107
  'variation_id' => FILTER_VALIDATE_INT,
108
+ 'wishlist_id' => FILTER_VALIDATE_INT,
109
+ 'quantity' => FILTER_VALIDATE_INT,
110
+ ) );
111
+ if ( empty( $_data['quantity'] ) ) {
112
  $_data['quantity'] = 1;
113
  }
114
+ if ( empty( $_data['wishlist_id'] ) ) {
115
  $_data['wishlist_id'] = $this->wishlist_id();
116
  }
117
+ $product_data = $this->check_product( $_data['product_id'], $_data['variation_id'], $_data['wishlist_id'], $meta );
118
+ if ( false === $product_data ) {
119
  return false;
120
  }
121
+ if ( $product_data ) {
122
+ return $this->update( $data, $meta, $product_data['ID'] );
123
  } else {
124
+ return $this->add( $data, $meta );
125
  }
126
  }
127
 
135
  * @global wpdb $wpdb
136
  *
137
  */
138
+ function add( $data = array(), $meta = array() ) {
 
139
 
140
  $default = array(
141
+ 'wishlist_id' => $this->wishlist_id(),
142
+ 'product_id' => 0,
143
  'variation_id' => 0,
144
+ 'formdata' => '',
145
+ 'author' => $this->user,
146
+ 'date' => current_time( 'Y-m-d H:i:s' ),
147
+ 'quantity' => 1,
148
+ 'price' => 0,
149
+ 'in_stock' => 1,
150
  );
151
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_add_field', array(
152
+ 'author' => FILTER_VALIDATE_INT,
153
+ 'product_id' => FILTER_VALIDATE_INT,
154
+ 'quantity' => FILTER_VALIDATE_INT,
155
  'variation_id' => FILTER_VALIDATE_INT,
156
+ 'wishlist_id' => FILTER_VALIDATE_INT,
157
+ ) ) );
158
+ $data = array_filter( $data );
159
 
160
+ $data = tinv_array_merge( $default, $data );
161
 
162
+ if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
163
  return false;
164
  }
165
 
166
+ $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
167
 
168
+ if ( $data['quantity'] <= 0 || ! $product_data ) {
169
  return false;
170
  }
171
 
172
+ if ( $product_data->is_sold_individually() ) {
173
  $data['quantity'] = 1;
174
  }
175
 
176
+ $data = apply_filters( 'tinvwl_wishlist_product_add', $data );
177
  $data['in_stock'] = $product_data->is_in_stock();
178
 
179
+ $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
180
 
181
+ if ( $product_data->is_type( 'variable' ) ) {
182
+ $data['price'] = filter_var( $product_data->get_variation_price( 'max', false ), FILTER_VALIDATE_FLOAT );
183
  } else {
184
+ $data['price'] = filter_var( ( $product_data->get_price() ), FILTER_VALIDATE_FLOAT );
185
  }
186
 
187
  global $wpdb;
188
+ if ( $wpdb->insert( $this->table, $data ) ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
189
  $id = $wpdb->insert_id;
190
 
191
  /* Run a 3rd party code when product added to a wishlist.
192
  *
193
  * @param array $data product data including author and wishlist IDs.
194
  * */
195
+ do_action( 'tinvwl_product_added', $data );
196
 
197
  return $id;
198
  }
207
  *
208
  * @return array
209
  */
210
+ function get_wishlist( $data = array(), $count = false ) {
211
+ if ( ! array_key_exists( 'wishlist_id', $data ) ) {
 
212
  $data['wishlist_id'] = $this->wishlist_id();
213
  }
214
+ if ( empty( $data['wishlist_id'] ) ) {
215
  return array();
216
  }
217
 
218
+ return $this->get( $data, $count );
219
  }
220
 
221
  /**
228
  *
229
  * @return mixed
230
  */
231
+ function check_product( $product_id, $variation_id = 0, $wishlist_id = 0, $meta = array() ) {
232
+ $product_id = absint( $product_id );
233
+ $variation_id = absint( $variation_id );
234
+ $wishlist_id = absint( $wishlist_id );
 
235
 
236
+ if ( empty( $wishlist_id ) ) {
237
  $wishlist_id = $this->wishlist_id();
238
  }
239
+ if ( empty( $wishlist_id ) || empty( $product_id ) ) {
240
  return false;
241
  }
242
 
243
+ $product_data = $this->product_data( $product_id, $variation_id );
244
 
245
+ if ( ! $product_data ) {
246
  return false;
247
  }
248
 
249
+ $product_id = $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id();
250
+ $variation_id = $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0;
251
 
252
+ $products = $this->get( array(
253
+ 'product_id' => $product_id,
254
  'variation_id' => $variation_id,
255
+ 'wishlist_id' => $wishlist_id,
256
+ 'formdata' => $this->prepare_save_meta( $meta, $product_id, $variation_id ),
257
+ 'count' => 1,
258
+ 'external' => false,
259
+ ) );
260
 
261
+ return array_shift( $products );
262
  }
263
 
264
  /**
271
  * @global wpdb $wpdb
272
  *
273
  */
274
+ function get( $data = array(), $count = false ) {
 
275
  global $wpdb;
276
 
277
  $default = array(
278
+ 'count' => 10,
279
+ 'field' => null,
280
+ 'offset' => 0,
281
+ 'order' => 'DESC',
282
  'order_by' => 'date',
283
  'external' => true,
284
+ 'sql' => '',
285
  );
286
 
287
+ foreach ( $default as $_k => $_v ) {
288
+ if ( array_key_exists( $_k, $data ) ) {
289
+ $default[ $_k ] = $data[ $_k ];
290
+ unset( $data[ $_k ] );
291
  }
292
  }
293
 
294
+ $default['offset'] = absint( $default['offset'] );
295
+ $default['count'] = absint( $default['count'] );
296
+ if ( is_array( $default['field'] ) ) {
297
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
298
+ } elseif ( is_string( $default['field'] ) ) {
299
+ $default['field'] = array( 'ID', $default['field'] );
300
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
301
  } else {
302
  $default['field'] = '*';
303
  }
304
+ if ( $count ) {
305
  $default['field'] = 'COUNT(`ID`) as `count`';
306
  }
307
 
308
+ $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
309
  $where = '1';
310
+ if ( ! empty( $data ) && is_array( $data ) ) {
311
+ if ( array_key_exists( 'meta', $data ) ) {
312
  $product_id = $variation_id = 0;
313
+ if ( array_key_exists( 'product_id', $data ) ) {
314
  $product_id = $data['product_id'];
315
  }
316
+ if ( array_key_exists( 'variation_id', $data ) ) {
317
  $variation_id = $data['variation_id'];
318
  }
319
+ $data['formdata'] = trim( $this->prepare_save_meta( $data['meta'], $product_id, $variation_id ), "'" );
320
+ unset( $data['meta'] );
321
  }
322
+ foreach ( $data as $f => $v ) {
323
+ $s = is_array( $v ) ? ' IN ' : '=';
324
+ if ( is_array( $v ) ) {
325
+ foreach ( $v as $_f => $_v ) {
326
+ $v[ $_f ] = $wpdb->prepare( '%s', $_v );
327
  }
328
+ $v = implode( ',', $v );
329
  $v = "($v)";
330
  } else {
331
+ $v = $wpdb->prepare( '%s', $v );
332
  }
333
+ $data[ $f ] = sprintf( '`%s`%s%s', $f, $s, $v );
334
  }
335
+ $where = implode( ' AND ', $data );
336
+ $sql .= ' WHERE ' . $where;
337
  }
338
 
339
+ $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
340
+ if ( ! empty( $default['sql'] ) ) {
341
+ $replacer = $replace = array();
342
+ $replace[0] = '{table}';
343
  $replacer[0] = $this->table;
344
+ $replace[1] = '{where}';
345
  $replacer[1] = $where;
346
 
347
+ foreach ( $default as $key => $value ) {
348
+ $i = count( $replace );
349
 
350
+ $replace[ $i ] = '{' . $key . '}';
351
+ $replacer[ $i ] = $value;
352
  }
353
 
354
+ $sql = str_replace( $replace, $replacer, $default['sql'] );
355
  }
356
+ $products = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
357
 
358
+ if ( empty( $products ) || is_wp_error( $products ) ) {
359
  return array();
360
  }
361
 
362
+ if ( $count ) {
363
  return $products[0]['count'];
364
  }
365
  $ids = array();
366
+ foreach ( $products as $k => $product ) {
367
+ if ( empty( $default['sql'] ) ) {
368
+ $product = filter_var_array( $product, array(
369
+ 'ID' => FILTER_VALIDATE_INT,
370
+ 'wishlist_id' => FILTER_VALIDATE_INT,
371
+ 'product_id' => FILTER_VALIDATE_INT,
372
  'variation_id' => FILTER_VALIDATE_INT,
373
+ 'author' => FILTER_VALIDATE_INT,
374
+ 'date' => FILTER_DEFAULT,
375
+ 'formdata' => FILTER_DEFAULT,
376
+ 'quantity' => FILTER_VALIDATE_INT,
377
+ 'price' => FILTER_SANITIZE_NUMBER_FLOAT,
378
+ 'in_stock' => FILTER_VALIDATE_BOOLEAN,
379
+ ) );
380
  $product['quantity'] = 1;
381
  }
382
 
383
+ if ( $default['external'] ) {
384
+ if ( isset( $product['product_id'] ) ) {
385
+ $ids[] = ( apply_filters( 'wpml_object_id', $product['product_id'], 'product', false ) ) ? apply_filters( 'wpml_object_id', $product['product_id'], 'product', false ) : $product['product_id'];
386
  }
387
  }
388
  $product['meta'] = array();
389
+ if ( array_key_exists( 'formdata', $product ) ) {
390
  $meta = $product['formdata'];
391
+ unset( $product['formdata'] );
392
 
393
+ $product['meta'] = $this->prepare_retrun_meta( $meta, $product['product_id'], $product['variation_id'], $product['quantity'] );
394
  }
395
+ $products[ $k ] = apply_filters( 'tinvwl_wishlist_product_get', $product );
396
  }
397
 
398
+ if ( ! empty( $ids ) ) {
399
+ $args = array(
400
  'include' => $ids,
401
+ 'limit' => count( $ids ),
402
  );
403
+ $_products = wc_get_products( $args );
404
+ foreach ( $_products as $_product ) {
405
 
406
+ foreach ( $products as $key => $wlproduct ) {
407
+ if ( ! isset( $wlproduct['product_id'] ) ) {
408
  continue;
409
  }
410
 
411
+ if ( $_product->get_id() === absint( ( apply_filters( 'wpml_object_id', $wlproduct['product_id'], 'product', false ) ) ? apply_filters( 'wpml_object_id', $wlproduct['product_id'], 'product', false ) : $wlproduct['product_id'] ) ) {
412
+ if ( in_array( $_product->get_type(), array( 'variable', 'grouped' ) ) ) {
413
  $use_original_id = false;
414
 
415
+ if ( function_exists( 'pll_is_translated_post_type' ) ) {
416
  $use_original_id = true;
417
  }
418
 
419
+ $products[ $key ]['data'] = $wlproduct['variation_id'] ? wc_get_product( apply_filters( 'wpml_object_id', $wlproduct['variation_id'], 'product_variation', $use_original_id ) ) : $_product;
420
  } else {
421
+ $products[ $key ]['data'] = $_product;
422
  }
423
  }
424
  }
425
  }
426
 
427
  // remove deleted products from database
428
+ if ( $default['external'] && ! function_exists( 'wpml_get_current_language' ) ) {
429
+ foreach ( $products as $key => $product ) {
430
+ if ( empty( $product['data'] ) ) {
431
+ unset( $products[ $key ] );
432
+ $this->remove( $product );
433
  }
434
  }
435
  }
446
  *
447
  * @return mixed
448
  */
449
+ function product_data( $product_id, $variation_id = 0 ) {
450
+ $product_id = absint( $product_id );
451
+ $variation_id = absint( $variation_id );
 
452
 
453
+ $product_data = apply_filters( 'tinvwl_product_data', wc_get_product( $variation_id ? $variation_id : $product_id ), $product_id, $variation_id );
454
 
455
+ if ( ! $product_data || 'trash' === get_post( $product_data->get_id() )->post_status ) {
456
  return null;
457
  }
458
 
459
+ $product_data->variation_id = absint( ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
460
 
461
  return $product_data;
462
  }
472
  * @global wpdb $wpdb
473
  *
474
  */
475
+ function update( $data = array(), $meta = array(), $id = 0 ) {
476
+ if ( empty( $meta ) && array_key_exists( 'meta', $data ) && ! empty( $data['meta'] ) ) {
 
477
  $meta = $data['meta'];
478
  }
479
 
480
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_update_field', array(
481
+ 'product_id' => FILTER_VALIDATE_INT,
482
+ 'quantity' => FILTER_VALIDATE_INT,
483
  'variation_id' => FILTER_VALIDATE_INT,
484
+ 'wishlist_id' => FILTER_VALIDATE_INT,
485
+ 'author' => FILTER_VALIDATE_INT,
486
+ ) ) );
487
+ $data = array_filter( $data );
488
 
489
+ if ( ! array_key_exists( 'wishlist_id', $data ) ) {
490
  $data['wishlist_id'] = $this->wishlist_id();
491
  }
492
+ if ( ! array_key_exists( 'variation_id', $data ) ) {
493
  $data['variation_id'] = 0;
494
  }
495
 
496
+ if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
497
  return false;
498
  }
499
+ $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
500
+ if ( ! $product_data ) {
501
  return false;
502
  }
503
 
504
+ if ( $product_data->is_sold_individually() ) {
505
  $data['quantity'] = 1;
506
  }
507
 
508
+ $data = apply_filters( 'tinvwl_wishlist_product_update', $data );
509
  $data['in_stock'] = $product_data->is_in_stock();
510
 
511
+ if ( $product_data->is_type( 'variable' ) ) {
512
+ $data['price'] = filter_var( $product_data->get_variation_price( 'max', false ), FILTER_VALIDATE_FLOAT );
513
  } else {
514
+ $data['price'] = filter_var( $product_data->get_price(), FILTER_VALIDATE_FLOAT );
515
  }
516
 
517
  global $wpdb;
518
 
519
+ $res_update = $wpdb->update( $this->table, $data, array(
520
+ 'product_id' => $data['product_id'],
521
  'variation_id' => $data['variation_id'],
522
+ 'wishlist_id' => $data['wishlist_id'],
523
+ 'formdata' => $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] ),
524
+ ) );
525
 
526
+ if ( $res_update !== false ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
527
 
528
  /* Run a 3rd party code when product updated on a wishlist.
529
  *
530
  * @param array $data product data including author and wishlist IDs.
531
  * */
532
+ do_action( 'tinvwl_product_updated', $data );
533
 
534
+ return ( $id ) ? $id : true;
535
  }
536
 
537
  return false;
549
  * @global wpdb $wpdb
550
  *
551
  */
552
+ function remove_product_from_wl( $wishlist_id = 0, $product_id = 0, $variation_id = 0, $meta = array() ) {
 
553
  global $wpdb;
554
+ if ( empty( $wishlist_id ) ) {
555
  $wishlist_id = $this->wishlist_id();
556
  }
557
+ if ( empty( $wishlist_id ) ) {
558
  return false;
559
  }
560
+ if ( empty( $product_id ) ) {
561
+ return false !== $wpdb->delete( $this->table, array( 'wishlist_id' => $wishlist_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
562
  }
563
 
564
+ $data = array(
565
+ 'wishlist_id' => $wishlist_id,
566
+ 'product_id' => $product_id,
567
  'variation_id' => $variation_id,
568
  );
569
+ $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
570
 
571
+ $result = false !== $wpdb->delete( $this->table, $data ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
572
+ if ( $result ) {
573
+ do_action( 'tinvwl_wishlist_product_removed_from_wishlist', $wishlist_id, $product_id, $variation_id );
574
+ set_transient( '_tinvwl_update_wishlists_data', '1' );
575
  }
576
 
577
  return $result;
586
  * @global wpdb $wpdb
587
  *
588
  */
589
+ function remove_product( $product_id = 0 ) {
590
+ if ( empty( $product_id ) ) {
 
591
  return false;
592
  }
593
 
594
  global $wpdb;
595
+ $result = false !== $wpdb->delete( $this->table, array( 'product_id' => $product_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
596
+ if ( $result ) {
597
+ do_action( 'tinvwl_wishlist_product_removed_by_product', $product_id );
598
+ set_transient( '_tinvwl_update_wishlists_data', '1' );
599
  }
600
 
601
  return $result;
610
  * @global wpdb $wpdb
611
  *
612
  */
613
+ function get_wishlist_by_product_id( $product_id = 0 ) {
614
+ if ( empty( $product_id ) ) {
 
615
  return false;
616
  }
617
 
618
  global $wpdb;
619
+ $sql = "SELECT `wishlist_id` FROM `{$this->table}` WHERE `ID`={$product_id}";
620
+ $result = $wpdb->get_results( $sql, ARRAY_A );
621
 
622
+ if ( ! $result ) {
623
  return false;
624
  }
625
 
626
  $wl = new TInvWL_Wishlist();
627
 
628
+ $wishlist = $wl->get_by_id( $result[0]['wishlist_id'] );
629
 
630
  return $wishlist;
631
  }
639
  * @global wpdb $wpdb
640
  *
641
  */
642
+ function remove( $data ) {
643
+ if ( ! isset( $data['ID'] ) || empty( $data['ID'] ) ) {
 
644
  return false;
645
  }
646
 
647
  global $wpdb;
648
+ $result = false !== $wpdb->delete( $this->table, array( 'ID' => $data['ID'] ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
649
+ if ( $result ) {
650
  /* Run a 3rd party code when product removed from a wishlist.
651
  *
652
  * @param array $data product data including author and wishlist IDs.
653
  * */
654
+ do_action( 'tinvwl_product_removed', $data );
655
+ set_transient( '_tinvwl_update_wishlists_data', '1' );
656
  }
657
 
658
  return $result;
665
  *
666
  * @return array
667
  */
668
+ function clean_meta( $meta ) {
 
669
 
670
  foreach (
671
  array(
677
  'product_sku',
678
  ) as $field
679
  ) {
680
+ if ( array_key_exists( $field, $meta ) ) {
681
+ unset( $meta[ $field ] );
682
  }
683
  }
684
+ $meta = array_filter( $meta );
685
 
686
  return $meta;
687
  }
695
  *
696
  * @return string
697
  */
698
+ function prepare_save_meta( $meta = array(), $product_id = 0, $variation_id = 0 ) {
699
+ if ( ! is_array( $meta ) ) {
 
700
  $meta = array();
701
  }
702
+ $meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
703
  foreach (
704
  array(
705
  'add-to-cart',
710
  'product_sku',
711
  ) as $field
712
  ) {
713
+ if ( array_key_exists( $field, $meta ) ) {
714
+ unset( $meta[ $field ] );
715
  }
716
  }
717
+ $meta = array_filter( $meta );
718
+ if ( empty( $meta ) ) {
719
  return '';
720
  }
721
 
722
+ return json_encode( $meta );
723
  }
724
 
725
  /**
732
  *
733
  * @return array
734
  */
735
+ function prepare_retrun_meta( $meta = '', $product_id = 0, $variation_id = 0, $quantity = 1 ) {
736
+ if ( empty( $meta ) ) {
 
737
  return array();
738
  }
739
+ $meta = @json_decode( $meta, true );
740
+ if ( empty( $meta ) || ! is_array( $meta ) ) {
741
  return array();
742
  }
743
+ if ( ! empty( $product_id ) ) {
744
  $meta['add-to-cart'] = $product_id;
745
+ $meta['product_id'] = $product_id;
746
+ $meta['quantity'] = $quantity;
747
+ if ( ! empty( $variation_id ) ) {
748
  $meta['variation_id'] = $variation_id;
749
  }
750
  }
751
 
752
+ return apply_filters( 'tinvwl_wishlist_product_unprepare_meta', $meta );
753
  }
754
  }
includes/wishlist.class.php CHANGED
@@ -7,15 +7,14 @@
7
  */
8
 
9
  // If this file is called directly, abort.
10
- if (!defined('ABSPATH')) {
11
  die;
12
  }
13
 
14
  /**
15
  * Wishlists function class
16
  */
17
- class TInvWL_Wishlist
18
- {
19
 
20
  /**
21
  * Table name
@@ -68,16 +67,15 @@ class TInvWL_Wishlist
68
  * @global wpdb $wpdb
69
  *
70
  */
71
- function __construct($plugin_name = TINVWL_PREFIX)
72
- {
73
  global $wpdb;
74
 
75
- $this->_name = $plugin_name;
76
- $this->table = sprintf('%s%s_%s', $wpdb->prefix, $this->_name, 'lists');
77
- $this->default_name = apply_filters('tinvwl_default_wishlist_title', tinv_get_option('general', 'default_title'));
78
  $this->default_privacy = 'share';
79
- $this->privacy = array('public', 'share', 'private');
80
- if (!in_array($this->default_privacy, $this->privacy)) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
81
  $this->default_privacy = 'share';
82
  }
83
  $this->user = get_current_user_id();
@@ -89,15 +87,14 @@ class TInvWL_Wishlist
89
  * @return string
90
  * @global wpdb $wpdb
91
  */
92
- function unique_share_key()
93
- {
94
  global $wpdb;
95
 
96
- $share_key = substr(md5(date('r') . mt_rand(0, 3000)), 0, 6);
97
- $unique = false;
98
- while ($unique === false) {
99
- $unique = !$wpdb->get_var($wpdb->prepare("SELECT `ID` FROM `{$this->table}` WHERE `share_key` = %s", $share_key));
100
- $share_key = substr(md5(date('r') . mt_rand(0, 3000)), 0, 6);
101
  }
102
 
103
  return $share_key;
@@ -110,26 +107,25 @@ class TInvWL_Wishlist
110
  *
111
  * @return boolean|array
112
  */
113
- function add_user_default($user_id = 0)
114
- {
115
- if (empty($user_id)) {
116
  $user_id = $this->user;
117
  }
118
- if (empty($user_id)) {
119
  return $this->add_sharekey_default();
120
  }
121
 
122
- if (!current_user_can('tinvwl_general_settings') && ($user_id != get_current_user_id())) {
123
  return false;
124
  }
125
 
126
- if ($wl = $this->get_by_user_default($user_id)) {
127
- return array_shift($wl);
128
  }
129
 
130
- $wl = $this->add('', 'default', $this->default_privacy, $user_id);
131
- if (is_array($wl) && array_key_exists('share_key', $wl)) {
132
- $this->set_sharekey($wl['share_key']);
133
 
134
  return $wl;
135
  }
@@ -144,15 +140,14 @@ class TInvWL_Wishlist
144
  *
145
  * @return boolean|array
146
  */
147
- function add_sharekey_default($sharekey = '')
148
- {
149
- if ($wl = $this->get_by_sharekey_default($sharekey)) {
150
- return array_shift($wl);
151
  }
152
 
153
- $wl = $this->add('', 'default', $this->default_privacy, 0);
154
- if (is_array($wl) && array_key_exists('share_key', $wl)) {
155
- $this->set_sharekey($wl['share_key']);
156
 
157
  return $wl;
158
  }
@@ -172,43 +167,42 @@ class TInvWL_Wishlist
172
  * @global wpdb $wpdb
173
  *
174
  */
175
- function add($data, $type = 'list', $status = 'public', $user_id = 0)
176
- {
177
- $user_id = absint($user_id);
178
- if (empty($user_id)) {
179
  $user_id = $this->user;
180
  }
181
 
182
  $default = array(
183
- 'author' => $user_id,
184
- 'date' => current_time('Y-m-d H:i:s'),
185
- 'status' => $this->default_privacy,
186
  'share_key' => $this->unique_share_key(),
187
- 'title' => $this->default_name,
188
- 'type' => 'list',
189
  );
190
 
191
- if (!is_array($data)) {
192
  $data = array(
193
- 'title' => $data,
194
  'status' => $status,
195
- 'type' => $type,
196
  );
197
  }
198
- $data = wp_parse_args($data, $default);
199
- $data = apply_filters('tinvwl_wishlist_add', $data);
200
- if (!in_array($data['status'], $this->privacy)) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
201
  $data['status'] = 'public';
202
  }
203
  global $wpdb;
204
- if ($wpdb->insert($this->table, $data)) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
205
  $data['ID'] = $wpdb->insert_id;
206
 
207
  /* Run a 3rd party code when a new wishlist created.
208
  *
209
  * @param array $data A wishlist data.
210
  * */
211
- do_action('tinvwl_wishlist_created', $data);
212
 
213
  return $data;
214
  }
@@ -223,23 +217,22 @@ class TInvWL_Wishlist
223
  *
224
  * @return array
225
  */
226
- function get_by_user_default($user_id = 0)
227
- {
228
- $user_id = absint($user_id);
229
- if (empty($user_id)) {
230
  $user_id = $this->user;
231
  }
232
 
233
  $data = array(
234
  'author' => $user_id,
235
- 'type' => 'default',
236
  );
237
 
238
- if (!current_user_can('tinvwl_general_settings') && (empty($this->user) || ($data['author'] != $this->user))) { // WPCS: loose comparison ok.
239
  $data['status'] = 'public';
240
  }
241
 
242
- return $this->get($data);
243
  }
244
 
245
  /**
@@ -249,21 +242,20 @@ class TInvWL_Wishlist
249
  *
250
  * @return array
251
  */
252
- function get_by_sharekey_default($sharekey = '')
253
- {
254
- if (empty($sharekey)) {
255
  $sharekey = $this->get_sharekey();
256
  }
257
- if (empty($sharekey)) {
258
  return array();
259
  }
260
 
261
  $data = array(
262
  'share_key' => $sharekey,
263
- 'type' => 'default',
264
  );
265
 
266
- return $this->get($data);
267
  }
268
 
269
  /**
@@ -274,23 +266,22 @@ class TInvWL_Wishlist
274
  *
275
  * @return array
276
  */
277
- function get_by_user($user_id = 0, $data = array())
278
- {
279
- $user_id = absint($user_id);
280
- if (empty($user_id)) {
281
  $user_id = $this->user;
282
  }
283
- $this->add_user_default($user_id);
284
  $_data = array(
285
  'author' => $user_id,
286
  );
287
 
288
- if (!current_user_can('tinvwl_general_settings') && (empty($this->user) || ($_data['author'] != $this->user))) { // WPCS: loose comparison ok.
289
  $_data['status'] = 'public';
290
  }
291
- $data = tinv_array_merge($data, $_data);
292
 
293
- return $this->get($data);
294
  }
295
 
296
  /**
@@ -300,15 +291,14 @@ class TInvWL_Wishlist
300
  *
301
  * @return array
302
  */
303
- function get_by_id($id)
304
- {
305
- $id = absint($id);
306
- if (empty($id)) {
307
  return null;
308
  }
309
 
310
- $wishlists = $this->get(array('ID' => $id));
311
- $wishlist = array_shift($wishlists);
312
 
313
  return $wishlist;
314
  }
@@ -320,13 +310,12 @@ class TInvWL_Wishlist
320
  *
321
  * @return array
322
  */
323
- function get_by_share_key($share_key)
324
- {
325
- if (!preg_match('/[a-f0-9]{6}/i', $share_key)) {
326
  return null;
327
  }
328
- $wishlists = $this->get(array('share_key' => $share_key));
329
- $wishlist = array_shift($wishlists);
330
 
331
  return $wishlist;
332
  }
@@ -340,89 +329,88 @@ class TInvWL_Wishlist
340
  * @global wpdb $wpdb
341
  *
342
  */
343
- function get($data = array())
344
- {
345
  global $wpdb;
346
 
347
  $default = array(
348
- 'count' => 10,
349
- 'field' => null,
350
- 'offset' => 0,
351
- 'order' => 'ASC',
352
  'order_by' => 'title',
353
- 'sql' => '',
354
  );
355
 
356
- foreach ($default as $_k => $_v) {
357
- if (array_key_exists($_k, $data)) {
358
- $default[$_k] = $data[$_k];
359
- unset($data[$_k]);
360
  }
361
  }
362
 
363
- if (is_array($default['field'])) {
364
- $default['field'] = '`' . implode('`,`', $default['field']) . '`';
365
- } elseif (is_string($default['field'])) {
366
- $default['field'] = array('ID', 'type', $default['field']);
367
- $default['field'] = '`' . implode('`,`', $default['field']) . '`';
368
  } else {
369
  $default['field'] = '*';
370
  }
371
  $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
372
 
373
  $where = '1';
374
- if (!empty($data) && is_array($data)) {
375
- foreach ($data as $f => $v) {
376
- $s = is_array($v) ? ' IN ' : '=';
377
- if (is_array($v)) {
378
- foreach ($v as $_f => $_v) {
379
- $v[$_f] = $wpdb->prepare('%s', $_v);
380
  }
381
- $v = implode(',', $v);
382
  $v = "($v)";
383
  } else {
384
- $v = $wpdb->prepare('%s', $v);
385
  }
386
- $data[$f] = sprintf('`%s`%s%s', $f, $s, $v);
387
  }
388
- $where = ' WHERE ' . implode(' AND ', $data);
389
- $sql .= $where;
390
  }
391
- $sql .= sprintf(' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count']);
392
 
393
- if (!empty($default['sql'])) {
394
- $replacer = $replace = array();
395
- $replace[0] = '{table}';
396
  $replacer[0] = $this->table;
397
- $replace[1] = '{where}';
398
  $replacer[1] = $where;
399
 
400
- foreach ($default as $key => $value) {
401
- $i = count($replace);
402
 
403
- $replace[$i] = '{' . $key . '}';
404
- $replacer[$i] = $value;
405
  }
406
 
407
- $sql = str_replace($replace, $replacer, $default['sql']);
408
  }
409
 
410
- $wls = $wpdb->get_results($sql, ARRAY_A); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
411
 
412
- if (empty($wls)) {
413
  return array();
414
  }
415
 
416
- foreach ($wls as $k => $wl) {
417
- $wl['ID'] = absint($wl['ID']);
418
- if (array_key_exists('author', $wl)) {
419
- $wl['author'] = absint($wl['author']);
420
  }
421
- if ('default' === $wl['type'] && empty($wl['title'])) {
422
  $wl['title'] = $this->default_name;
423
  }
424
 
425
- $wls[$k] = apply_filters('tinvwl_wishlist_get', $wl);
426
  }
427
 
428
  return $wls;
@@ -440,32 +428,31 @@ class TInvWL_Wishlist
440
  * @global wpdb $wpdb
441
  *
442
  */
443
- function update($id, $data, $type = 'list', $status = 'public')
444
- {
445
- if (!is_array($data)) {
446
  $data = array(
447
- 'title' => $data,
448
  'status' => $status,
449
- 'type' => $type,
450
  );
451
  }
452
- $data = filter_var_array($data, apply_filters('tinvwl_wishlist_fields_update', array(
453
- 'title' => FILTER_SANITIZE_STRING,
454
  'status' => FILTER_SANITIZE_STRING,
455
- 'type' => FILTER_SANITIZE_STRING,
456
  'author' => FILTER_VALIDATE_INT,
457
- )));
458
- $data = array_filter($data);
459
- $data = apply_filters('tinvwl_wishlist_update', $data, $id);
460
- if (!array_key_exists('title', $data)) {
461
- $wishlist = $this->get_by_id($id);
462
- if ('default' === $wishlist['type']) {
463
  $data['title'] = '';
464
  }
465
  }
466
  global $wpdb;
467
 
468
- return false !== $wpdb->update($this->table, $data, array('ID' => $id)); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
469
  }
470
 
471
  /**
@@ -477,18 +464,17 @@ class TInvWL_Wishlist
477
  * @global wpdb $wpdb
478
  *
479
  */
480
- public function remove($id)
481
- {
482
- $id = absint($id);
483
- if (empty($id)) {
484
  return false;
485
  }
486
  global $wpdb;
487
- $result = $wpdb->delete($this->table, array('ID' => $id)); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
488
- if (false !== $result) {
489
- do_action('tinvwl_wishlist_removed', $id);
490
  $wlp = new TInvWL_Product();
491
- $wlp->remove_product_from_wl($id);
492
 
493
  return true;
494
  }
@@ -503,14 +489,13 @@ class TInvWL_Wishlist
503
  *
504
  * @return string
505
  */
506
- function set_sharekey($sharekey = '')
507
- {
508
  global $tinvwl_wishlist_sharekey;
509
 
510
- if (!empty($sharekey)) {
511
  self::$default_sharekey = $tinvwl_wishlist_sharekey = $sharekey;
512
- @setcookie('tinv_wishlistkey', self::$default_sharekey, time() + 31 * DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
513
- set_transient('_tinvwl_update_wishlists_data', '1');
514
  }
515
 
516
  return self::$default_sharekey;
@@ -521,17 +506,16 @@ class TInvWL_Wishlist
521
  *
522
  * @return string
523
  */
524
- function get_sharekey()
525
- {
526
  global $tinvwl_wishlist_sharekey;
527
 
528
- if (empty(self::$default_sharekey)) {
529
- self::$default_sharekey = $tinvwl_wishlist_sharekey = filter_input(INPUT_COOKIE, 'tinv_wishlistkey', FILTER_VALIDATE_REGEXP, array(
530
  'options' => array(
531
- 'regexp' => '/^[A-Fa-f0-9]{6}$/',
532
  'default' => $tinvwl_wishlist_sharekey,
533
  ),
534
- ));
535
  }
536
 
537
  return self::$default_sharekey;
7
  */
8
 
9
  // If this file is called directly, abort.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
  die;
12
  }
13
 
14
  /**
15
  * Wishlists function class
16
  */
17
+ class TInvWL_Wishlist {
 
18
 
19
  /**
20
  * Table name
67
  * @global wpdb $wpdb
68
  *
69
  */
70
+ function __construct( $plugin_name = TINVWL_PREFIX ) {
 
71
  global $wpdb;
72
 
73
+ $this->_name = $plugin_name;
74
+ $this->table = sprintf( '%s%s_%s', $wpdb->prefix, $this->_name, 'lists' );
75
+ $this->default_name = apply_filters( 'tinvwl_default_wishlist_title', tinv_get_option( 'general', 'default_title' ) );
76
  $this->default_privacy = 'share';
77
+ $this->privacy = array( 'public', 'share', 'private' );
78
+ if ( ! in_array( $this->default_privacy, $this->privacy ) ) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
79
  $this->default_privacy = 'share';
80
  }
81
  $this->user = get_current_user_id();
87
  * @return string
88
  * @global wpdb $wpdb
89
  */
90
+ function unique_share_key() {
 
91
  global $wpdb;
92
 
93
+ $share_key = substr( md5( date( 'r' ) . mt_rand( 0, 3000 ) ), 0, 6 );
94
+ $unique = false;
95
+ while ( $unique === false ) {
96
+ $unique = ! $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$this->table}` WHERE `share_key` = %s", $share_key ) );
97
+ $share_key = substr( md5( date( 'r' ) . mt_rand( 0, 3000 ) ), 0, 6 );
98
  }
99
 
100
  return $share_key;
107
  *
108
  * @return boolean|array
109
  */
110
+ function add_user_default( $user_id = 0 ) {
111
+ if ( empty( $user_id ) ) {
 
112
  $user_id = $this->user;
113
  }
114
+ if ( empty( $user_id ) ) {
115
  return $this->add_sharekey_default();
116
  }
117
 
118
+ if ( ! current_user_can( 'tinvwl_general_settings' ) && ( $user_id != get_current_user_id() ) ) {
119
  return false;
120
  }
121
 
122
+ if ( $wl = $this->get_by_user_default( $user_id ) ) {
123
+ return array_shift( $wl );
124
  }
125
 
126
+ $wl = $this->add( '', 'default', $this->default_privacy, $user_id );
127
+ if ( is_array( $wl ) && array_key_exists( 'share_key', $wl ) ) {
128
+ $this->set_sharekey( $wl['share_key'] );
129
 
130
  return $wl;
131
  }
140
  *
141
  * @return boolean|array
142
  */
143
+ function add_sharekey_default( $sharekey = '' ) {
144
+ if ( $wl = $this->get_by_sharekey_default( $sharekey ) ) {
145
+ return array_shift( $wl );
 
146
  }
147
 
148
+ $wl = $this->add( $this->default_name, 'default', $this->default_privacy, 0 );
149
+ if ( is_array( $wl ) && array_key_exists( 'share_key', $wl ) ) {
150
+ $this->set_sharekey( $wl['share_key'] );
151
 
152
  return $wl;
153
  }
167
  * @global wpdb $wpdb
168
  *
169
  */
170
+ function add( $data, $type = 'list', $status = 'public', $user_id = 0 ) {
171
+ $user_id = absint( $user_id );
172
+ if ( empty( $user_id ) ) {
 
173
  $user_id = $this->user;
174
  }
175
 
176
  $default = array(
177
+ 'author' => $user_id,
178
+ 'date' => current_time( 'Y-m-d H:i:s' ),
179
+ 'status' => $this->default_privacy,
180
  'share_key' => $this->unique_share_key(),
181
+ 'title' => $this->default_name,
182
+ 'type' => 'list',
183
  );
184
 
185
+ if ( ! is_array( $data ) ) {
186
  $data = array(
187
+ 'title' => $data,
188
  'status' => $status,
189
+ 'type' => $type,
190
  );
191
  }
192
+ $data = wp_parse_args( $data, $default );
193
+ $data = apply_filters( 'tinvwl_wishlist_add', $data );
194
+ if ( ! in_array( $data['status'], $this->privacy ) ) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
195
  $data['status'] = 'public';
196
  }
197
  global $wpdb;
198
+ if ( $wpdb->insert( $this->table, $data ) ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
199
  $data['ID'] = $wpdb->insert_id;
200
 
201
  /* Run a 3rd party code when a new wishlist created.
202
  *
203
  * @param array $data A wishlist data.
204
  * */
205
+ do_action( 'tinvwl_wishlist_created', $data );
206
 
207
  return $data;
208
  }
217
  *
218
  * @return array
219
  */
220
+ function get_by_user_default( $user_id = 0 ) {
221
+ $user_id = absint( $user_id );
222
+ if ( empty( $user_id ) ) {
 
223
  $user_id = $this->user;
224
  }
225
 
226
  $data = array(
227
  'author' => $user_id,
228
+ 'type' => 'default',
229
  );
230
 
231
+ if ( ! current_user_can( 'tinvwl_general_settings' ) && ( empty( $this->user ) || ( $data['author'] != $this->user ) ) ) { // WPCS: loose comparison ok.
232
  $data['status'] = 'public';
233
  }
234
 
235
+ return $this->get( $data );
236
  }
237
 
238
  /**
242
  *
243
  * @return array
244
  */
245
+ function get_by_sharekey_default( $sharekey = '' ) {
246
+ if ( empty( $sharekey ) ) {
 
247
  $sharekey = $this->get_sharekey();
248
  }
249
+ if ( empty( $sharekey ) ) {
250
  return array();
251
  }
252
 
253
  $data = array(
254
  'share_key' => $sharekey,
255
+ 'type' => 'default',
256
  );
257
 
258
+ return $this->get( $data );
259
  }
260
 
261
  /**
266
  *
267
  * @return array
268
  */
269
+ function get_by_user( $user_id = 0, $data = array() ) {
270
+ $user_id = absint( $user_id );
271
+ if ( empty( $user_id ) ) {
 
272
  $user_id = $this->user;
273
  }
274
+ $this->add_user_default( $user_id );
275
  $_data = array(
276
  'author' => $user_id,
277
  );
278
 
279
+ if ( ! current_user_can( 'tinvwl_general_settings' ) && ( empty( $this->user ) || ( $_data['author'] != $this->user ) ) ) { // WPCS: loose comparison ok.
280
  $_data['status'] = 'public';
281
  }
282
+ $data = tinv_array_merge( $data, $_data );
283
 
284
+ return $this->get( $data );
285
  }
286
 
287
  /**
291
  *
292
  * @return array
293
  */
294
+ function get_by_id( $id ) {
295
+ $id = absint( $id );
296
+ if ( empty( $id ) ) {
 
297
  return null;
298
  }
299
 
300
+ $wishlists = $this->get( array( 'ID' => $id ) );
301
+ $wishlist = array_shift( $wishlists );
302
 
303
  return $wishlist;
304
  }
310
  *
311
  * @return array
312
  */
313
+ function get_by_share_key( $share_key ) {
314
+ if ( ! preg_match( '/[a-f0-9]{6}/i', $share_key ) ) {
 
315
  return null;
316
  }
317
+ $wishlists = $this->get( array( 'share_key' => $share_key ) );
318
+ $wishlist = array_shift( $wishlists );
319
 
320
  return $wishlist;
321
  }
329
  * @global wpdb $wpdb
330
  *
331
  */
332
+ function get( $data = array() ) {
 
333
  global $wpdb;
334
 
335
  $default = array(
336
+ 'count' => 10,
337
+ 'field' => null,
338
+ 'offset' => 0,
339
+ 'order' => 'ASC',
340
  'order_by' => 'title',
341
+ 'sql' => '',
342
  );
343
 
344
+ foreach ( $default as $_k => $_v ) {
345
+ if ( array_key_exists( $_k, $data ) ) {
346
+ $default[ $_k ] = $data[ $_k ];
347
+ unset( $data[ $_k ] );
348
  }
349
  }
350
 
351
+ if ( is_array( $default['field'] ) ) {
352
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
353
+ } elseif ( is_string( $default['field'] ) ) {
354
+ $default['field'] = array( 'ID', 'type', $default['field'] );
355
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
356
  } else {
357
  $default['field'] = '*';
358
  }
359
  $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
360
 
361
  $where = '1';
362
+ if ( ! empty( $data ) && is_array( $data ) ) {
363
+ foreach ( $data as $f => $v ) {
364
+ $s = is_array( $v ) ? ' IN ' : '=';
365
+ if ( is_array( $v ) ) {
366
+ foreach ( $v as $_f => $_v ) {
367
+ $v[ $_f ] = $wpdb->prepare( '%s', $_v );
368
  }
369
+ $v = implode( ',', $v );
370
  $v = "($v)";
371
  } else {
372
+ $v = $wpdb->prepare( '%s', $v );
373
  }
374
+ $data[ $f ] = sprintf( '`%s`%s%s', $f, $s, $v );
375
  }
376
+ $where = ' WHERE ' . implode( ' AND ', $data );
377
+ $sql .= $where;
378
  }
379
+ $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
380
 
381
+ if ( ! empty( $default['sql'] ) ) {
382
+ $replacer = $replace = array();
383
+ $replace[0] = '{table}';
384
  $replacer[0] = $this->table;
385
+ $replace[1] = '{where}';
386
  $replacer[1] = $where;
387
 
388
+ foreach ( $default as $key => $value ) {
389
+ $i = count( $replace );
390
 
391
+ $replace[ $i ] = '{' . $key . '}';
392
+ $replacer[ $i ] = $value;
393
  }
394
 
395
+ $sql = str_replace( $replace, $replacer, $default['sql'] );
396
  }
397
 
398
+ $wls = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
399
 
400
+ if ( empty( $wls ) ) {
401
  return array();
402
  }
403
 
404
+ foreach ( $wls as $k => $wl ) {
405
+ $wl['ID'] = absint( $wl['ID'] );
406
+ if ( array_key_exists( 'author', $wl ) ) {
407
+ $wl['author'] = absint( $wl['author'] );
408
  }
409
+ if ( 'default' === $wl['type'] && empty( $wl['title'] ) ) {
410
  $wl['title'] = $this->default_name;
411
  }
412
 
413
+ $wls[ $k ] = apply_filters( 'tinvwl_wishlist_get', $wl );
414
  }
415
 
416
  return $wls;
428
  * @global wpdb $wpdb
429
  *
430
  */
431
+ function update( $id, $data, $type = 'list', $status = 'public' ) {
432
+ if ( ! is_array( $data ) ) {
 
433
  $data = array(
434
+ 'title' => $data,
435
  'status' => $status,
436
+ 'type' => $type,
437
  );
438
  }
439
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_fields_update', array(
440
+ 'title' => FILTER_SANITIZE_STRING,
441
  'status' => FILTER_SANITIZE_STRING,
442
+ 'type' => FILTER_SANITIZE_STRING,
443
  'author' => FILTER_VALIDATE_INT,
444
+ ) ) );
445
+ $data = array_filter( $data );
446
+ $data = apply_filters( 'tinvwl_wishlist_update', $data, $id );
447
+ if ( ! array_key_exists( 'title', $data ) ) {
448
+ $wishlist = $this->get_by_id( $id );
449
+ if ( 'default' === $wishlist['type'] ) {
450
  $data['title'] = '';
451
  }
452
  }
453
  global $wpdb;
454
 
455
+ return false !== $wpdb->update( $this->table, $data, array( 'ID' => $id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
456
  }
457
 
458
  /**
464
  * @global wpdb $wpdb
465
  *
466
  */
467
+ public function remove( $id ) {
468
+ $id = absint( $id );
469
+ if ( empty( $id ) ) {
 
470
  return false;
471
  }
472
  global $wpdb;
473
+ $result = $wpdb->delete( $this->table, array( 'ID' => $id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
474
+ if ( false !== $result ) {
475
+ do_action( 'tinvwl_wishlist_removed', $id );
476
  $wlp = new TInvWL_Product();
477
+ $wlp->remove_product_from_wl( $id );
478
 
479
  return true;
480
  }
489
  *
490
  * @return string
491
  */
492
+ function set_sharekey( $sharekey = '' ) {
 
493
  global $tinvwl_wishlist_sharekey;
494
 
495
+ if ( ! empty( $sharekey ) ) {
496
  self::$default_sharekey = $tinvwl_wishlist_sharekey = $sharekey;
497
+ @setcookie( 'tinv_wishlistkey', self::$default_sharekey, time() + 31 * DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
498
+ set_transient( '_tinvwl_update_wishlists_data', '1' );
499
  }
500
 
501
  return self::$default_sharekey;
506
  *
507
  * @return string
508
  */
509
+ function get_sharekey() {
 
510
  global $tinvwl_wishlist_sharekey;
511
 
512
+ if ( empty( self::$default_sharekey ) ) {
513
+ self::$default_sharekey = $tinvwl_wishlist_sharekey = filter_input( INPUT_COOKIE, 'tinv_wishlistkey', FILTER_VALIDATE_REGEXP, array(
514
  'options' => array(
515
+ 'regexp' => '/^[A-Fa-f0-9]{6}$/',
516
  'default' => $tinvwl_wishlist_sharekey,
517
  ),
518
+ ) );
519
  }
520
 
521
  return self::$default_sharekey;
integrations/yith-woocommerce-product-add-ons.php CHANGED
@@ -13,7 +13,7 @@
13
  */
14
 
15
  // If this file is called directly, abort.
16
- if (!defined('ABSPATH')) {
17
  exit;
18
  }
19
 
@@ -24,24 +24,24 @@ $slug = "yith-woocommerce-product-add-ons";
24
 
25
  $name = "YITH WooCommerce Product Add-Ons";
26
 
27
- $available = class_exists('YITH_WAPO');
28
 
29
- $tinvwl_integrations = is_array($tinvwl_integrations) ? $tinvwl_integrations : [];
30
 
31
- $tinvwl_integrations[$slug] = array(
32
- 'name' => $name,
33
  'available' => $available,
34
  );
35
 
36
- if (!tinv_get_option('integrations', $slug)) {
37
  return;
38
  }
39
 
40
- if (!$available) {
41
  return;
42
  }
43
 
44
- if (!function_exists('tinv_wishlist_item_meta_yith_woocommerce_product_add_on')) {
45
 
46
  /**
47
  * Set description for meta YITH WooCommerce Product Add-on
@@ -52,121 +52,126 @@ if (!function_exists('tinv_wishlist_item_meta_yith_woocommerce_product_add_on'))
52
  *
53
  * @return array
54
  */
55
- function tinv_wishlist_item_meta_yith_woocommerce_product_add_on($item_data, $product_id, $variation_id)
56
- {
57
 
58
- if (isset($item_data['yith_wapo_product_id']) && class_exists('YITH_WAPO')) {
59
- unset($item_data['yith_wapo_product_id']);
60
- unset($item_data['yith_wapo_is_single']);
61
 
62
- $id = ($variation_id) ? $variation_id : $product_id;
63
 
64
- $base_product = wc_get_product($id);
65
 
66
- if ((is_object($base_product) && get_option('yith_wapo_settings_show_product_price_cart') == 'yes')) {
67
 
68
- $price = yit_get_display_price($base_product);
69
 
70
- $price_html = wc_price($price);
71
 
72
  $item_data[] = array(
73
- 'key' => __('Base price', 'ti-woocommerce-wishlist'),
74
  'display' => $price_html,
75
  );
76
 
77
  }
78
- if (!empty($item_data['yith_wapo'])) {
79
  // $total_options_price = 0;
80
- $cart_data_array = array();
81
  $first_free_options_count = 0;
82
- foreach (json_decode($item_data['yith_wapo']['display'], true) as $index => $option) {
83
- foreach ($option as $key => $value) {
84
  if ( $key && '' !== $value ) {
85
- $value = stripslashes( $value );
86
 
87
- $explode = explode('-', $key);
88
- if (isset($explode[1])) {
89
- $addon_id = $explode[0];
90
  $option_id = $explode[1];
91
  } else {
92
- $addon_id = $key;
93
  $option_id = $value;
94
  }
95
 
96
- $info = yith_wapo_get_option_info($addon_id, $option_id);
97
- error_log( print_r($info , true ) );
98
- if ($info['price_type'] == 'percentage') {
99
- $option_percentage = floatval($info['price']);
100
- $option_percentage_sale = floatval($info['price_sale']);
101
- $option_price = ($product_price / 100) * $option_percentage;
102
- $option_price_sale = ($product_price / 100) * $option_percentage_sale;
103
- } else if ($info['price_type'] == 'multiplied') {
104
- $option_price = $info['price'] * $value;
105
  $option_price_sale = $info['price'] * $value;
106
  } else {
107
- $option_price = $info['price'];
108
  $option_price_sale = $info['price_sale'];
109
  }
110
 
111
  $sign = $info['price_method'] == 'decrease' ? '-' : '+';
112
 
113
  // First X free options check
114
- if ($info['addon_first_options_selected'] == 'yes' && $first_free_options_count < $info['addon_first_free_options']) {
115
  $option_price = 0;
116
- $first_free_options_count++;
117
  } else {
118
  $option_price = $option_price_sale > 0 ? $option_price_sale : $option_price;
119
  }
120
 
121
- $cart_data_name = ((isset($info['addon_label']) && $info['addon_label'] != '') ? $info['addon_label'] : '');
122
 
123
- if (in_array($info['addon_type'], array('checkbox', 'color', 'label', 'radio', 'select'))) {
 
 
 
 
 
 
124
  $value = $info['label'];
125
- } else if (in_array($info['addon_type'], array('product'))) {
126
- $option_product_info = explode('-', $value);
127
- $option_product_id = $option_product_info[1];
128
- $option_product_qty = $option_product_info[2];
129
- $option_product = wc_get_product($option_product_id);
130
- $value = $option_product->get_title();
131
 
132
  // product prices
133
  $product_price = $option_product->get_price();
134
- if ($info['price_method'] == 'product') {
135
  $option_price = $product_price;
136
- } else if ($info['price_method'] == 'discount') {
137
  $option_discount_value = $option_price;
138
- $option_price = $product_price - $option_discount_value;
139
- if ($info['price_type'] == 'percentage') {
140
- $option_price = $product_price - (($product_price / 100) * $option_discount_value);
141
  }
142
  }
143
 
144
- } else if (in_array($info['addon_type'], array('file'))) {
145
- $file_url = explode('/', $value);
146
- $value = '<a href="' . $value . '" target="_blank">' . end($file_url) . '</a>';
147
  } else {
148
  $cart_data_name = $info['label'];
149
  }
150
 
151
- $option_price = $option_price != '' ? ($option_price + (($option_price / 100) * yith_wapo_get_tax_rate())) : 0;
152
 
153
- if (get_option('yith_wapo_show_options_in_cart') == 'yes') {
154
- if (!isset($cart_data_array[$cart_data_name])) {
155
- $cart_data_array[$cart_data_name] = '';
156
  }
157
- $cart_data_array[$cart_data_name] .= '<div>' . $value . ($option_price != '' ? ' (' . $sign . wc_price($option_price) . ')' : '') . '</div>';
158
  }
159
 
160
  }
161
  }
162
  }
163
- foreach ($cart_data_array as $key => $value) {
164
  $item_data[] = array(
165
- 'key' => $key,
166
  'display' => $value,
167
  );
168
  }
169
- unset($item_data['yith_wapo']);
170
 
171
  }
172
 
@@ -175,10 +180,10 @@ if (!function_exists('tinv_wishlist_item_meta_yith_woocommerce_product_add_on'))
175
  return $item_data;
176
  }
177
 
178
- add_filter('tinvwl_wishlist_item_meta_post', 'tinv_wishlist_item_meta_yith_woocommerce_product_add_on', 10, 3);
179
  } // End if().
180
 
181
- if (!function_exists('tinvwl_item_price_yith_woocommerce_product_add_on')) {
182
 
183
  /**
184
  * Modify price for YITH WooCommerce product Addons.
@@ -189,79 +194,78 @@ if (!function_exists('tinvwl_item_price_yith_woocommerce_product_add_on')) {
189
  *
190
  * @return string
191
  */
192
- function tinvwl_item_price_yith_woocommerce_product_add_on($price, $wl_product, $product)
193
- {
194
 
195
- if (class_exists('YITH_WAPO')) {
196
 
197
- if (!empty($wl_product['meta']['yith_wapo'])) {
198
- $total_options_price = 0;
199
  $first_free_options_count = 0;
200
- foreach (json_decode($wl_product['meta']['yith_wapo'], true) as $index => $option) {
201
- foreach ($option as $key => $value) {
202
  if ( $key && '' !== $value ) {
203
- $value = stripslashes( $value );
204
 
205
- $explode = explode('-', $key);
206
- if (isset($explode[1])) {
207
- $addon_id = $explode[0];
208
  $option_id = $explode[1];
209
  } else {
210
- $addon_id = $key;
211
  $option_id = $value;
212
  }
213
 
214
- $info = yith_wapo_get_option_info($addon_id, $option_id);
215
 
216
- if ($info['price_type'] == 'percentage') {
217
  $_product = $product;
218
  // WooCommerce Measurement Price Calculator (compatibility)
219
- if (isset($cart_item['pricing_item_meta_data']['_price'])) {
220
  $product_price = $cart_item['pricing_item_meta_data']['_price'];
221
  } else {
222
- $product_price = floatval($_product->get_price());
223
  }
224
- $option_percentage = floatval($info['price']);
225
- $option_percentage_sale = floatval($info['price_sale']);
226
- $option_price = ($product_price / 100) * $option_percentage;
227
- $option_price_sale = ($product_price / 100) * $option_percentage_sale;
228
- } else if ($info['price_type'] == 'multiplied') {
229
- $option_price = $info['price'] * $value;
230
  $option_price_sale = $info['price'] * $value;
231
  } else {
232
- $option_price = $info['price'];
233
  $option_price_sale = $info['price_sale'];
234
  }
235
 
236
  // First X free options check
237
- if ($info['addon_first_options_selected'] == 'yes' && $first_free_options_count < $info['addon_first_free_options']) {
238
- $first_free_options_count++;
239
  } else {
240
  $option_price = $option_price_sale > 0 ? $option_price_sale : $option_price;
241
 
242
 
243
- if (in_array($info['addon_type'], array('product')) && ($info['price_method'] == 'product' || $info['price_method'] == 'discount')) {
244
- $option_product_info = explode('-', $value);
245
- $option_product_id = $option_product_info[1];
246
- $option_product_qty = $option_product_info[2];
247
- $option_product = wc_get_product($option_product_id);
248
- $value = $option_product->get_title();
249
- $product_price = $option_product->get_price();
250
- if ($info['price_method'] == 'product') {
251
  $option_price = $product_price;
252
- } else if ($info['price_method'] == 'discount') {
253
  $option_discount_value = $option_price;
254
- $option_price = $product_price - $option_discount_value;
255
- if ($info['price_type'] == 'percentage') {
256
- $option_price = $product_price - (($product_price / 100) * $option_discount_value);
257
  }
258
  }
259
- $total_options_price += floatval($option_price);
260
 
261
- } else if ($info['price_method'] == 'decrease') {
262
- $total_options_price -= floatval($option_price);
263
  } else {
264
- $total_options_price += floatval($option_price);
265
  }
266
  }
267
 
@@ -270,7 +274,7 @@ if (!function_exists('tinvwl_item_price_yith_woocommerce_product_add_on')) {
270
  }
271
 
272
  $base_price = $product->get_price();
273
- $price = wc_price($base_price + $total_options_price);
274
 
275
  }
276
  }
@@ -278,22 +282,21 @@ if (!function_exists('tinvwl_item_price_yith_woocommerce_product_add_on')) {
278
  return $price;
279
  }
280
 
281
- add_filter('tinvwl_wishlist_item_price', 'tinvwl_item_price_yith_woocommerce_product_add_on', 10, 3);
282
  } // End if().
283
 
284
- if (!function_exists('tinvwl_add_to_cart_meta_yith_woocommerce_product_add_on')) {
285
 
286
- function tinvwl_add_to_cart_meta_yith_woocommerce_product_add_on($wl_product)
287
- {
288
- if (class_exists('YITH_WAPO')) {
289
 
290
- if (!empty($wl_product['meta']['yith_wapo'])) {
291
- $wl_product['meta']['yith_wapo'] = json_decode($wl_product['meta']['yith_wapo'], true);
292
  }
293
  }
294
 
295
  return $wl_product;
296
  }
297
 
298
- add_filter('tinvwl_addproduct_tocart', 'tinvwl_add_to_cart_meta_yith_woocommerce_product_add_on');
299
  } // End if().
13
  */
14
 
15
  // If this file is called directly, abort.
16
+ if ( ! defined( 'ABSPATH' ) ) {
17
  exit;
18
  }
19
 
24
 
25
  $name = "YITH WooCommerce Product Add-Ons";
26
 
27
+ $available = class_exists( 'YITH_WAPO' );
28
 
29
+ $tinvwl_integrations = is_array( $tinvwl_integrations ) ? $tinvwl_integrations : [];
30
 
31
+ $tinvwl_integrations[ $slug ] = array(
32
+ 'name' => $name,
33
  'available' => $available,
34
  );
35
 
36
+ if ( ! tinv_get_option( 'integrations', $slug ) ) {
37
  return;
38
  }
39
 
40
+ if ( ! $available ) {
41
  return;
42
  }
43
 
44
+ if ( ! function_exists( 'tinv_wishlist_item_meta_yith_woocommerce_product_add_on' ) ) {
45
 
46
  /**
47
  * Set description for meta YITH WooCommerce Product Add-on
52
  *
53
  * @return array
54
  */
55
+ function tinv_wishlist_item_meta_yith_woocommerce_product_add_on( $item_data, $product_id, $variation_id ) {
 
56
 
57
+ if ( isset( $item_data['yith_wapo_product_id'] ) && class_exists( 'YITH_WAPO' ) ) {
58
+ unset( $item_data['yith_wapo_product_id'] );
59
+ unset( $item_data['yith_wapo_is_single'] );
60
 
61
+ $id = ( $variation_id ) ? $variation_id : $product_id;
62
 
63
+ $base_product = wc_get_product( $id );
64
 
65
+ if ( ( is_object( $base_product ) && get_option( 'yith_wapo_settings_show_product_price_cart' ) == 'yes' ) ) {
66
 
67
+ $price = yit_get_display_price( $base_product );
68
 
69
+ $price_html = wc_price( $price );
70
 
71
  $item_data[] = array(
72
+ 'key' => __( 'Base price', 'ti-woocommerce-wishlist' ),
73
  'display' => $price_html,
74
  );
75
 
76
  }
77
+ if ( ! empty( $item_data['yith_wapo'] ) ) {
78
  // $total_options_price = 0;
79
+ $cart_data_array = array();
80
  $first_free_options_count = 0;
81
+ foreach ( json_decode( $item_data['yith_wapo']['display'], true ) as $index => $option ) {
82
+ foreach ( $option as $key => $value ) {
83
  if ( $key && '' !== $value ) {
84
+ $value = stripslashes( $value );
85
 
86
+ $explode = explode( '-', $key );
87
+ if ( isset( $explode[1] ) ) {
88
+ $addon_id = $explode[0];
89
  $option_id = $explode[1];
90
  } else {
91
+ $addon_id = $key;
92
  $option_id = $value;
93
  }
94
 
95
+ $info = yith_wapo_get_option_info( $addon_id, $option_id );
96
+
97
+ if ( $info['price_type'] == 'percentage' ) {
98
+ $option_percentage = floatval( $info['price'] );
99
+ $option_percentage_sale = floatval( $info['price_sale'] );
100
+ $option_price = ( $product_price / 100 ) * $option_percentage;
101
+ $option_price_sale = ( $product_price / 100 ) * $option_percentage_sale;
102
+ } else if ( $info['price_type'] == 'multiplied' ) {
103
+ $option_price = $info['price'] * $value;
104
  $option_price_sale = $info['price'] * $value;
105
  } else {
106
+ $option_price = $info['price'];
107
  $option_price_sale = $info['price_sale'];
108
  }
109
 
110
  $sign = $info['price_method'] == 'decrease' ? '-' : '+';
111
 
112
  // First X free options check
113
+ if ( $info['addon_first_options_selected'] == 'yes' && $first_free_options_count < $info['addon_first_free_options'] ) {
114
  $option_price = 0;
115
+ $first_free_options_count ++;
116
  } else {
117
  $option_price = $option_price_sale > 0 ? $option_price_sale : $option_price;
118
  }
119
 
120
+ $cart_data_name = ( ( isset( $info['addon_label'] ) && $info['addon_label'] != '' ) ? $info['addon_label'] : '' );
121
 
122
+ if ( in_array( $info['addon_type'], array(
123
+ 'checkbox',
124
+ 'color',
125
+ 'label',
126
+ 'radio',
127
+ 'select'
128
+ ) ) ) {
129
  $value = $info['label'];
130
+ } else if ( in_array( $info['addon_type'], array( 'product' ) ) ) {
131
+ $option_product_info = explode( '-', $value );
132
+ $option_product_id = $option_product_info[1];
133
+ $option_product_qty = $option_product_info[2];
134
+ $option_product = wc_get_product( $option_product_id );
135
+ $value = $option_product->get_title();
136
 
137
  // product prices
138
  $product_price = $option_product->get_price();
139
+ if ( $info['price_method'] == 'product' ) {
140
  $option_price = $product_price;
141
+ } else if ( $info['price_method'] == 'discount' ) {
142
  $option_discount_value = $option_price;
143
+ $option_price = $product_price - $option_discount_value;
144
+ if ( $info['price_type'] == 'percentage' ) {
145
+ $option_price = $product_price - ( ( $product_price / 100 ) * $option_discount_value );
146
  }
147
  }
148
 
149
+ } else if ( in_array( $info['addon_type'], array( 'file' ) ) ) {
150
+ $file_url = explode( '/', $value );
151
+ $value = '<a href="' . $value . '" target="_blank">' . end( $file_url ) . '</a>';
152
  } else {
153
  $cart_data_name = $info['label'];
154
  }
155
 
156
+ $option_price = $option_price != '' ? ( $option_price + ( ( $option_price / 100 ) * yith_wapo_get_tax_rate() ) ) : 0;
157
 
158
+ if ( get_option( 'yith_wapo_show_options_in_cart' ) == 'yes' ) {
159
+ if ( ! isset( $cart_data_array[ $cart_data_name ] ) ) {
160
+ $cart_data_array[ $cart_data_name ] = '';
161
  }
162
+ $cart_data_array[ $cart_data_name ] .= '<div>' . $value . ( $option_price != '' ? ' (' . $sign . wc_price( $option_price ) . ')' : '' ) . '</div>';
163
  }
164
 
165
  }
166
  }
167
  }
168
+ foreach ( $cart_data_array as $key => $value ) {
169
  $item_data[] = array(
170
+ 'key' => $key,
171
  'display' => $value,
172
  );
173
  }
174
+ unset( $item_data['yith_wapo'] );
175
 
176
  }
177
 
180
  return $item_data;
181
  }
182
 
183
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_item_meta_yith_woocommerce_product_add_on', 10, 3 );
184
  } // End if().
185
 
186
+ if ( ! function_exists( 'tinvwl_item_price_yith_woocommerce_product_add_on' ) ) {
187
 
188
  /**
189
  * Modify price for YITH WooCommerce product Addons.
194
  *
195
  * @return string
196
  */
197
+ function tinvwl_item_price_yith_woocommerce_product_add_on( $price, $wl_product, $product ) {
 
198
 
199
+ if ( class_exists( 'YITH_WAPO' ) ) {
200
 
201
+ if ( ! empty( $wl_product['meta']['yith_wapo'] ) ) {
202
+ $total_options_price = 0;
203
  $first_free_options_count = 0;
204
+ foreach ( json_decode( $wl_product['meta']['yith_wapo'], true ) as $index => $option ) {
205
+ foreach ( $option as $key => $value ) {
206
  if ( $key && '' !== $value ) {
207
+ $value = stripslashes( $value );
208
 
209
+ $explode = explode( '-', $key );
210
+ if ( isset( $explode[1] ) ) {
211
+ $addon_id = $explode[0];
212
  $option_id = $explode[1];
213
  } else {
214
+ $addon_id = $key;
215
  $option_id = $value;
216
  }
217
 
218
+ $info = yith_wapo_get_option_info( $addon_id, $option_id );
219
 
220
+ if ( $info['price_type'] == 'percentage' ) {
221
  $_product = $product;
222
  // WooCommerce Measurement Price Calculator (compatibility)
223
+ if ( isset( $cart_item['pricing_item_meta_data']['_price'] ) ) {
224
  $product_price = $cart_item['pricing_item_meta_data']['_price'];
225
  } else {
226
+ $product_price = floatval( $_product->get_price() );
227
  }
228
+ $option_percentage = floatval( $info['price'] );
229
+ $option_percentage_sale = floatval( $info['price_sale'] );
230
+ $option_price = ( $product_price / 100 ) * $option_percentage;
231
+ $option_price_sale = ( $product_price / 100 ) * $option_percentage_sale;
232
+ } else if ( $info['price_type'] == 'multiplied' ) {
233
+ $option_price = $info['price'] * $value;
234
  $option_price_sale = $info['price'] * $value;
235
  } else {
236
+ $option_price = $info['price'];
237
  $option_price_sale = $info['price_sale'];
238
  }
239
 
240
  // First X free options check
241
+ if ( $info['addon_first_options_selected'] == 'yes' && $first_free_options_count < $info['addon_first_free_options'] ) {
242
+ $first_free_options_count ++;
243
  } else {
244
  $option_price = $option_price_sale > 0 ? $option_price_sale : $option_price;
245
 
246
 
247
+ if ( in_array( $info['addon_type'], array( 'product' ) ) && ( $info['price_method'] == 'product' || $info['price_method'] == 'discount' ) ) {
248
+ $option_product_info = explode( '-', $value );
249
+ $option_product_id = $option_product_info[1];
250
+ $option_product_qty = $option_product_info[2];
251
+ $option_product = wc_get_product( $option_product_id );
252
+ $value = $option_product->get_title();
253
+ $product_price = $option_product->get_price();
254
+ if ( $info['price_method'] == 'product' ) {
255
  $option_price = $product_price;
256
+ } else if ( $info['price_method'] == 'discount' ) {
257
  $option_discount_value = $option_price;
258
+ $option_price = $product_price - $option_discount_value;
259
+ if ( $info['price_type'] == 'percentage' ) {
260
+ $option_price = $product_price - ( ( $product_price / 100 ) * $option_discount_value );
261
  }
262
  }
263
+ $total_options_price += floatval( $option_price );
264
 
265
+ } else if ( $info['price_method'] == 'decrease' ) {
266
+ $total_options_price -= floatval( $option_price );
267
  } else {
268
+ $total_options_price += floatval( $option_price );
269
  }
270
  }
271
 
274
  }
275
 
276
  $base_price = $product->get_price();
277
+ $price = wc_price( $base_price + $total_options_price );
278
 
279
  }
280
  }
282
  return $price;
283
  }
284
 
285
+ add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_yith_woocommerce_product_add_on', 10, 3 );
286
  } // End if().
287
 
288
+ if ( ! function_exists( 'tinvwl_add_to_cart_meta_yith_woocommerce_product_add_on' ) ) {
289
 
290
+ function tinvwl_add_to_cart_meta_yith_woocommerce_product_add_on( $wl_product ) {
291
+ if ( class_exists( 'YITH_WAPO' ) ) {
 
292
 
293
+ if ( ! empty( $wl_product['meta']['yith_wapo'] ) ) {
294
+ $wl_product['meta']['yith_wapo'] = json_decode( $wl_product['meta']['yith_wapo'], true );
295
  }
296
  }
297
 
298
  return $wl_product;
299
  }
300
 
301
+ add_filter( 'tinvwl_addproduct_tocart', 'tinvwl_add_to_cart_meta_yith_woocommerce_product_add_on' );
302
  } // End if().
languages/ti-woocommerce-wishlist.pot CHANGED
@@ -1,8 +1,8 @@
1
- # Copyright (C) 2022 TI WooCommerce Wishlist Plugin - 1.41.0
2
- # This file is distributed under the same license as the TI WooCommerce Wishlist Plugin - 1.41.0 package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: TI WooCommerce Wishlist Plugin - 1.41.0\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
@@ -11,7 +11,7 @@ msgstr ""
11
  "Language-Team: TemplateInvaders (https://templateinvaders.com/)\n"
12
  "Last-Translator: TemplateInvaders (https://templateinvaders.com/)\n"
13
  "MIME-Version: 1.0\n"
14
- "Project-Id-Version: TI WooCommerce Wishlist Plugin - 1.41.0\n"
15
  "Report-Msgid-Bugs-To: https://templateinvaders.com/help/\n"
16
  "X-Poedit-Basepath: ..\n"
17
  "X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
@@ -1204,7 +1204,7 @@ msgstr ""
1204
  msgid "Wishlist Button"
1205
  msgstr ""
1206
 
1207
- #: integrations/yith-woocommerce-product-add-ons.php:73
1208
  msgid "Base price"
1209
  msgstr ""
1210
 
@@ -1212,15 +1212,15 @@ msgstr ""
1212
  msgid "Out of stock"
1213
  msgstr ""
1214
 
1215
- #: public/addtowishlist.class.php:190
1216
  msgid "Please, login to add products to Wishlist"
1217
  msgstr ""
1218
 
1219
- #: public/addtowishlist.class.php:192
1220
  msgid "Login"
1221
  msgstr ""
1222
 
1223
- #: public/addtowishlist.class.php:211
1224
  msgid "Something went wrong"
1225
  msgstr ""
1226
 
1
+ # Copyright (C) 2022 TI WooCommerce Wishlist Plugin - 1.41.1
2
+ # This file is distributed under the same license as the TI WooCommerce Wishlist Plugin - 1.41.1 package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: TI WooCommerce Wishlist Plugin - 1.41.1\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
11
  "Language-Team: TemplateInvaders (https://templateinvaders.com/)\n"
12
  "Last-Translator: TemplateInvaders (https://templateinvaders.com/)\n"
13
  "MIME-Version: 1.0\n"
14
+ "Project-Id-Version: TI WooCommerce Wishlist Plugin - 1.41.1\n"
15
  "Report-Msgid-Bugs-To: https://templateinvaders.com/help/\n"
16
  "X-Poedit-Basepath: ..\n"
17
  "X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
1204
  msgid "Wishlist Button"
1205
  msgstr ""
1206
 
1207
+ #: integrations/yith-woocommerce-product-add-ons.php:72
1208
  msgid "Base price"
1209
  msgstr ""
1210
 
1212
  msgid "Out of stock"
1213
  msgstr ""
1214
 
1215
+ #: public/addtowishlist.class.php:187
1216
  msgid "Please, login to add products to Wishlist"
1217
  msgstr ""
1218
 
1219
+ #: public/addtowishlist.class.php:189
1220
  msgid "Login"
1221
  msgstr ""
1222
 
1223
+ #: public/addtowishlist.class.php:208
1224
  msgid "Something went wrong"
1225
  msgstr ""
1226
 
public/addtowishlist.class.php CHANGED
@@ -22,7 +22,6 @@ class TInvWL_Public_AddToWishlist {
22
  * @var string
23
  */
24
  private $_name;
25
-
26
  /**
27
  * Global product
28
  *
@@ -35,7 +34,6 @@ class TInvWL_Public_AddToWishlist {
35
  * @var array
36
  */
37
  private $user_wishlist;
38
-
39
  /**
40
  * This wishlists and product
41
  *
@@ -56,7 +54,6 @@ class TInvWL_Public_AddToWishlist {
56
  * @var bolean
57
  */
58
  private $is_loop;
59
-
60
  /**
61
  * This class
62
  *
@@ -328,7 +325,7 @@ class TInvWL_Public_AddToWishlist {
328
  }
329
 
330
  if ( $status && tinv_get_option( 'general', 'redirect' ) && tinv_get_option( 'page', 'wishlist' ) && tinv_get_option( 'general', 'show_notice' ) ) {
331
- $data['redirect'] = $data['wishlist_url'];
332
  }
333
 
334
  $product = $original_product = wc_get_product( $post['product_id'] );
@@ -378,20 +375,14 @@ class TInvWL_Public_AddToWishlist {
378
 
379
  function get_wishlists_data( $share_key ) {
380
 
381
- global $wpdb, $sitepress;
382
 
383
  $table = sprintf( '%s%s', $wpdb->prefix, 'tinvwl_items' );
384
  $table_lists = sprintf( '%s%s', $wpdb->prefix, 'tinvwl_lists' );
385
  $table_translations = sprintf( '%s%s', $wpdb->prefix, 'icl_translations' );
386
  $table_languages = sprintf( '%s%s', $wpdb->prefix, 'icl_languages' );
387
  $lang = filter_input( INPUT_POST, 'lang', FILTER_SANITIZE_STRING );
388
-
389
- if ( $sitepress && $sitepress instanceof SitePress ) {
390
- $wpml_settings = $sitepress->get_settings();
391
- if ( isset( $wpml_settings['custom_posts_sync_option'] ) && isset( $wpml_settings['custom_posts_sync_option']['product'] ) && '1' !== $wpml_settings['custom_posts_sync_option']['product'] ) {
392
- $lang = false;
393
- }
394
- }
395
 
396
  $data = $products = $wishlists = $results = array();
397
 
@@ -434,14 +425,20 @@ class TInvWL_Public_AddToWishlist {
434
  $sql .= " AND `{$table_lists}`.`share_key` = '{$share_key}'";
435
  }
436
  if ( $lang ) {
 
 
 
 
 
 
437
  $sql .= "LEFT JOIN {$table_translations} tr ON
438
  {$table}.product_id = tr.element_id AND tr.element_type = 'post_product'
439
  LEFT JOIN {$table_translations} tr2 ON
440
  {$table}.variation_id != 0 AND {$table}.variation_id = tr2.element_id AND tr2.element_type = 'post_product_variation'
441
  LEFT JOIN {$table_translations} t ON
442
- tr.trid = t.trid AND t.element_type = 'post_product' AND t.language_code = '{$lang}'
443
  LEFT JOIN {$table_translations} t2 ON
444
- {$table}.variation_id != 0 AND tr2.trid = t2.trid AND t2.element_type = 'post_product_variation' AND t2.language_code = '{$lang}'
445
  JOIN {$table_languages} l ON
446
  (
447
  t.language_code = l.code OR t2.language_code = l.code
@@ -482,7 +479,7 @@ JOIN {$table_languages} l ON
482
  $sql .= ' WHERE ' . $where;
483
  }
484
 
485
- $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
486
 
487
  if ( ! empty( $default['sql'] ) ) {
488
  $replacer = $replace = array();
@@ -541,6 +538,10 @@ JOIN {$table_languages} l ON
541
  $response['lang'] = $lang;
542
  }
543
 
 
 
 
 
544
  return $response;
545
  }
546
 
22
  * @var string
23
  */
24
  private $_name;
 
25
  /**
26
  * Global product
27
  *
34
  * @var array
35
  */
36
  private $user_wishlist;
 
37
  /**
38
  * This wishlists and product
39
  *
54
  * @var bolean
55
  */
56
  private $is_loop;
 
57
  /**
58
  * This class
59
  *
325
  }
326
 
327
  if ( $status && tinv_get_option( 'general', 'redirect' ) && tinv_get_option( 'page', 'wishlist' ) && tinv_get_option( 'general', 'show_notice' ) ) {
328
+ $data['redirect'] = apply_filters( 'tinvwl_addtowishlist_redirect', $data['wishlist_url'] );
329
  }
330
 
331
  $product = $original_product = wc_get_product( $post['product_id'] );
375
 
376
  function get_wishlists_data( $share_key ) {
377
 
378
+ global $wpdb;
379
 
380
  $table = sprintf( '%s%s', $wpdb->prefix, 'tinvwl_items' );
381
  $table_lists = sprintf( '%s%s', $wpdb->prefix, 'tinvwl_lists' );
382
  $table_translations = sprintf( '%s%s', $wpdb->prefix, 'icl_translations' );
383
  $table_languages = sprintf( '%s%s', $wpdb->prefix, 'icl_languages' );
384
  $lang = filter_input( INPUT_POST, 'lang', FILTER_SANITIZE_STRING );
385
+ $lang_default = filter_input( INPUT_POST, 'lang_default', FILTER_SANITIZE_STRING );
 
 
 
 
 
 
386
 
387
  $data = $products = $wishlists = $results = array();
388
 
425
  $sql .= " AND `{$table_lists}`.`share_key` = '{$share_key}'";
426
  }
427
  if ( $lang ) {
428
+ if ( $lang_default ) {
429
+ $lang = sprintf( "'%s'", implode( "', '", array( $lang, $lang_default ) ) );
430
+ } else {
431
+ $lang = "'" . $lang . "'";
432
+ }
433
+
434
  $sql .= "LEFT JOIN {$table_translations} tr ON
435
  {$table}.product_id = tr.element_id AND tr.element_type = 'post_product'
436
  LEFT JOIN {$table_translations} tr2 ON
437
  {$table}.variation_id != 0 AND {$table}.variation_id = tr2.element_id AND tr2.element_type = 'post_product_variation'
438
  LEFT JOIN {$table_translations} t ON
439
+ tr.trid = t.trid AND t.element_type = 'post_product' AND t.language_code IN ({$lang})
440
  LEFT JOIN {$table_translations} t2 ON
441
+ {$table}.variation_id != 0 AND tr2.trid = t2.trid AND t2.element_type = 'post_product_variation' AND t2.language_code IN ({$lang})
442
  JOIN {$table_languages} l ON
443
  (
444
  t.language_code = l.code OR t2.language_code = l.code
479
  $sql .= ' WHERE ' . $where;
480
  }
481
 
482
+ $sql .= sprintf( ' GROUP BY `%s`.ID ORDER BY `%s` %s LIMIT %d,%d;', $table, $default['order_by'], $default['order'], $default['offset'], $default['count'] );
483
 
484
  if ( ! empty( $default['sql'] ) ) {
485
  $replacer = $replace = array();
538
  $response['lang'] = $lang;
539
  }
540
 
541
+ if ( $lang_default ) {
542
+ $response['lang_default'] = $lang_default;
543
+ }
544
+
545
  return $response;
546
  }
547
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: templateinvaders
3
  Tags: woocommerce, wishlist, woocommerce wishlist, e-commerce, ecommerce
4
  Requires at least: 4.7
5
  Tested up to: 5.9
6
- Stable tag: 1.41.0
7
  License: GPLv3
8
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
9
  Plugin URI: https://wordpress.org/plugins/ti-woocommerce-wishlist/
@@ -163,6 +163,14 @@ Yes, you can! Join in on our [GitHub repository](https://github.com/TemplateInva
163
 
164
 
165
  == Changelog ==
 
 
 
 
 
 
 
 
166
  = 1.41.0 =
167
  *Release Date - 17 February 2022*
168
 
3
  Tags: woocommerce, wishlist, woocommerce wishlist, e-commerce, ecommerce
4
  Requires at least: 4.7
5
  Tested up to: 5.9
6
+ Stable tag: 1.41.1
7
  License: GPLv3
8
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
9
  Plugin URI: https://wordpress.org/plugins/ti-woocommerce-wishlist/
163
 
164
 
165
  == Changelog ==
166
+ = 1.41.1 =
167
+ *Release Date - 20 February 2022*
168
+
169
+ * Added feature to automatically close add to wishlist popup after few seconds if redirect disabled
170
+ * Added filter `tinvwl_addtowishlist_redirect`
171
+ * Fixed WPML plugin issue
172
+ * Fixed add to wishlist issue for guests
173
+
174
  = 1.41.0 =
175
  *Release Date - 17 February 2022*
176
 
ti-woocommerce-wishlist.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: TI WooCommerce Wishlist
5
  * Plugin URI: https://wordpress.org/plugins/ti-woocommerce-wishlist/
6
  * Description: Wishlist functionality for your WooCommerce store.
7
- * Version: 1.41.0
8
  * Requires at least: 4.7
9
  * Tested up to: 5.9
10
  * WC requires at least: 3.0
@@ -41,7 +41,7 @@ if (!defined('TINVWL_DOMAIN')) {
41
  }
42
 
43
  if (!defined('TINVWL_FVERSION')) {
44
- define('TINVWL_FVERSION', '1.41.0');
45
  }
46
 
47
  if (!defined('TINVWL_LOAD_FREE')) {
4
  * Plugin Name: TI WooCommerce Wishlist
5
  * Plugin URI: https://wordpress.org/plugins/ti-woocommerce-wishlist/
6
  * Description: Wishlist functionality for your WooCommerce store.
7
+ * Version: 1.41.1
8
  * Requires at least: 4.7
9
  * Tested up to: 5.9
10
  * WC requires at least: 3.0
41
  }
42
 
43
  if (!defined('TINVWL_FVERSION')) {
44
+ define('TINVWL_FVERSION', '1.41.1');
45
  }
46
 
47
  if (!defined('TINVWL_LOAD_FREE')) {