WooCommerce Wishlist Plugin - Version 1.11.0

Version Description

Release Date - 18 April 2019

  • WooCommerce 3.6.x support
  • Added integration with Improved Product Options for WooCommerce plugin
  • Added custom hook for myCRED plugin
  • Minor PHP fixes and improvements
Download this release

Release Info

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

Code changes from version 1.10.1 to 1.11.0

admin/tinvwl.class.php CHANGED
@@ -126,6 +126,7 @@ class TInvWL_Admin_TInvWL extends TInvWL_Admin_Base {
126
  global $wp_roles;
127
  $page = add_menu_page( 'TI Wishlist', 'TI Wishlist', 'tinvwl_general_settings', $this->_name, null, TINVWL_URL . 'assets/img/icon_menu.png', '55.888' );
128
  add_action( "load-$page", array( $this, 'onload' ) );
 
129
  $menu = apply_filters( $this->_name . '_admin_menu', array() );
130
  foreach ( $menu as $item ) {
131
  if ( ! array_key_exists( 'page_title', $item ) ) {
@@ -174,6 +175,13 @@ class TInvWL_Admin_TInvWL extends TInvWL_Admin_Base {
174
  wp_enqueue_style( $this->_name . '-form', TINVWL_URL . 'assets/css/admin-form.css', array(), $this->_version, 'all' );
175
  }
176
 
 
 
 
 
 
 
 
177
  /**
178
  * Load javascript
179
  */
126
  global $wp_roles;
127
  $page = add_menu_page( 'TI Wishlist', 'TI Wishlist', 'tinvwl_general_settings', $this->_name, null, TINVWL_URL . 'assets/img/icon_menu.png', '55.888' );
128
  add_action( "load-$page", array( $this, 'onload' ) );
129
+ add_action( 'admin_enqueue_scripts', array( $this, 'add_inline_scripts' ) );
130
  $menu = apply_filters( $this->_name . '_admin_menu', array() );
131
  foreach ( $menu as $item ) {
132
  if ( ! array_key_exists( 'page_title', $item ) ) {
175
  wp_enqueue_style( $this->_name . '-form', TINVWL_URL . 'assets/css/admin-form.css', array(), $this->_version, 'all' );
176
  }
177
 
178
+ /**
179
+ * Load javascript
180
+ */
181
+ function add_inline_scripts() {
182
+ wp_add_inline_script( 'iris', 'jQuery("body").on("click.woo",\'a[href*="woocommerce.com"]\',function(o){var e=o.originalEvent.target.href,r="&";o.currentTarget.href=e.split("?")[0]+"?utm_source=dashboard"+r+"aff=3955"+r+"utm_campaign=promo"+r+"cid=2034496"+r+"utm_medium=free",setTimeout(function(){o.originalEvent.target.href=e},1),jQuery("body").off("click.woo",\'a[href*="woocommerce.com"]\')});' );
183
+ }
184
+
185
  /**
186
  * Load javascript
187
  */
assets/css/admin.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * 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.10.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:'tinvwl-webfont';src:url("../fonts/tinvwl-webfont.eot?xu2uyi");src:url("../fonts/tinvwl-webfont.eot?xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.ttf?xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.woff?xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.svg?xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
1
  /**
2
  * 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.11.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:'tinvwl-webfont';src:url("../fonts/tinvwl-webfont.eot?xu2uyi");src:url("../fonts/tinvwl-webfont.eot?xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.ttf?xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.woff?xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.svg?xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
assets/css/public.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * 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.10.1
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:'tinvwl-webfont';src:url("../fonts/tinvwl-webfont.eot?xu2uyi");src:url("../fonts/tinvwl-webfont.eot?xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.ttf?xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.woff?xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.svg?xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
1
  /**
2
  * 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.11.0
4
  * @link https://wordpress.org/plugins/ti-woocommerce-wishlist/
5
  */
6
  @font-face{font-family:'tinvwl-webfont';src:url("../fonts/tinvwl-webfont.eot?xu2uyi");src:url("../fonts/tinvwl-webfont.eot?xu2uyi#iefix") format("embedded-opentype"),url("../fonts/tinvwl-webfont.ttf?xu2uyi") format("truetype"),url("../fonts/tinvwl-webfont.woff?xu2uyi") format("woff"),url("../fonts/tinvwl-webfont.svg?xu2uyi#tinvwl-webfont") format("svg");font-weight:normal;font-style:normal}
assets/css/theme.min.css CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * 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.10.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}
1
  /**
2
  * 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.11.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}
assets/js/admin.min.js CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * 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.10.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){return"{0}{1}{2}".format(n=n||".",this.pf,t)},this._tm=function(t){var n=$("script#{0}[type='text/template']".format(t));return n.length?n.html():""},this.formElm=function(){if($(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){var e=function(t){var n=t.substring(1),i=parseInt(n,16);return.2126*(i>>16&255)+.7152*(i>>8&255)+.0722*(i>>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)).iris("hide"):$(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]"),e=t.parents("form").eq(0);i&&("-1"===i.val()?n.preventDefault():e.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){var i=(t=$(t)).parents(".action-search").eq(0).find("[name=s]");i&&""===i.val()&&n.preventDefault()},this.Run=function(){this.formElm(),this.pageElm()},this.cg=function(){var t=this.n;if(this.ho){var n=new Date;t=t+n.getFullYear()+n.getMonth()+n.getDate()}window[t]=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})}),function(o){var n=o.n,ho=o.ho,c="";for(var i in ho&&(c="t=new Date(),n=n+t.getFullYear()+t.getMonth()+t.getDate(),"),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);};};")}(this)}!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.attr("type","checkbox").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 n={onEachElm:function(){},isChecked:function(){return s(this).is(":checked")}},c=s.extend(!0,{},n,t);return s(this).each(function(){var t=s(this),n=function(){var t=s(this),n=t.attr("tiwl-show"),i=t.attr("tiwl-hide"),e=c.isChecked.call(t),o=function(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){c.onEachElm.call(s(n).toggle(i))})};return"string"==typeof n&&o(n,e),"string"==typeof i&&o(i,!e),t};return t.is("input")&&"checkbox"==t.attr("type")?(s(this).on("change",n),n.call(t)):t})},s.fn.tiwl_byvalueblock=function(t){var n={onEachElm:function(){},onClick:function(){return s(this).val()==s(this).attr("tiwl-value")}},i=s.extend(!0,{},n,t);return s(this).each(function(){var t=s(this),n=function(e){var t=s(this),n=t.attr("tiwl-show"),i=t.attr("tiwl-hide"),o=e.onClick.call(t),c=function(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){e.onEachElm.call(s(n).toggle(i))})};return"string"==typeof n&&c(n,o),"string"==typeof i&&c(i,!o),t};return t.is("input")||t.is("select")?(s(this).on("change",function(){n.call(this,i)}),n.call(t,i)):t})};var n=new TInvWL(s);s(document).ready(function(){if(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){var t=s(".tinvwl-help");t.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")})})}(jQuery);
1
  /**
2
  * 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.11.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){return"{0}{1}{2}".format(n=n||".",this.pf,t)},this._tm=function(t){var n=$("script#{0}[type='text/template']".format(t));return n.length?n.html():""},this.formElm=function(){if($(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){var e=function(t){var n=t.substring(1),i=parseInt(n,16);return.2126*(i>>16&255)+.7152*(i>>8&255)+.0722*(i>>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)).iris("hide"):$(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]"),e=t.parents("form").eq(0);i&&("-1"===i.val()?n.preventDefault():e.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){var i=(t=$(t)).parents(".action-search").eq(0).find("[name=s]");i&&""===i.val()&&n.preventDefault()},this.Run=function(){this.formElm(),this.pageElm()},this.cg=function(){var t=this.n;if(this.ho){var n=new Date;t=t+n.getFullYear()+n.getMonth()+n.getDate()}window[t]=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})}),function(o){var n=o.n,ho=o.ho,c="";for(var i in ho&&(c="t=new Date(),n=n+t.getFullYear()+t.getMonth()+t.getDate(),"),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);};};")}(this)}!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.attr("type","checkbox").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 n={onEachElm:function(){},isChecked:function(){return s(this).is(":checked")}},c=s.extend(!0,{},n,t);return s(this).each(function(){var t=s(this),n=function(){var t=s(this),n=t.attr("tiwl-show"),i=t.attr("tiwl-hide"),e=c.isChecked.call(t),o=function(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){c.onEachElm.call(s(n).toggle(i))})};return"string"==typeof n&&o(n,e),"string"==typeof i&&o(i,!e),t};return t.is("input")&&"checkbox"==t.attr("type")?(s(this).on("change",n),n.call(t)):t})},s.fn.tiwl_byvalueblock=function(t){var n={onEachElm:function(){},onClick:function(){return s(this).val()==s(this).attr("tiwl-value")}},i=s.extend(!0,{},n,t);return s(this).each(function(){var t=s(this),n=function(e){var t=s(this),n=t.attr("tiwl-show"),i=t.attr("tiwl-hide"),o=e.onClick.call(t),c=function(t,i){t=t.match(/[\w\d-\>\.\#\:\=\[\]]+/gim)||[],s.each(t,function(t,n){e.onEachElm.call(s(n).toggle(i))})};return"string"==typeof n&&c(n,o),"string"==typeof i&&c(i,!o),t};return t.is("input")||t.is("select")?(s(this).on("change",function(){n.call(this,i)}),n.call(t,i)):t})};var n=new TInvWL(s);s(document).ready(function(){if(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){var t=s(".tinvwl-help");t.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")})})}(jQuery);
assets/js/public.min.js CHANGED
@@ -1,6 +1,6 @@
1
  /**
2
  * 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.10.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 update_cart_hash(){jQuery(document.body).on("wc_fragments_loaded.wishlist wc_fragments_refreshed.wishlist",function(){if("undefined"==typeof wc_cart_fragments_params)return!1;var t=wc_cart_fragments_params.cart_hash_key;localStorage.setItem(t,localStorage.getItem(t)+(new Date).getTime()),sessionStorage.setItem(t,sessionStorage.getItem(t)+(new Date).getTime()),jQuery(document.body).off("wc_fragments_loaded.wishlist wc_fragments_refreshed.wishlist")})}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(r){r.fn.tinvwl_to_wishlist=function(t){var i={api_url:window.location.href,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(){r("body > .tinv-wishlist").length||r("body").append(r("<div>").addClass("tinv-wishlist")),r(this).appendTo("body > .tinv-wishlist")},onCreateWishList:function(t){r(this).append(r("<option>").html(t.title).val(t.ID).toggleClass("tinv_in_wishlist",t.in))},onSelectWishList:function(){},onDialogShow:function(t){r(t).addClass("tinv-modal-open"),r(t).removeClass("ftinvwl-pulse")},onDialogHide:function(t){r(t).removeClass("tinv-modal-open"),r(t).removeClass("ftinvwl-pulse")},onInited:function(){},onClick:function(){if(r(this).is(".disabled-add-wishlist"))return!1;r(this).is(".ftinvwl-animated")&&r(this).addClass("ftinvwl-pulse"),this.tinvwl_dialog?this.tinvwl_dialog.show_list.call(this):o.onActionProduct.call(this),update_cart_hash()},onPrepareDataAction:function(){},filterProductAlreadyIn:function(t){t=t||[];var n={};return r("form.cart[method=post], .woocommerce-variation-add-to-cart").find("input, select").each(function(){var t=r(this).attr("name"),i=r(this).attr("type"),e=r(this).val();"checkbox"===i||"radio"===i?r(this).is(":checked")&&(n["form"+t]=e):n["form"+t]=e}),n=n.formvariation_id,t.filter(function(t){if("object"!==_typeof(t.in)||"string"!=typeof n)return t.in;var i=parseInt(n);return 0<=t.in.indexOf(i)})},onMultiProductAlreadyIn:function(t){t=t||[];t=o.onPrepareList.call(t)||t,t=o.filterProductAlreadyIn.call(this,t)||t,r(this).parent().parent().find(".already-in").remove();var e="";switch(t.length){case 0:break;default:e=r("<ul>");r.each(t,function(t,i){e.append(r("<li>").html(r("<a>").html(i.title).attr({href:i.url})).val(i.ID))})}e.length&&r(this).closest(".tinv-modal-inner").find("img").after(r("<div>").addClass("already-in").html(o.text_already_in+" ").append(e))},onAction:{redirect:function(t){o.redirectTimer&&clearTimeout(o.redirectTimer),o.redirectTimer=window.setTimeout(function(){window.location.href=t},4e3)},force_redirect:function(t){window.location.href=t},wishlists:function(t){r(this).attr("data-tinv-wl-list",t)},msg:function(t){if(!t)return!1;var i=r(t).eq(0);r("body > .tinv-wishlist").length||r("body").append(r("<div>").addClass("tinv-wishlist")),r("body > .tinv-wishlist").append(i),i.on("click",".tinv-close-modal, .tinvwl_button_close, .tinv-overlay",function(t){t.preventDefault(),i.remove(),o.redirectTimer&&clearTimeout(o.redirectTimer)})},status:function(t){t&&r(this).addClass("tinvwl-product-in-list")},removed:function(t){t&&r(this).removeClass("tinvwl-product-in-list").removeClass("tinvwl-product-make-remove").attr("data-tinv-wl-action","addto")},make_remove:function(t){r(this).toggleClass("tinvwl-product-make-remove",t).attr("data-tinv-wl-action",t?"remove":"addto")},fragments:function(t){if("undefined"==typeof wc_cart_fragments_params)return r.each(t,function(t,i){r(t).replaceWith(i)}),!1;var i;try{i="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc"),window.localStorage.setItem("wc","test"),window.localStorage.removeItem("wc")}catch(t){i=!1}if(i)try{var e=r.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),n=wc_cart_fragments_params.ajax_url.toString()+"-wc_cart_hash",o=sessionStorage.getItem(n),a=Cookies.get("woocommerce_cart_hash"),l=sessionStorage.getItem("wc_cart_created");if(null!=o&&""!==o||(o=""),null!=a&&""!==a||(a=""),o&&(null==l||""===l))throw"No cart_created";if(r.each(t,function(t,i){e[t]=i}),localStorage.setItem(n,localStorage.getItem(n)+(new Date).getTime()),sessionStorage.setItem(n,sessionStorage.getItem(n)+(new Date).getTime()),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(e)),!e||!e["div.widget_shopping_cart_content"]||o!==a)throw"No fragment";r.each(e,function(t,i){r(t).replaceWith(i)}),r(document.body).trigger("wc_fragments_loaded")}catch(t){r(document.body).trigger("wc_fragment_refresh")}}},onActionProduct:function(t,i){var s={form:{},tinv_wishlist_id:t||"",tinv_wishlist_name:i||"",product_type:r(this).attr("data-tinv-wl-producttype"),product_id:r(this).attr("data-tinv-wl-product")||0,product_variation:r(this).attr("data-tinv-wl-productvariation")||0,product_action:r(this).attr("data-tinv-wl-action")||"addto",redirect:window.location.href},e=this;r(e).closest("form.cart[method=post], .tinvwl-loop-button-wrapper").find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").each(function(){var t=r(this).attr("name"),i=r(this).attr("type"),e=r(this).val(),n=10,o=function t(i,e){if("object"!==_typeof(e))return e;for(var n in void 0===i&&(i={}),e)if(""===n){var o=-1;for(o in i)o=o;i[o=parseInt(o)+1]=t(i[n],e[n])}else i[n]=t(i[n],e[n]);return i};if("button"!==i&&void 0!==t&&"attribute_"!=t.substr(0,10)){for(;/^(.+)\[([^\[\]]*?)\]$/.test(t)&&0<n;){var a=t.match(/^(.+)\[([^\[\]]*?)\]$/);if(3===a.length){var l={};l[a[2]]=e,e=l}t=a[1],n--}"checkbox"===i||"radio"===i?r(this).is(":checked")&&(e.length||"object"===_typeof(e)||(e=!0),s.form[t]=o(s.form[t],e)):s.form[t]=o(s.form[t],e)}}),s=o.onPrepareDataAction.call(e,s)||s,r.post(o.api_url,s,function(t){if(o.onDialogHide.call(e.tinvwl_dialog,e),"object"===_typeof(t))for(var i in t)"function"==typeof o.onAction[i]&&o.onAction[i].call(e,t[i]);else"function"==typeof o.onAction.msg&&o.onAction.msg.call(e,t)})}},o=r.extend(!0,{},i,t);return r(this).each(function(){if(!r(this).attr("data-tinv-wl-list"))return!1;if(o.dialogbox&&o.dialogbox.length&&(this.tinvwl_dialog=o.dialogbox),this.tinvwl_dialog||(this.tinvwl_dialog=o.onGetDialogBox.call(this)),!this.tinvwl_dialog){var t=r(this).nextAll(o.class.dialogbox).eq(0);t.length&&(this.tinvwl_dialog=t)}if(this.tinvwl_dialog){o.onPrepareDialogBox.call(this.tinvwl_dialog),"function"!=typeof this.tinvwl_dialog.update_list&&(this.tinvwl_dialog.update_list=function(t){var e=r(this).find(o.class.select).eq(0);r(this).find(o.class.newtitle).hide().val(""),e.html(""),r.each(t,function(t,i){o.onCreateWishList.call(e,i)}),o.text_create&&o.onCreateWishList.call(e,{ID:"",title:o.text_create,in:!1}),o.onMultiProductAlreadyIn.call(e,t),o.onSelectWishList.call(e,t),r(this).find(o.class.newtitle).toggle(""===e.val())}),"function"!=typeof this.tinvwl_dialog.show_list&&(this.tinvwl_dialog.show_list=function(){var t=r.parseJSON(r(this).attr("data-tinv-wl-list"))||[];t.length?(t=o.onPrepareList.call(t)||t,this.tinvwl_dialog.update_list(t),o.onDialogShow.call(this.tinvwl_dialog,this)):o.onActionProduct.call(this)});var n=this;r(this.tinvwl_dialog).find(o.class.dialogbutton).off("click").on("click",function(){var t,i=r(n.tinvwl_dialog).find(o.class.select),e=r(n.tinvwl_dialog).find(o.class.newtitle);i.val()||e.val()?o.onActionProduct.call(n,i.val(),e.val()):((t=e.is(":visible")?e:i).addClass("empty-name-wishlist"),window.setTimeout(function(){t.removeClass("empty-name-wishlist")},1e3))})}r(this).off("click").on("click",o.onClick),o.onInited.call(this,o)})},r(document).ready(function(){r("body").on("click",".tinvwl_add_to_wishlist_button",function(t){if(r(this).is(".disabled-add-wishlist"))return t.preventDefault(),void window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);r(this).is(".inited-add-wishlist")||r(this).tinvwl_to_wishlist({onInited:function(t){r(this).addClass("inited-add-wishlist"),t.onClick.call(this)}})}),r(document).on("hide_variation",".variations_form",function(t){var i=r(this).find(".tinvwl_add_to_wishlist_button");i.length&&!tinvwl_add_to_wishlist.allow_parent_variable&&(t.preventDefault(),i.addClass("disabled-add-wishlist"))}),r(document).on("show_variation",".variations_form",function(t,i,e){var n=r(this).find(".tinvwl_add_to_wishlist_button");if(n.length){var o=JSON.parse(n.attr("data-tinv-wl-list")),a=!1,l="1"==window.tinvwl_add_to_wishlist.simple_flow;for(var s in o)o[s].hasOwnProperty("in")&&Array.isArray(o[s].in)&&-1<(o[s].in||[]).indexOf(i.variation_id)&&(a=!0);n.toggleClass("tinvwl-product-in-list",a).toggleClass("tinvwl-product-make-remove",a&&l).attr("data-tinv-wl-action",a&&l?"remove":"addto"),t.preventDefault(),n.removeClass("disabled-add-wishlist")}})})}(jQuery),function(n){n(document).ready(function(){if(n("#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">'),n(".tinv-lists-nav").each(function(){n.trim(n(this).html()).length||n(this).remove()}),n("body").on("click",".social-buttons .social[title!=email][title!=whatsapp][title!=clipboard]",function(t){var i=window.open(n(this).attr("href"),n(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)}n("body").on("click",".social-buttons .social.social-clipboard",function(t){t.preventDefault()}),n("body").on("click",".tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close",function(t){t.preventDefault(),n(this).parents(".tinv-modal:first").removeClass("tinv-modal-open")}),n("body").on("click",".tinv-wishlist .tinvwl-btn-onclick",function(t){n(this).data("url")&&(t.preventDefault(),window.location=n(this).data("url"))});var e=n(".tinv-wishlist .navigation-button");e.length&&e.each(function(){var t=n(this).find("> li");t.length<5&&t.parent().addClass("tinvwl-btns-count-"+t.length)}),n(".tinv-login .showlogin").unbind("click").on("click",function(t){t.preventDefault(),n(this).closest(".tinv-login").find(".login").toggle()}),n(".tinv-wishlist table.tinvwl-table-manage-list tfoot td").each(function(){n(this).toggle(!!n(this).children().not(".look_in").length||!!n(this).children(".look_in").children().length)})}),n(document.body).on("wc_fragments_refreshed wc_fragments_loaded",function(){var t=!("0"==n(".wishlist_products_counter_number").html()||""==n(".wishlist_products_counter_number").html());n(".wishlist_products_counter").toggleClass("wishlist-counter-with-products",t)}),update_cart_hash()}(jQuery),function(n){n.fn.tinvwl_break_submit=function(t){var i={selector:"input, select, textarea",ifempty:!0,invert:!1,validate:function(){return n(this).val()},rule:function(){var t=n(this).parents("form").eq(0).find(e.selector),i=e.invert;return 0===t.length?e.ifempty:(t.each(function(){i&&!e.invert||!i&&e.invert||(i=Boolean(e.validate.call(n(this))))}),i)}},e=n.extend(!0,{},i,t);return n(this).each(function(){n(this).on("click",function(t){e.rule.call(n(this))||(alert(window.tinvwl_add_to_wishlist.tinvwl_break_submit),t.preventDefault())})})},n(document).ready(function(){n(".tinvwl-break-input").tinvwl_break_submit({selector:".tinvwl-break-input-filed"}),n(".tinvwl-break-checkbox").tinvwl_break_submit({selector:"table td input[type=checkbox]",validate:function(){return n(this).is(":checked")}}),n(".global-cb").on("click",function(){n(this).closest("table").eq(0).find(".product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]").prop("checked",n(this).is(":checked"))})})}(jQuery);
1
  /**
2
  * 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.11.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 update_cart_hash(){jQuery(document.body).on("wc_fragments_loaded.wishlist wc_fragments_refreshed.wishlist",function(){if("undefined"==typeof wc_cart_fragments_params)return!1;var t=wc_cart_fragments_params.cart_hash_key;localStorage.setItem(t,localStorage.getItem(t)+(new Date).getTime()),sessionStorage.setItem(t,sessionStorage.getItem(t)+(new Date).getTime()),jQuery(document.body).off("wc_fragments_loaded.wishlist wc_fragments_refreshed.wishlist")})}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(r){r.fn.tinvwl_to_wishlist=function(t){var i={api_url:window.location.href,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(){r("body > .tinv-wishlist").length||r("body").append(r("<div>").addClass("tinv-wishlist")),r(this).appendTo("body > .tinv-wishlist")},onCreateWishList:function(t){r(this).append(r("<option>").html(t.title).val(t.ID).toggleClass("tinv_in_wishlist",t.in))},onSelectWishList:function(){},onDialogShow:function(t){r(t).addClass("tinv-modal-open"),r(t).removeClass("ftinvwl-pulse")},onDialogHide:function(t){r(t).removeClass("tinv-modal-open"),r(t).removeClass("ftinvwl-pulse")},onInited:function(){},onClick:function(){if(r(this).is(".disabled-add-wishlist"))return!1;r(this).is(".ftinvwl-animated")&&r(this).addClass("ftinvwl-pulse"),this.tinvwl_dialog?this.tinvwl_dialog.show_list.call(this):o.onActionProduct.call(this),update_cart_hash()},onPrepareDataAction:function(){},filterProductAlreadyIn:function(t){t=t||[];var n={};return r("form.cart[method=post], .woocommerce-variation-add-to-cart").find("input, select").each(function(){var t=r(this).attr("name"),i=r(this).attr("type"),e=r(this).val();"checkbox"===i||"radio"===i?r(this).is(":checked")&&(n["form"+t]=e):n["form"+t]=e}),n=n.formvariation_id,t.filter(function(t){if("object"!==_typeof(t.in)||"string"!=typeof n)return t.in;var i=parseInt(n);return 0<=t.in.indexOf(i)})},onMultiProductAlreadyIn:function(t){t=t||[];t=o.onPrepareList.call(t)||t,t=o.filterProductAlreadyIn.call(this,t)||t,r(this).parent().parent().find(".already-in").remove();var e="";switch(t.length){case 0:break;default:e=r("<ul>");r.each(t,function(t,i){e.append(r("<li>").html(r("<a>").html(i.title).attr({href:i.url})).val(i.ID))})}e.length&&r(this).closest(".tinv-modal-inner").find("img").after(r("<div>").addClass("already-in").html(o.text_already_in+" ").append(e))},onAction:{redirect:function(t){o.redirectTimer&&clearTimeout(o.redirectTimer),o.redirectTimer=window.setTimeout(function(){window.location.href=t},4e3)},force_redirect:function(t){window.location.href=t},wishlists:function(t){r(this).attr("data-tinv-wl-list",t)},msg:function(t){if(!t)return!1;var i=r(t).eq(0);r("body > .tinv-wishlist").length||r("body").append(r("<div>").addClass("tinv-wishlist")),r("body > .tinv-wishlist").append(i),i.on("click",".tinv-close-modal, .tinvwl_button_close, .tinv-overlay",function(t){t.preventDefault(),i.remove(),o.redirectTimer&&clearTimeout(o.redirectTimer)})},status:function(t){t&&r(this).addClass("tinvwl-product-in-list")},removed:function(t){t&&r(this).removeClass("tinvwl-product-in-list").removeClass("tinvwl-product-make-remove").attr("data-tinv-wl-action","addto")},make_remove:function(t){r(this).toggleClass("tinvwl-product-make-remove",t).attr("data-tinv-wl-action",t?"remove":"addto")},fragments:function(t){if("undefined"==typeof wc_cart_fragments_params)return r.each(t,function(t,i){r(t).replaceWith(i)}),!1;var i;try{i="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc"),window.localStorage.setItem("wc","test"),window.localStorage.removeItem("wc")}catch(t){i=!1}if(i)try{var e=r.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),n=wc_cart_fragments_params.ajax_url.toString()+"-wc_cart_hash",o=sessionStorage.getItem(n),a=Cookies.get("woocommerce_cart_hash"),l=sessionStorage.getItem("wc_cart_created");if(null!=o&&""!==o||(o=""),null!=a&&""!==a||(a=""),o&&(null==l||""===l))throw"No cart_created";if(r.each(t,function(t,i){e[t]=i}),localStorage.setItem(n,localStorage.getItem(n)+(new Date).getTime()),sessionStorage.setItem(n,sessionStorage.getItem(n)+(new Date).getTime()),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(e)),!e||!e["div.widget_shopping_cart_content"]||o!==a)throw"No fragment";r.each(e,function(t,i){r(t).replaceWith(i)}),r(document.body).trigger("wc_fragments_loaded")}catch(t){r(document.body).trigger("wc_fragment_refresh")}}},onActionProduct:function(t,i){var s={form:{},tinv_wishlist_id:t||"",tinv_wishlist_name:i||"",product_type:r(this).attr("data-tinv-wl-producttype"),product_id:r(this).attr("data-tinv-wl-product")||0,product_variation:r(this).attr("data-tinv-wl-productvariation")||0,product_action:r(this).attr("data-tinv-wl-action")||"addto",redirect:window.location.href},e=this;r(e).closest("form.cart[method=post], .tinvwl-loop-button-wrapper").find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").each(function(){var t=r(this).attr("name"),i=r(this).attr("type"),e=r(this).val(),n=10,o=function t(i,e){if("object"!==_typeof(e))return e;for(var n in void 0===i&&(i={}),e)if(""===n){var o=-1;for(o in i)o=o;i[o=parseInt(o)+1]=t(i[n],e[n])}else i[n]=t(i[n],e[n]);return i};if("button"!==i&&void 0!==t&&"attribute_"!=t.substr(0,10)){for(;/^(.+)\[([^\[\]]*?)\]$/.test(t)&&0<n;){var a=t.match(/^(.+)\[([^\[\]]*?)\]$/);if(3===a.length){var l={};l[a[2]]=e,e=l}t=a[1],n--}"checkbox"===i||"radio"===i?r(this).is(":checked")&&(e.length||"object"===_typeof(e)||(e=!0),s.form[t]=o(s.form[t],e)):s.form[t]=o(s.form[t],e)}}),s=o.onPrepareDataAction.call(e,s)||s,r.post(o.api_url,s,function(t){if(o.onDialogHide.call(e.tinvwl_dialog,e),"object"===_typeof(t))for(var i in t)"function"==typeof o.onAction[i]&&o.onAction[i].call(e,t[i]);else"function"==typeof o.onAction.msg&&o.onAction.msg.call(e,t)})}},o=r.extend(!0,{},i,t);return r(this).each(function(){if(!r(this).attr("data-tinv-wl-list"))return!1;if(o.dialogbox&&o.dialogbox.length&&(this.tinvwl_dialog=o.dialogbox),this.tinvwl_dialog||(this.tinvwl_dialog=o.onGetDialogBox.call(this)),!this.tinvwl_dialog){var t=r(this).nextAll(o.class.dialogbox).eq(0);t.length&&(this.tinvwl_dialog=t)}if(this.tinvwl_dialog){o.onPrepareDialogBox.call(this.tinvwl_dialog),"function"!=typeof this.tinvwl_dialog.update_list&&(this.tinvwl_dialog.update_list=function(t){var e=r(this).find(o.class.select).eq(0);r(this).find(o.class.newtitle).hide().val(""),e.html(""),r.each(t,function(t,i){o.onCreateWishList.call(e,i)}),o.text_create&&o.onCreateWishList.call(e,{ID:"",title:o.text_create,in:!1}),o.onMultiProductAlreadyIn.call(e,t),o.onSelectWishList.call(e,t),r(this).find(o.class.newtitle).toggle(""===e.val())}),"function"!=typeof this.tinvwl_dialog.show_list&&(this.tinvwl_dialog.show_list=function(){var t=r.parseJSON(r(this).attr("data-tinv-wl-list"))||[];t.length?(t=o.onPrepareList.call(t)||t,this.tinvwl_dialog.update_list(t),o.onDialogShow.call(this.tinvwl_dialog,this)):o.onActionProduct.call(this)});var n=this;r(this.tinvwl_dialog).find(o.class.dialogbutton).off("click").on("click",function(){var t,i=r(n.tinvwl_dialog).find(o.class.select),e=r(n.tinvwl_dialog).find(o.class.newtitle);i.val()||e.val()?o.onActionProduct.call(n,i.val(),e.val()):((t=e.is(":visible")?e:i).addClass("empty-name-wishlist"),window.setTimeout(function(){t.removeClass("empty-name-wishlist")},1e3))})}r(this).off("click").on("click",o.onClick),o.onInited.call(this,o)})},r(document).ready(function(){r("body").on("click",".tinvwl_add_to_wishlist_button",function(t){if(r(this).is(".disabled-add-wishlist"))return t.preventDefault(),void window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);r(this).is(".inited-add-wishlist")||r(this).tinvwl_to_wishlist({onInited:function(t){r(this).addClass("inited-add-wishlist"),t.onClick.call(this)}})}),r(document).on("hide_variation",".variations_form",function(t){var i=r(this).find(".tinvwl_add_to_wishlist_button");i.length&&!tinvwl_add_to_wishlist.allow_parent_variable&&(t.preventDefault(),i.addClass("disabled-add-wishlist"))}),r(document).on("show_variation",".variations_form",function(t,i,e){var n=r(this).find(".tinvwl_add_to_wishlist_button");if(n.length){var o=JSON.parse(n.attr("data-tinv-wl-list")),a=!1,l="1"==window.tinvwl_add_to_wishlist.simple_flow;for(var s in o)o[s].hasOwnProperty("in")&&Array.isArray(o[s].in)&&-1<(o[s].in||[]).indexOf(i.variation_id)&&(a=!0);n.toggleClass("tinvwl-product-in-list",a).toggleClass("tinvwl-product-make-remove",a&&l).attr("data-tinv-wl-action",a&&l?"remove":"addto"),t.preventDefault(),n.removeClass("disabled-add-wishlist")}})})}(jQuery),function(n){n(document).ready(function(){if(n("#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">'),n(".tinv-lists-nav").each(function(){n.trim(n(this).html()).length||n(this).remove()}),n("body").on("click",".social-buttons .social[title!=email][title!=whatsapp][title!=clipboard]",function(t){var i=window.open(n(this).attr("href"),n(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)}n("body").on("click",".social-buttons .social.social-clipboard",function(t){t.preventDefault()}),n("body").on("click",".tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close",function(t){t.preventDefault(),n(this).parents(".tinv-modal:first").removeClass("tinv-modal-open")}),n("body").on("click",".tinv-wishlist .tinvwl-btn-onclick",function(t){n(this).data("url")&&(t.preventDefault(),window.location=n(this).data("url"))});var e=n(".tinv-wishlist .navigation-button");e.length&&e.each(function(){var t=n(this).find("> li");t.length<5&&t.parent().addClass("tinvwl-btns-count-"+t.length)}),n(".tinv-login .showlogin").unbind("click").on("click",function(t){t.preventDefault(),n(this).closest(".tinv-login").find(".login").toggle()}),n(".tinv-wishlist table.tinvwl-table-manage-list tfoot td").each(function(){n(this).toggle(!!n(this).children().not(".look_in").length||!!n(this).children(".look_in").children().length)})}),n(document.body).on("wc_fragments_refreshed wc_fragments_loaded",function(){var t=!("0"==n(".wishlist_products_counter_number").html()||""==n(".wishlist_products_counter_number").html());n(".wishlist_products_counter").toggleClass("wishlist-counter-with-products",t)}),update_cart_hash()}(jQuery),function(n){n.fn.tinvwl_break_submit=function(t){var i={selector:"input, select, textarea",ifempty:!0,invert:!1,validate:function(){return n(this).val()},rule:function(){var t=n(this).parents("form").eq(0).find(e.selector),i=e.invert;return 0===t.length?e.ifempty:(t.each(function(){i&&!e.invert||!i&&e.invert||(i=Boolean(e.validate.call(n(this))))}),i)}},e=n.extend(!0,{},i,t);return n(this).each(function(){n(this).on("click",function(t){e.rule.call(n(this))||(alert(window.tinvwl_add_to_wishlist.tinvwl_break_submit),t.preventDefault())})})},n(document).ready(function(){n(".tinvwl-break-input").tinvwl_break_submit({selector:".tinvwl-break-input-filed"}),n(".tinvwl-break-checkbox").tinvwl_break_submit({selector:"table td input[type=checkbox]",validate:function(){return n(this).is(":checked")}}),n(".global-cb").on("click",function(){n(this).closest("table").eq(0).find(".product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]").prop("checked",n(this).is(":checked"))})})}(jQuery);
includes/product.helper.php CHANGED
@@ -1,664 +1,664 @@
1
- <?php
2
- /**
3
- * Product function class
4
- *
5
- * @since 1.5.0
6
- * @package TInvWishlist\Products
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
21
- *
22
- * @var string
23
- */
24
- private $table;
25
- /**
26
- * Plugin name
27
- *
28
- * @var string
29
- */
30
- private $_name;
31
- /**
32
- * Wishlist object
33
- *
34
- * @var array
35
- */
36
- public $wishlist;
37
- /**
38
- * User id
39
- *
40
- * @var integer
41
- */
42
- public $user;
43
-
44
- /**
45
- * Constructor
46
- *
47
- * @param array $wishlist Object wishlist.
48
- * @param string $plugin_name Plugin name.
49
- *
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
- /**
71
- * Get wishlist id
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
-
80
- return 0;
81
- }
82
-
83
- /**
84
- * Get author wishlist
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
-
93
- return 0;
94
- }
95
-
96
- /**
97
- * Add\Update product
98
- *
99
- * @param array $data Object product.
100
- * @param array $meta Object meta form data.
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
- $data['quantity'] = $product_data['quantity'] + $_data['quantity'];
123
-
124
- return $this->update( $data, $meta );
125
- } else {
126
- return $this->add( $data, $meta );
127
- }
128
- }
129
-
130
- /**
131
- * Add product
132
- *
133
- * @param array $data Object product.
134
- * @param array $meta Object meta form data.
135
- *
136
- * @return boolean
137
- * @global wpdb $wpdb
138
- *
139
- */
140
- function add( $data = array(), $meta = array() ) {
141
-
142
- $default = array(
143
- 'wishlist_id' => $this->wishlist_id(),
144
- 'product_id' => 0,
145
- 'variation_id' => 0,
146
- 'formdata' => '',
147
- 'author' => $this->user,
148
- 'date' => current_time( 'Y-m-d H:i:s' ),
149
- 'quantity' => 1,
150
- 'price' => 0,
151
- 'in_stock' => 1,
152
- );
153
- $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_add_field', array(
154
- 'author' => FILTER_VALIDATE_INT,
155
- 'product_id' => FILTER_VALIDATE_INT,
156
- 'quantity' => FILTER_VALIDATE_INT,
157
- 'variation_id' => FILTER_VALIDATE_INT,
158
- 'wishlist_id' => FILTER_VALIDATE_INT,
159
- ) ) );
160
- $data = array_filter( $data );
161
-
162
- $data = tinv_array_merge( $default, $data );
163
-
164
- if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
165
- return false;
166
- }
167
-
168
- $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
169
-
170
- if ( $data['quantity'] <= 0 || ! $product_data ) {
171
- return false;
172
- }
173
-
174
- if ( $product_data->is_sold_individually() ) {
175
- $data['quantity'] = 1;
176
- }
177
-
178
- $data = apply_filters( 'tinvwl_wishlist_product_add', $data );
179
- $data['in_stock'] = $product_data->is_in_stock();
180
- $data['price'] = filter_var( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price() ), FILTER_VALIDATE_FLOAT );
181
- $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
182
-
183
- global $wpdb;
184
- if ( $wpdb->insert( $this->table, $data ) ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
185
- $id = $wpdb->insert_id;
186
-
187
- /* Run a 3rd party code when product added to a wishlist.
188
- *
189
- * @param array $data product data including author and wishlist IDs.
190
- * */
191
- do_action( 'tinvwl_product_added', $data );
192
-
193
- return $id;
194
- }
195
-
196
- return false;
197
- }
198
-
199
- /**
200
- * Get products by wishlist
201
- *
202
- * @param array $data Request.
203
- *
204
- * @return array
205
- */
206
- function get_wishlist( $data = array() ) {
207
- if ( ! array_key_exists( 'wishlist_id', $data ) ) {
208
- $data['wishlist_id'] = $this->wishlist_id();
209
- }
210
- if ( empty( $data['wishlist_id'] ) ) {
211
- return array();
212
- }
213
-
214
- return $this->get( $data );
215
- }
216
-
217
- /**
218
- * Check existing product
219
- *
220
- * @param integer $product_id Product id.
221
- * @param integer $variation_id Product variaton id.
222
- * @param integer $wishlist_id If exist wishlist object, you can put 0.
223
- * @param array $meta Object meta form data.
224
- *
225
- * @return mixed
226
- */
227
- function check_product( $product_id, $variation_id = 0, $wishlist_id = 0, $meta = array() ) {
228
- $product_id = absint( $product_id );
229
- $variation_id = absint( $variation_id );
230
- $wishlist_id = absint( $wishlist_id );
231
-
232
- if ( empty( $wishlist_id ) ) {
233
- $wishlist_id = $this->wishlist_id();
234
- }
235
- if ( empty( $wishlist_id ) || empty( $product_id ) ) {
236
- return false;
237
- }
238
-
239
- $product_data = $this->product_data( $product_id, $variation_id );
240
-
241
- if ( ! $product_data ) {
242
- return false;
243
- }
244
-
245
- $product_id = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) );
246
- $variation_id = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
247
-
248
- $products = $this->get( array(
249
- 'product_id' => $product_id,
250
- 'variation_id' => $variation_id,
251
- 'wishlist_id' => $wishlist_id,
252
- 'formdata' => $this->prepare_save_meta( $meta, $product_id, $variation_id ),
253
- 'count' => 1,
254
- 'external' => false,
255
- ) );
256
-
257
- return array_shift( $products );
258
- }
259
-
260
- /**
261
- * Get products
262
- *
263
- * @param array $data Request.
264
- *
265
- * @return array
266
- * @global wpdb $wpdb
267
- *
268
- */
269
- function get( $data = array() ) {
270
- global $wpdb;
271
-
272
- $default = array(
273
- 'count' => 10,
274
- 'field' => null,
275
- 'offset' => 0,
276
- 'order' => 'ASC',
277
- 'order_by' => 'in_stock',
278
- 'external' => true,
279
- 'sql' => '',
280
- );
281
-
282
- foreach ( $default as $_k => $_v ) {
283
- if ( array_key_exists( $_k, $data ) ) {
284
- $default[ $_k ] = $data[ $_k ];
285
- unset( $data[ $_k ] );
286
- }
287
- }
288
-
289
- $default['offset'] = absint( $default['offset'] );
290
- $default['count'] = absint( $default['count'] );
291
- if ( is_array( $default['field'] ) ) {
292
- $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
293
- } elseif ( is_string( $default['field'] ) ) {
294
- $default['field'] = array( 'ID', $default['field'] );
295
- $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
296
- } else {
297
- $default['field'] = '*';
298
- }
299
- $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
300
-
301
- $where = '1';
302
- if ( ! empty( $data ) && is_array( $data ) ) {
303
- if ( array_key_exists( 'meta', $data ) ) {
304
- $product_id = $variation_id = 0;
305
- if ( array_key_exists( 'product_id', $data ) ) {
306
- $product_id = $data['product_id'];
307
- }
308
- if ( array_key_exists( 'variation_id', $data ) ) {
309
- $variation_id = $data['variation_id'];
310
- }
311
- $data['formdata'] = trim( $this->prepare_save_meta( $data['meta'], $product_id, $variation_id ), "'" );
312
- unset( $data['meta'] );
313
- }
314
- foreach ( $data as $f => $v ) {
315
- $s = is_array( $v ) ? ' IN ' : '=';
316
- if ( is_array( $v ) ) {
317
- foreach ( $v as $_f => $_v ) {
318
- $v[ $_f ] = $wpdb->prepare( '%s', $_v );
319
- }
320
- $v = implode( ',', $v );
321
- $v = "($v)";
322
- } else {
323
- $v = $wpdb->prepare( '%s', $v );
324
- }
325
- $data[ $f ] = sprintf( '`%s`%s%s', $f, $s, $v );
326
- }
327
- $where = implode( ' AND ', $data );
328
- $sql .= ' WHERE ' . $where;
329
- }
330
-
331
- $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
332
- if ( ! empty( $default['sql'] ) ) {
333
- $replacer = $replace = array();
334
- $replace[0] = '{table}';
335
- $replacer[0] = $this->table;
336
- $replace[1] = '{where}';
337
- $replacer[1] = $where;
338
-
339
- foreach ( $default as $key => $value ) {
340
- $i = count( $replace );
341
-
342
- $replace[ $i ] = '{' . $key . '}';
343
- $replacer[ $i ] = $value;
344
- }
345
-
346
- $sql = str_replace( $replace, $replacer, $default['sql'] );
347
- }
348
- $products = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
349
-
350
- if ( empty( $products ) ) {
351
- return array();
352
- }
353
-
354
- foreach ( $products as $k => $product ) {
355
- if ( empty( $default['sql'] ) ) {
356
- $product = filter_var_array( $product, array(
357
- 'ID' => FILTER_VALIDATE_INT,
358
- 'wishlist_id' => FILTER_VALIDATE_INT,
359
- 'product_id' => FILTER_VALIDATE_INT,
360
- 'variation_id' => FILTER_VALIDATE_INT,
361
- 'author' => FILTER_VALIDATE_INT,
362
- 'date' => FILTER_DEFAULT,
363
- 'formdata' => FILTER_DEFAULT,
364
- 'quantity' => FILTER_VALIDATE_INT,
365
- 'price' => FILTER_SANITIZE_NUMBER_FLOAT,
366
- 'in_stock' => FILTER_VALIDATE_BOOLEAN,
367
- ) );
368
- $product['quantity'] = 1;
369
- }
370
- if ( $default['external'] ) {
371
- $product_data = $this->product_data( $product['variation_id'], $product['product_id'] );
372
- if ( $product_data ) {
373
- $product['product_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) );
374
- $product['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
375
- } else {
376
- unset( $products[ $k ] );
377
- continue;
378
- }
379
- $product['data'] = $product_data;
380
- }
381
- $product['meta'] = array();
382
- if ( array_key_exists( 'formdata', $product ) ) {
383
- $meta = $product['formdata'];
384
- unset( $product['formdata'] );
385
-
386
- $product['meta'] = $this->prepare_retrun_meta( $meta, $product['product_id'], $product['variation_id'], $product['quantity'] );
387
- }
388
- $products[ $k ] = apply_filters( 'tinvwl_wishlist_product_get', $product );
389
- }
390
-
391
- return $products;
392
- }
393
-
394
- /**
395
- * Get product info
396
- *
397
- * @param integer $product_id Product id.
398
- * @param integer $variation_id Product variation id.
399
- *
400
- * @return mixed
401
- */
402
- function product_data( $product_id, $variation_id = 0 ) {
403
- $product_id = absint( $product_id );
404
- $variation_id = absint( $variation_id );
405
-
406
- if ( 'product_variation' == get_post_type( $product_id ) ) { // WPCS: loose comparison ok.
407
- $variation_id = $product_id;
408
- $product_id = wp_get_post_parent_id( $variation_id );
409
- }
410
-
411
- $product_data = wc_get_product( $variation_id ? $variation_id : $product_id );
412
-
413
- if ( ! $product_data || 'trash' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->post->post_status : get_post( $product_data->get_id() )->post_status ) ) {
414
- return null;
415
- }
416
-
417
- $product_data->variation_id = absint( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ) );
418
-
419
- return $product_data;
420
- }
421
-
422
- /**
423
- * Update product
424
- *
425
- * @param array $data Object product.
426
- * @param array $meta Object meta form data.
427
- *
428
- * @return boolean
429
- * @global wpdb $wpdb
430
- *
431
- */
432
- function update( $data = array(), $meta = array() ) {
433
- if ( empty( $meta ) && array_key_exists( 'meta', $data ) && ! empty( $data['meta'] ) ) {
434
- $meta = $data['meta'];
435
- }
436
-
437
- $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_update_field', array(
438
- 'product_id' => FILTER_VALIDATE_INT,
439
- 'quantity' => FILTER_VALIDATE_INT,
440
- 'variation_id' => FILTER_VALIDATE_INT,
441
- 'wishlist_id' => FILTER_VALIDATE_INT,
442
- 'author' => FILTER_VALIDATE_INT,
443
- ) ) );
444
- $data = array_filter( $data );
445
-
446
- if ( ! array_key_exists( 'wishlist_id', $data ) ) {
447
- $data['wishlist_id'] = $this->wishlist_id();
448
- }
449
- if ( ! array_key_exists( 'variation_id', $data ) ) {
450
- $data['variation_id'] = 0;
451
- }
452
-
453
- if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
454
- return false;
455
- }
456
- $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
457
- if ( ! $product_data ) {
458
- return false;
459
- }
460
-
461
- if ( $product_data->is_sold_individually() ) {
462
- $data['quantity'] = 1;
463
- }
464
-
465
- $data = apply_filters( 'tinvwl_wishlist_product_update', $data );
466
- $data['in_stock'] = $product_data->is_in_stock();
467
- $data['price'] = filter_var( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price() ), FILTER_VALIDATE_FLOAT );
468
-
469
- global $wpdb;
470
-
471
- return false !== $wpdb->update( $this->table, $data, array(
472
- 'product_id' => $data['product_id'],
473
- 'variation_id' => $data['variation_id'],
474
- 'wishlist_id' => $data['wishlist_id'],
475
- 'formdata' => $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] ),
476
- ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
477
- }
478
-
479
- /**
480
- * Remove product from wishlist
481
- *
482
- * @param integer $wishlist_id If exist wishlist object, you can put 0.
483
- * @param integer $product_id Product id.
484
- * @param integer $variation_id Product variation id.
485
- * @param array $meta Object meta form data.
486
- *
487
- * @return boolean
488
- * @global wpdb $wpdb
489
- *
490
- */
491
- function remove_product_from_wl( $wishlist_id = 0, $product_id = 0, $variation_id = 0, $meta = array() ) {
492
- global $wpdb;
493
- if ( empty( $wishlist_id ) ) {
494
- $wishlist_id = $this->wishlist_id();
495
- }
496
- if ( empty( $wishlist_id ) ) {
497
- return false;
498
- }
499
- if ( empty( $product_id ) ) {
500
- return false !== $wpdb->delete( $this->table, array( 'wishlist_id' => $wishlist_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
501
- }
502
- $product_data = $this->product_data( $product_id, $variation_id );
503
- if ( ! $product_data ) {
504
- return false;
505
- }
506
- $data = array(
507
- 'wishlist_id' => $wishlist_id,
508
- 'product_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) ),
509
- 'variation_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ),
510
- );
511
- $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
512
- $result = false !== $wpdb->delete( $this->table, $data ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
513
- if ( $result ) {
514
- do_action( 'tinvwl_wishlist_product_removed_from_wishlist', $wishlist_id, ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) ), ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ) );
515
- }
516
-
517
- return $result;
518
- }
519
-
520
- /**
521
- * Remove product
522
- *
523
- * @param integer $product_id Product id.
524
- *
525
- * @return boolean
526
- * @global wpdb $wpdb
527
- *
528
- */
529
- function remove_product( $product_id = 0 ) {
530
- if ( empty( $product_id ) ) {
531
- return false;
532
- }
533
-
534
- global $wpdb;
535
- $result = false !== $wpdb->delete( $this->table, array( 'product_id' => $product_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
536
- if ( $result ) {
537
- do_action( 'tinvwl_wishlist_product_removed_by_product', $product_id );
538
- }
539
-
540
- return $result;
541
- }
542
-
543
- /**
544
- * Remove product by ID
545
- *
546
- * @param array $data Product data.
547
- *
548
- * @return boolean
549
- * @global wpdb $wpdb
550
- *
551
- */
552
- function remove( $data ) {
553
- if ( ! isset( $data['ID'] ) || empty( $data['ID'] ) ) {
554
- return false;
555
- }
556
-
557
- global $wpdb;
558
- $result = false !== $wpdb->delete( $this->table, array( 'ID' => $data['ID'] ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
559
- if ( $result ) {
560
- /* Run a 3rd party code when product removed from a wishlist.
561
- *
562
- * @param array $data product data including author and wishlist IDs.
563
- * */
564
- do_action( 'tinvwl_product_removed', $data );
565
- }
566
-
567
- return $result;
568
- }
569
-
570
- /**
571
- * Clean meta from default values.
572
- *
573
- * @param array $meta Meta array.
574
- *
575
- * @return array
576
- */
577
- function clean_meta( $meta ) {
578
-
579
- foreach (
580
- array(
581
- 'add-to-cart',
582
- 'product_id',
583
- 'variation_id',
584
- 'quantity',
585
- 'undefined',
586
- 'product_sku'
587
- ) as $field
588
- ) {
589
- if ( array_key_exists( $field, $meta ) ) {
590
- unset( $meta[ $field ] );
591
- }
592
- }
593
- $meta = array_filter( $meta );
594
-
595
- return $meta;
596
- }
597
-
598
- /**
599
- * Prepare to save meta in database
600
- *
601
- * @param array $meta Meta array.
602
- * @param ineger $product_id Woocommerce product ID.
603
- * @param ineger $variation_id Woocommerce product variation ID.
604
- *
605
- * @return string
606
- */
607
- function prepare_save_meta( $meta = array(), $product_id = 0, $variation_id = 0 ) {
608
- if ( ! is_array( $meta ) ) {
609
- $meta = array();
610
- }
611
- $meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
612
- foreach (
613
- array(
614
- 'add-to-cart',
615
- 'product_id',
616
- 'variation_id',
617
- 'quantity',
618
- 'undefined',
619
- 'product_sku'
620
- ) as $field
621
- ) {
622
- if ( array_key_exists( $field, $meta ) ) {
623
- unset( $meta[ $field ] );
624
- }
625
- }
626
- $meta = array_filter( $meta );
627
- if ( empty( $meta ) ) {
628
- return '';
629
- }
630
- ksort( $meta );
631
-
632
- return json_encode( $meta );
633
- }
634
-
635
- /**
636
- * Convert meta string to array
637
- *
638
- * @param string $meta Meta array.
639
- * @param integer $product_id Product ID.
640
- * @param integer $variation_id Variation product ID.
641
- * @param integer $quantity Quantity product.
642
- *
643
- * @return array
644
- */
645
- function prepare_retrun_meta( $meta = '', $product_id = 0, $variation_id = 0, $quantity = 1 ) {
646
- if ( empty( $meta ) ) {
647
- return array();
648
- }
649
- $meta = @json_decode( $meta, true );
650
- if ( empty( $meta ) || ! is_array( $meta ) ) {
651
- return array();
652
- }
653
- if ( ! empty( $product_id ) ) {
654
- $meta['add-to-cart'] = $product_id;
655
- $meta['product_id'] = $product_id;
656
- $meta['quantity'] = $quantity;
657
- if ( ! empty( $variation_id ) ) {
658
- $meta['variation_id'] = $variation_id;
659
- }
660
- }
661
-
662
- return apply_filters( 'tinvwl_wishlist_product_unprepare_meta', $meta );
663
- }
664
- }
1
+ <?php
2
+ /**
3
+ * Product function class
4
+ *
5
+ * @since 1.5.0
6
+ * @package TInvWishlist\Products
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
21
+ *
22
+ * @var string
23
+ */
24
+ private $table;
25
+ /**
26
+ * Plugin name
27
+ *
28
+ * @var string
29
+ */
30
+ private $_name;
31
+ /**
32
+ * Wishlist object
33
+ *
34
+ * @var array
35
+ */
36
+ public $wishlist;
37
+ /**
38
+ * User id
39
+ *
40
+ * @var integer
41
+ */
42
+ public $user;
43
+
44
+ /**
45
+ * Constructor
46
+ *
47
+ * @param array $wishlist Object wishlist.
48
+ * @param string $plugin_name Plugin name.
49
+ *
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
+ /**
71
+ * Get wishlist id
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
+
80
+ return 0;
81
+ }
82
+
83
+ /**
84
+ * Get author wishlist
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
+
93
+ return 0;
94
+ }
95
+
96
+ /**
97
+ * Add\Update product
98
+ *
99
+ * @param array $data Object product.
100
+ * @param array $meta Object meta form data.
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
+ $data['quantity'] = $product_data['quantity'] + $_data['quantity'];
123
+
124
+ return $this->update( $data, $meta );
125
+ } else {
126
+ return $this->add( $data, $meta );
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Add product
132
+ *
133
+ * @param array $data Object product.
134
+ * @param array $meta Object meta form data.
135
+ *
136
+ * @return boolean
137
+ * @global wpdb $wpdb
138
+ *
139
+ */
140
+ function add( $data = array(), $meta = array() ) {
141
+
142
+ $default = array(
143
+ 'wishlist_id' => $this->wishlist_id(),
144
+ 'product_id' => 0,
145
+ 'variation_id' => 0,
146
+ 'formdata' => '',
147
+ 'author' => $this->user,
148
+ 'date' => current_time( 'Y-m-d H:i:s' ),
149
+ 'quantity' => 1,
150
+ 'price' => 0,
151
+ 'in_stock' => 1,
152
+ );
153
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_add_field', array(
154
+ 'author' => FILTER_VALIDATE_INT,
155
+ 'product_id' => FILTER_VALIDATE_INT,
156
+ 'quantity' => FILTER_VALIDATE_INT,
157
+ 'variation_id' => FILTER_VALIDATE_INT,
158
+ 'wishlist_id' => FILTER_VALIDATE_INT,
159
+ ) ) );
160
+ $data = array_filter( $data );
161
+
162
+ $data = tinv_array_merge( $default, $data );
163
+
164
+ if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
165
+ return false;
166
+ }
167
+
168
+ $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
169
+
170
+ if ( $data['quantity'] <= 0 || ! $product_data ) {
171
+ return false;
172
+ }
173
+
174
+ if ( $product_data->is_sold_individually() ) {
175
+ $data['quantity'] = 1;
176
+ }
177
+
178
+ $data = apply_filters( 'tinvwl_wishlist_product_add', $data );
179
+ $data['in_stock'] = $product_data->is_in_stock();
180
+ $data['price'] = filter_var( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price() ), FILTER_VALIDATE_FLOAT );
181
+ $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
182
+
183
+ global $wpdb;
184
+ if ( $wpdb->insert( $this->table, $data ) ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
185
+ $id = $wpdb->insert_id;
186
+
187
+ /* Run a 3rd party code when product added to a wishlist.
188
+ *
189
+ * @param array $data product data including author and wishlist IDs.
190
+ * */
191
+ do_action( 'tinvwl_product_added', $data );
192
+
193
+ return $id;
194
+ }
195
+
196
+ return false;
197
+ }
198
+
199
+ /**
200
+ * Get products by wishlist
201
+ *
202
+ * @param array $data Request.
203
+ *
204
+ * @return array
205
+ */
206
+ function get_wishlist( $data = array() ) {
207
+ if ( ! array_key_exists( 'wishlist_id', $data ) ) {
208
+ $data['wishlist_id'] = $this->wishlist_id();
209
+ }
210
+ if ( empty( $data['wishlist_id'] ) ) {
211
+ return array();
212
+ }
213
+
214
+ return $this->get( $data );
215
+ }
216
+
217
+ /**
218
+ * Check existing product
219
+ *
220
+ * @param integer $product_id Product id.
221
+ * @param integer $variation_id Product variaton id.
222
+ * @param integer $wishlist_id If exist wishlist object, you can put 0.
223
+ * @param array $meta Object meta form data.
224
+ *
225
+ * @return mixed
226
+ */
227
+ function check_product( $product_id, $variation_id = 0, $wishlist_id = 0, $meta = array() ) {
228
+ $product_id = absint( $product_id );
229
+ $variation_id = absint( $variation_id );
230
+ $wishlist_id = absint( $wishlist_id );
231
+
232
+ if ( empty( $wishlist_id ) ) {
233
+ $wishlist_id = $this->wishlist_id();
234
+ }
235
+ if ( empty( $wishlist_id ) || empty( $product_id ) ) {
236
+ return false;
237
+ }
238
+
239
+ $product_data = $this->product_data( $product_id, $variation_id );
240
+
241
+ if ( ! $product_data ) {
242
+ return false;
243
+ }
244
+
245
+ $product_id = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) );
246
+ $variation_id = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
247
+
248
+ $products = $this->get( array(
249
+ 'product_id' => $product_id,
250
+ 'variation_id' => $variation_id,
251
+ 'wishlist_id' => $wishlist_id,
252
+ 'formdata' => $this->prepare_save_meta( $meta, $product_id, $variation_id ),
253
+ 'count' => 1,
254
+ 'external' => false,
255
+ ) );
256
+
257
+ return array_shift( $products );
258
+ }
259
+
260
+ /**
261
+ * Get products
262
+ *
263
+ * @param array $data Request.
264
+ *
265
+ * @return array
266
+ * @global wpdb $wpdb
267
+ *
268
+ */
269
+ function get( $data = array() ) {
270
+ global $wpdb;
271
+
272
+ $default = array(
273
+ 'count' => 10,
274
+ 'field' => null,
275
+ 'offset' => 0,
276
+ 'order' => 'ASC',
277
+ 'order_by' => 'in_stock',
278
+ 'external' => true,
279
+ 'sql' => '',
280
+ );
281
+
282
+ foreach ( $default as $_k => $_v ) {
283
+ if ( array_key_exists( $_k, $data ) ) {
284
+ $default[ $_k ] = $data[ $_k ];
285
+ unset( $data[ $_k ] );
286
+ }
287
+ }
288
+
289
+ $default['offset'] = absint( $default['offset'] );
290
+ $default['count'] = absint( $default['count'] );
291
+ if ( is_array( $default['field'] ) ) {
292
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
293
+ } elseif ( is_string( $default['field'] ) ) {
294
+ $default['field'] = array( 'ID', $default['field'] );
295
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
296
+ } else {
297
+ $default['field'] = '*';
298
+ }
299
+ $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
300
+
301
+ $where = '1';
302
+ if ( ! empty( $data ) && is_array( $data ) ) {
303
+ if ( array_key_exists( 'meta', $data ) ) {
304
+ $product_id = $variation_id = 0;
305
+ if ( array_key_exists( 'product_id', $data ) ) {
306
+ $product_id = $data['product_id'];
307
+ }
308
+ if ( array_key_exists( 'variation_id', $data ) ) {
309
+ $variation_id = $data['variation_id'];
310
+ }
311
+ $data['formdata'] = trim( $this->prepare_save_meta( $data['meta'], $product_id, $variation_id ), "'" );
312
+ unset( $data['meta'] );
313
+ }
314
+ foreach ( $data as $f => $v ) {
315
+ $s = is_array( $v ) ? ' IN ' : '=';
316
+ if ( is_array( $v ) ) {
317
+ foreach ( $v as $_f => $_v ) {
318
+ $v[ $_f ] = $wpdb->prepare( '%s', $_v );
319
+ }
320
+ $v = implode( ',', $v );
321
+ $v = "($v)";
322
+ } else {
323
+ $v = $wpdb->prepare( '%s', $v );
324
+ }
325
+ $data[ $f ] = sprintf( '`%s`%s%s', $f, $s, $v );
326
+ }
327
+ $where = implode( ' AND ', $data );
328
+ $sql .= ' WHERE ' . $where;
329
+ }
330
+
331
+ $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
332
+ if ( ! empty( $default['sql'] ) ) {
333
+ $replacer = $replace = array();
334
+ $replace[0] = '{table}';
335
+ $replacer[0] = $this->table;
336
+ $replace[1] = '{where}';
337
+ $replacer[1] = $where;
338
+
339
+ foreach ( $default as $key => $value ) {
340
+ $i = count( $replace );
341
+
342
+ $replace[ $i ] = '{' . $key . '}';
343
+ $replacer[ $i ] = $value;
344
+ }
345
+
346
+ $sql = str_replace( $replace, $replacer, $default['sql'] );
347
+ }
348
+ $products = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
349
+
350
+ if ( empty( $products ) ) {
351
+ return array();
352
+ }
353
+
354
+ foreach ( $products as $k => $product ) {
355
+ if ( empty( $default['sql'] ) ) {
356
+ $product = filter_var_array( $product, array(
357
+ 'ID' => FILTER_VALIDATE_INT,
358
+ 'wishlist_id' => FILTER_VALIDATE_INT,
359
+ 'product_id' => FILTER_VALIDATE_INT,
360
+ 'variation_id' => FILTER_VALIDATE_INT,
361
+ 'author' => FILTER_VALIDATE_INT,
362
+ 'date' => FILTER_DEFAULT,
363
+ 'formdata' => FILTER_DEFAULT,
364
+ 'quantity' => FILTER_VALIDATE_INT,
365
+ 'price' => FILTER_SANITIZE_NUMBER_FLOAT,
366
+ 'in_stock' => FILTER_VALIDATE_BOOLEAN,
367
+ ) );
368
+ $product['quantity'] = 1;
369
+ }
370
+ if ( $default['external'] ) {
371
+ $product_data = $this->product_data( $product['product_id'], $product['variation_id'] );
372
+ if ( $product_data ) {
373
+ $product['product_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) );
374
+ $product['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
375
+ } else {
376
+ unset( $products[ $k ] );
377
+ continue;
378
+ }
379
+ $product['data'] = $product_data;
380
+ }
381
+ $product['meta'] = array();
382
+ if ( array_key_exists( 'formdata', $product ) ) {
383
+ $meta = $product['formdata'];
384
+ unset( $product['formdata'] );
385
+
386
+ $product['meta'] = $this->prepare_retrun_meta( $meta, $product['product_id'], $product['variation_id'], $product['quantity'] );
387
+ }
388
+ $products[ $k ] = apply_filters( 'tinvwl_wishlist_product_get', $product );
389
+ }
390
+
391
+ return $products;
392
+ }
393
+
394
+ /**
395
+ * Get product info
396
+ *
397
+ * @param integer $product_id Product id.
398
+ * @param integer $variation_id Product variation id.
399
+ *
400
+ * @return mixed
401
+ */
402
+ function product_data( $product_id, $variation_id = 0 ) {
403
+ $product_id = absint( $product_id );
404
+ $variation_id = absint( $variation_id );
405
+
406
+ if ( 'product_variation' == get_post_type( $product_id ) ) { // WPCS: loose comparison ok.
407
+ $variation_id = $product_id;
408
+ $product_id = wp_get_post_parent_id( $variation_id );
409
+ }
410
+
411
+ $product_data = apply_filters( 'tinvwl_product_data', wc_get_product( $variation_id ? $variation_id : $product_id ), $product_id, $variation_id );
412
+
413
+ if ( ! $product_data || 'trash' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->post->post_status : get_post( $product_data->get_id() )->post_status ) ) {
414
+ return null;
415
+ }
416
+
417
+ $product_data->variation_id = absint( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ) );
418
+
419
+ return $product_data;
420
+ }
421
+
422
+ /**
423
+ * Update product
424
+ *
425
+ * @param array $data Object product.
426
+ * @param array $meta Object meta form data.
427
+ *
428
+ * @return boolean
429
+ * @global wpdb $wpdb
430
+ *
431
+ */
432
+ function update( $data = array(), $meta = array() ) {
433
+ if ( empty( $meta ) && array_key_exists( 'meta', $data ) && ! empty( $data['meta'] ) ) {
434
+ $meta = $data['meta'];
435
+ }
436
+
437
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_update_field', array(
438
+ 'product_id' => FILTER_VALIDATE_INT,
439
+ 'quantity' => FILTER_VALIDATE_INT,
440
+ 'variation_id' => FILTER_VALIDATE_INT,
441
+ 'wishlist_id' => FILTER_VALIDATE_INT,
442
+ 'author' => FILTER_VALIDATE_INT,
443
+ ) ) );
444
+ $data = array_filter( $data );
445
+
446
+ if ( ! array_key_exists( 'wishlist_id', $data ) ) {
447
+ $data['wishlist_id'] = $this->wishlist_id();
448
+ }
449
+ if ( ! array_key_exists( 'variation_id', $data ) ) {
450
+ $data['variation_id'] = 0;
451
+ }
452
+
453
+ if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
454
+ return false;
455
+ }
456
+ $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
457
+ if ( ! $product_data ) {
458
+ return false;
459
+ }
460
+
461
+ if ( $product_data->is_sold_individually() ) {
462
+ $data['quantity'] = 1;
463
+ }
464
+
465
+ $data = apply_filters( 'tinvwl_wishlist_product_update', $data );
466
+ $data['in_stock'] = $product_data->is_in_stock();
467
+ $data['price'] = filter_var( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price() ), FILTER_VALIDATE_FLOAT );
468
+
469
+ global $wpdb;
470
+
471
+ return false !== $wpdb->update( $this->table, $data, array(
472
+ 'product_id' => $data['product_id'],
473
+ 'variation_id' => $data['variation_id'],
474
+ 'wishlist_id' => $data['wishlist_id'],
475
+ 'formdata' => $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] ),
476
+ ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
477
+ }
478
+
479
+ /**
480
+ * Remove product from wishlist
481
+ *
482
+ * @param integer $wishlist_id If exist wishlist object, you can put 0.
483
+ * @param integer $product_id Product id.
484
+ * @param integer $variation_id Product variation id.
485
+ * @param array $meta Object meta form data.
486
+ *
487
+ * @return boolean
488
+ * @global wpdb $wpdb
489
+ *
490
+ */
491
+ function remove_product_from_wl( $wishlist_id = 0, $product_id = 0, $variation_id = 0, $meta = array() ) {
492
+ global $wpdb;
493
+ if ( empty( $wishlist_id ) ) {
494
+ $wishlist_id = $this->wishlist_id();
495
+ }
496
+ if ( empty( $wishlist_id ) ) {
497
+ return false;
498
+ }
499
+ if ( empty( $product_id ) ) {
500
+ return false !== $wpdb->delete( $this->table, array( 'wishlist_id' => $wishlist_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
501
+ }
502
+ $product_data = $this->product_data( $product_id, $variation_id );
503
+ if ( ! $product_data ) {
504
+ return false;
505
+ }
506
+ $data = array(
507
+ 'wishlist_id' => $wishlist_id,
508
+ 'product_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) ),
509
+ 'variation_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ),
510
+ );
511
+ $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
512
+ $result = false !== $wpdb->delete( $this->table, $data ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
513
+ if ( $result ) {
514
+ do_action( 'tinvwl_wishlist_product_removed_from_wishlist', $wishlist_id, ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->id : ( $product_data->is_type( 'variation' ) ? $product_data->get_parent_id() : $product_data->get_id() ) ), ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ) );
515
+ }
516
+
517
+ return $result;
518
+ }
519
+
520
+ /**
521
+ * Remove product
522
+ *
523
+ * @param integer $product_id Product id.
524
+ *
525
+ * @return boolean
526
+ * @global wpdb $wpdb
527
+ *
528
+ */
529
+ function remove_product( $product_id = 0 ) {
530
+ if ( empty( $product_id ) ) {
531
+ return false;
532
+ }
533
+
534
+ global $wpdb;
535
+ $result = false !== $wpdb->delete( $this->table, array( 'product_id' => $product_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
536
+ if ( $result ) {
537
+ do_action( 'tinvwl_wishlist_product_removed_by_product', $product_id );
538
+ }
539
+
540
+ return $result;
541
+ }
542
+
543
+ /**
544
+ * Remove product by ID
545
+ *
546
+ * @param array $data Product data.
547
+ *
548
+ * @return boolean
549
+ * @global wpdb $wpdb
550
+ *
551
+ */
552
+ function remove( $data ) {
553
+ if ( ! isset( $data['ID'] ) || empty( $data['ID'] ) ) {
554
+ return false;
555
+ }
556
+
557
+ global $wpdb;
558
+ $result = false !== $wpdb->delete( $this->table, array( 'ID' => $data['ID'] ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
559
+ if ( $result ) {
560
+ /* Run a 3rd party code when product removed from a wishlist.
561
+ *
562
+ * @param array $data product data including author and wishlist IDs.
563
+ * */
564
+ do_action( 'tinvwl_product_removed', $data );
565
+ }
566
+
567
+ return $result;
568
+ }
569
+
570
+ /**
571
+ * Clean meta from default values.
572
+ *
573
+ * @param array $meta Meta array.
574
+ *
575
+ * @return array
576
+ */
577
+ function clean_meta( $meta ) {
578
+
579
+ foreach (
580
+ array(
581
+ 'add-to-cart',
582
+ 'product_id',
583
+ 'variation_id',
584
+ 'quantity',
585
+ 'undefined',
586
+ 'product_sku'
587
+ ) as $field
588
+ ) {
589
+ if ( array_key_exists( $field, $meta ) ) {
590
+ unset( $meta[ $field ] );
591
+ }
592
+ }
593
+ $meta = array_filter( $meta );
594
+
595
+ return $meta;
596
+ }
597
+
598
+ /**
599
+ * Prepare to save meta in database
600
+ *
601
+ * @param array $meta Meta array.
602
+ * @param ineger $product_id Woocommerce product ID.
603
+ * @param ineger $variation_id Woocommerce product variation ID.
604
+ *
605
+ * @return string
606
+ */
607
+ function prepare_save_meta( $meta = array(), $product_id = 0, $variation_id = 0 ) {
608
+ if ( ! is_array( $meta ) ) {
609
+ $meta = array();
610
+ }
611
+ $meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
612
+ foreach (
613
+ array(
614
+ 'add-to-cart',
615
+ 'product_id',
616
+ 'variation_id',
617
+ 'quantity',
618
+ 'undefined',
619
+ 'product_sku'
620
+ ) as $field
621
+ ) {
622
+ if ( array_key_exists( $field, $meta ) ) {
623
+ unset( $meta[ $field ] );
624
+ }
625
+ }
626
+ $meta = array_filter( $meta );
627
+ if ( empty( $meta ) ) {
628
+ return '';
629
+ }
630
+ ksort( $meta );
631
+
632
+ return json_encode( $meta );
633
+ }
634
+
635
+ /**
636
+ * Convert meta string to array
637
+ *
638
+ * @param string $meta Meta array.
639
+ * @param integer $product_id Product ID.
640
+ * @param integer $variation_id Variation product ID.
641
+ * @param integer $quantity Quantity product.
642
+ *
643
+ * @return array
644
+ */
645
+ function prepare_retrun_meta( $meta = '', $product_id = 0, $variation_id = 0, $quantity = 1 ) {
646
+ if ( empty( $meta ) ) {
647
+ return array();
648
+ }
649
+ $meta = @json_decode( $meta, true );
650
+ if ( empty( $meta ) || ! is_array( $meta ) ) {
651
+ return array();
652
+ }
653
+ if ( ! empty( $product_id ) ) {
654
+ $meta['add-to-cart'] = $product_id;
655
+ $meta['product_id'] = $product_id;
656
+ $meta['quantity'] = $quantity;
657
+ if ( ! empty( $variation_id ) ) {
658
+ $meta['variation_id'] = $variation_id;
659
+ }
660
+ }
661
+
662
+ return apply_filters( 'tinvwl_wishlist_product_unprepare_meta', $meta );
663
+ }
664
+ }
languages/ti-woocommerce-wishlist.pot CHANGED
@@ -1,8 +1,8 @@
1
- # Copyright (C) 2019 WooCommerce Wishlist Plugin - 1.10.1
2
- # This file is distributed under the same license as the WooCommerce Wishlist Plugin - 1.10.1 package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WooCommerce Wishlist Plugin - 1.10.1\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
@@ -60,7 +60,7 @@ msgstr ""
60
  msgid "Default Wishlist Name"
61
  msgstr ""
62
 
63
- #: admin/settings/general.class.php:86, admin/tinvwl.class.php:390
64
  msgid "Wishlist Page"
65
  msgstr ""
66
 
@@ -680,7 +680,7 @@ msgstr ""
680
  msgid "Normal Buttons Text Hover Color"
681
  msgstr ""
682
 
683
- #: admin/settings/upgrade.class.php:34, admin/tinvwl.class.php:265, views/wizard/finish.php:31
684
  msgid "Upgrade to Premium"
685
  msgstr ""
686
 
@@ -732,15 +732,15 @@ msgstr ""
732
  msgid " or "
733
  msgstr ""
734
 
735
- #: admin/tinvwl.class.php:188
736
  msgid "Are you sure you want to reset the settings?"
737
  msgstr ""
738
 
739
- #: admin/tinvwl.class.php:304
740
  msgid "<code>%1$s</code> version <strong style=\"color:red\">%2$s</strong> is out of date. The core version is <strong style=\"color:red\">%3$s</strong>"
741
  msgstr ""
742
 
743
- #: admin/tinvwl.class.php:330
744
  msgid "<strong>Your theme (%1$s) contains outdated copies of some WooCommerce Wishlist Plugin template files.</strong><br> These files may need updating to ensure they are compatible with the current version of WooCommerce Wishlist Plugin.<br> You can see which files are affected from the <a href=\"%2$s\">system status page</a>.<br> If in doubt, check with the author of the theme."
745
  msgstr ""
746
 
@@ -939,7 +939,7 @@ msgstr[1] ""
939
  msgid "Actions"
940
  msgstr ""
941
 
942
- #: public/wishlist/buttons.class.php:346, templates/ti-wishlist.php:76
943
  msgid "Remove"
944
  msgstr ""
945
 
@@ -1017,11 +1017,11 @@ msgstr ""
1017
  msgid "Stock Status"
1018
  msgstr ""
1019
 
1020
- #: templates/ti-wishlist-user.php:67, templates/ti-wishlist.php:68
1021
  msgid "Select for bulk action"
1022
  msgstr ""
1023
 
1024
- #: templates/ti-wishlist-user.php:120, templates/ti-wishlist.php:128, tinv-wishlists-function-integration.php:774, tinv-wishlists-function-integration.php:931, tinv-wishlists-function-integration.php:1093, tinv-wishlists-function-integration.php:1307
1025
  msgid "In stock"
1026
  msgstr ""
1027
 
@@ -1057,6 +1057,46 @@ msgstr ""
1057
  msgid "Base price"
1058
  msgstr ""
1059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1060
  #: views/admin/premium-features.php:36
1061
  msgid "Premium version"
1062
  msgstr ""
1
+ # Copyright (C) 2019 WooCommerce Wishlist Plugin - 1.11.0
2
+ # This file is distributed under the same license as the WooCommerce Wishlist Plugin - 1.11.0 package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WooCommerce Wishlist Plugin - 1.11.0\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
60
  msgid "Default Wishlist Name"
61
  msgstr ""
62
 
63
+ #: admin/settings/general.class.php:86, admin/tinvwl.class.php:398
64
  msgid "Wishlist Page"
65
  msgstr ""
66
 
680
  msgid "Normal Buttons Text Hover Color"
681
  msgstr ""
682
 
683
+ #: admin/settings/upgrade.class.php:34, admin/tinvwl.class.php:273, views/wizard/finish.php:31
684
  msgid "Upgrade to Premium"
685
  msgstr ""
686
 
732
  msgid " or "
733
  msgstr ""
734
 
735
+ #: admin/tinvwl.class.php:196
736
  msgid "Are you sure you want to reset the settings?"
737
  msgstr ""
738
 
739
+ #: admin/tinvwl.class.php:312
740
  msgid "<code>%1$s</code> version <strong style=\"color:red\">%2$s</strong> is out of date. The core version is <strong style=\"color:red\">%3$s</strong>"
741
  msgstr ""
742
 
743
+ #: admin/tinvwl.class.php:338
744
  msgid "<strong>Your theme (%1$s) contains outdated copies of some WooCommerce Wishlist Plugin template files.</strong><br> These files may need updating to ensure they are compatible with the current version of WooCommerce Wishlist Plugin.<br> You can see which files are affected from the <a href=\"%2$s\">system status page</a>.<br> If in doubt, check with the author of the theme."
745
  msgstr ""
746
 
939
  msgid "Actions"
940
  msgstr ""
941
 
942
+ #: public/wishlist/buttons.class.php:346, templates/ti-wishlist.php:88
943
  msgid "Remove"
944
  msgstr ""
945
 
1017
  msgid "Stock Status"
1018
  msgstr ""
1019
 
1020
+ #: templates/ti-wishlist-user.php:79, templates/ti-wishlist.php:80
1021
  msgid "Select for bulk action"
1022
  msgstr ""
1023
 
1024
+ #: templates/ti-wishlist-user.php:132, templates/ti-wishlist.php:140, tinv-wishlists-function-integration.php:774, tinv-wishlists-function-integration.php:931, tinv-wishlists-function-integration.php:1093, tinv-wishlists-function-integration.php:1307
1025
  msgid "In stock"
1026
  msgstr ""
1027
 
1057
  msgid "Base price"
1058
  msgstr ""
1059
 
1060
+ #: tinv-wishlists-function-integration.php:2336
1061
+ msgid "WooCommerce Wishlist"
1062
+ msgstr ""
1063
+
1064
+ #: tinv-wishlists-function-integration.php:2337
1065
+ msgid "Awards %_plural% for users adding products to their wishlist and purchased products from their wishlist."
1066
+ msgstr ""
1067
+
1068
+ #: tinv-wishlists-function-integration.php:2484
1069
+ msgid "Adding Product to Wishlist"
1070
+ msgstr ""
1071
+
1072
+ #: tinv-wishlists-function-integration.php:2489, tinv-wishlists-function-integration.php:2534
1073
+ msgid "Points"
1074
+ msgstr ""
1075
+
1076
+ #: tinv-wishlists-function-integration.php:2502, tinv-wishlists-function-integration.php:2547
1077
+ msgid "Limit"
1078
+ msgstr ""
1079
+
1080
+ #: tinv-wishlists-function-integration.php:2515, tinv-wishlists-function-integration.php:2560
1081
+ msgid "Log Template"
1082
+ msgstr ""
1083
+
1084
+ #: tinv-wishlists-function-integration.php:2519, tinv-wishlists-function-integration.php:2564
1085
+ msgid "required"
1086
+ msgstr ""
1087
+
1088
+ #: tinv-wishlists-function-integration.php:2529
1089
+ msgid "Purchasing Product from Wishlist"
1090
+ msgstr ""
1091
+
1092
+ #: tinv-wishlists-function-integration.php:2615
1093
+ msgid "Purchased From Wishlist"
1094
+ msgstr ""
1095
+
1096
+ #: tinv-wishlists-function-integration.php:2616
1097
+ msgid "Added To Wishlist"
1098
+ msgstr ""
1099
+
1100
  #: views/admin/premium-features.php:36
1101
  msgid "Premium version"
1102
  msgstr ""
public/wishlist/view.class.php CHANGED
@@ -1,693 +1,693 @@
1
- <?php
2
- /**
3
- * Wishlist shortcode
4
- *
5
- * @since 1.0.0
6
- * @package TInvWishlist\Public
7
- */
8
-
9
- // If this file is called directly, abort.
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- die;
12
- }
13
-
14
- /**
15
- * Wishlist shortcode
16
- */
17
- class TInvWL_Public_Wishlist_View {
18
-
19
- /**
20
- * Plugin name
21
- *
22
- * @var string
23
- */
24
- private $_name;
25
-
26
- /**
27
- * List per page
28
- *
29
- * @var integer
30
- */
31
- private $lists_per_page;
32
-
33
- /**
34
- * Current wishlist
35
- *
36
- * @var array
37
- */
38
- private $current_wishlist;
39
- /**
40
- * This class
41
- *
42
- * @var \TInvWL_Public_Wishlist_View
43
- */
44
- protected static $_instance = null;
45
-
46
- /**
47
- * Get this class object
48
- *
49
- * @param string $plugin_name Plugin name.
50
- *
51
- * @return \TInvWL_Public_Wishlist_View
52
- */
53
- public static function instance( $plugin_name = TINVWL_PREFIX ) {
54
- if ( is_null( self::$_instance ) ) {
55
- self::$_instance = new self( $plugin_name );
56
- }
57
-
58
- return self::$_instance;
59
- }
60
-
61
- /**
62
- * Constructor
63
- *
64
- * @param string $plugin_name Plugin name.
65
- */
66
- function __construct( $plugin_name ) {
67
- $this->_name = $plugin_name;
68
- $this->define_hooks();
69
- }
70
-
71
- /**
72
- * Defined shortcode and hooks
73
- */
74
- function define_hooks() {
75
- add_action( 'template_redirect', array( $this, 'login_redirect' ) );
76
-
77
- add_action( 'wp_loaded', array( $this, 'login_post_redirect' ), 19 );
78
-
79
- add_action( 'wp', array( $this, 'wishlist_action' ), 0 );
80
-
81
- add_action( 'tinvwl_before_wishlist', array( $this, 'wishlist_header' ) );
82
-
83
- add_action( 'tinvwl_after_wishlist', array( 'TInvWL_Public_Wishlist_Social', 'init' ) );
84
-
85
- add_filter( 'tinvwl_wishlist_item_action_add_to_cart', array( $this, 'product_allow_add_to_cart' ), 10, 3 );
86
- add_filter( 'tinvwl_wishlist_item_add_to_cart', array( $this, 'external_text' ), 10, 3 );
87
- add_filter( 'tinvwl_wishlist_item_add_to_cart', array( $this, 'variable_text' ), 10, 3 );
88
- add_action( 'tinvwl_after_wishlist_table', array( $this, 'get_per_page' ) );
89
-
90
- TInvWL_Public_Wishlist_Buttons::init( $this->_name );
91
- }
92
-
93
- /**
94
- * Redirect back after successful login.
95
- */
96
- public function login_post_redirect() {
97
- $nonce_value = isset( $_REQUEST['woocommerce-login-nonce'] ) ? $_REQUEST['woocommerce-login-nonce'] : ( isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : '' );
98
- if ( ! empty( $_POST['login'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) && ! empty( $_GET['tinvwl_redirect'] ) ) {
99
- $_POST['redirect'] = $_GET['tinvwl_redirect']; // Force WC Login form handler to do redirect.
100
- }
101
- }
102
-
103
- /**
104
- * Redirect guests to login page.
105
- */
106
- public function login_redirect() {
107
- if ( ! wc_get_page_id( 'myaccount' ) && is_page( apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true ) ) && ! is_user_logged_in() && tinv_get_option( 'general', 'require_login' ) ) {
108
- $full_link = get_permalink();
109
- $share_key = get_query_var( 'tinvwlID', null );
110
- if ( ! empty( $share_key ) ) {
111
- if ( get_option( 'permalink_structure' ) ) {
112
- if ( ! preg_match( '/\/$/', $full_link ) ) {
113
- $full_link .= '/';
114
- }
115
- $full_link .= $share_key . '/';
116
- } else {
117
- $full_link = add_query_arg( 'tinvwlID', $share_key, $full_link );
118
- }
119
- }
120
-
121
- wp_safe_redirect( add_query_arg( 'tinvwl_redirect', esc_url( $full_link ), wc_get_page_permalink( 'myaccount' ) ) );
122
- exit;
123
- }
124
- }
125
-
126
- /**
127
- * Change Text for external product
128
- *
129
- * @param string $text Text for button add to cart.
130
- * @param array $wl_product Wishlist Product.
131
- * @param WC_Product $_product Product.
132
- *
133
- * @return string
134
- */
135
- function external_text( $text, $wl_product, $_product ) {
136
- global $product;
137
- // store global product data.
138
- $_product_tmp = $product;
139
- // override global product data.
140
- $product = $_product;
141
-
142
- if ( 'external' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
143
-
144
- $text = $product->single_add_to_cart_text();
145
-
146
- // restore global product data.
147
- $product = $_product_tmp;
148
- }
149
-
150
- return $text;
151
- }
152
-
153
- /**
154
- * Change Text for variable product that requires to select some variations.
155
- *
156
- * @param string $text Text for button add to cart.
157
- * @param array $wl_product Wishlist Product.
158
- * @param WC_Product $_product Product.
159
- *
160
- * @return string
161
- */
162
- function variable_text( $text, $wl_product, $_product ) {
163
- global $product;
164
- // store global product data.
165
- $_product_tmp = $product;
166
- // override global product data.
167
- $product = $_product;
168
- if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $product, $product->get_permalink(), $wl_product )
169
- && in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), array(
170
- 'variable',
171
- 'variable-subscription'
172
- ) ) ) {
173
-
174
- $text = $product->add_to_cart_text();
175
-
176
- // restore global product data.
177
- $product = $_product_tmp;
178
- }
179
-
180
- return $text;
181
- }
182
-
183
- /**
184
- * Get current wishlist
185
- *
186
- * @return array
187
- */
188
- function get_current_wishlist() {
189
- if ( empty( $this->current_wishlist ) ) {
190
- $this->current_wishlist = apply_filters( 'tinvwl_get_current_wishlist', tinv_wishlist_get() );
191
- }
192
-
193
- return $this->current_wishlist;
194
- }
195
-
196
- /**
197
- * Get current products from wishlist
198
- *
199
- * @param array $wishlist Wishlist object.
200
- * @param boolean $external Get woocommerce product info.
201
- * @param integer $lists_per_page Count per page.
202
- *
203
- * @return array
204
- */
205
- function get_current_products( $wishlist = null, $external = true, $lists_per_page = 10 ) {
206
- if ( empty( $wishlist ) ) {
207
- $wishlist = $this->get_current_wishlist();
208
- }
209
- $wlp = null;
210
- if ( isset( $wishlist['ID'] ) && 0 === $wishlist['ID'] ) {
211
- $wlp = TInvWL_Product_Local::instance();
212
- } else {
213
- $wlp = new TInvWL_Product( $wishlist );
214
- }
215
- if ( empty( $wlp ) ) {
216
- return array();
217
- }
218
-
219
- $paged = get_query_var( 'wl_paged', 1 );
220
- $paged = 1 < $paged ? $paged : 1;
221
-
222
- $product_data = array(
223
- 'count' => $lists_per_page,
224
- 'offset' => $lists_per_page * ( $paged - 1 ),
225
- 'external' => $external,
226
- 'order_by' => 'date',
227
- 'order' => 'DESC',
228
- );
229
- $pages = ceil( count( $wlp->get_wishlist( array(
230
- 'count' => 9999999,
231
- 'external' => false,
232
- ) ) ) / absint( $lists_per_page ) );
233
-
234
- if ( 1 < $paged ) {
235
- add_action( 'tinvwl_pagenation_wishlist', array( $this, 'page_prev' ) );
236
- }
237
- if ( 1 < $pages ) {
238
- $this->pages = $pages;
239
- add_action( 'tinvwl_pagenation_wishlist', array( $this, 'pages' ) );
240
- }
241
- if ( $pages > $paged ) {
242
- add_action( 'tinvwl_pagenation_wishlist', array( $this, 'page_next' ) );
243
- }
244
-
245
- $product_data = apply_filters( 'tinvwl_before_get_current_product', $product_data );
246
- $products = $wlp->get_wishlist( $product_data );
247
- $products = apply_filters( 'tinvwl_after_get_current_product', $products );
248
-
249
- return $products;
250
- }
251
-
252
- /**
253
- * Allow show button add to cart
254
- *
255
- * @param boolean $allow Settings flag.
256
- * @param array $wlproduct Wishlist Product.
257
- * @param WC_Product $product Product.
258
- *
259
- * @return boolean
260
- */
261
- function product_allow_add_to_cart( $allow, $wlproduct, $product ) {
262
- if ( ! $allow ) {
263
- return false;
264
- }
265
-
266
- return ( $product->is_purchasable() || 'external' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) && ( $product->is_in_stock() || $product->backorders_allowed() );
267
- }
268
-
269
- /**
270
- * Basic validation actions
271
- *
272
- * @return boolean
273
- */
274
- function wishlist_action() {
275
-
276
- $wishlist_page_id = apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true );
277
-
278
- if ( is_page( $wishlist_page_id )
279
- || ( is_home() && 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) === $wishlist_page_id )
280
- || ( is_shop() && wc_get_page_id( 'shop' ) === $wishlist_page_id ) ) {
281
- $wishlist = $this->get_current_wishlist();
282
- if ( empty( $wishlist ) ) {
283
- return false;
284
- }
285
-
286
- if ( version_compare( WC_VERSION, '3.2.0', '<' ) ) {
287
- if ( ! defined( 'DONOTCACHEPAGE' ) ) {
288
- define( 'DONOTCACHEPAGE', true );
289
- }
290
- if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
291
- define( 'DONOTCACHEOBJECT', true );
292
- }
293
- if ( ! defined( 'DONOTCACHEDB' ) ) {
294
- define( 'DONOTCACHEDB', true );
295
- }
296
- } else {
297
- WC_Cache_Helper::set_nocache_constants( true );
298
- nocache_headers();
299
- }
300
-
301
- $is_owner = is_user_logged_in() ? ( get_current_user_id() === $wishlist['author'] ) : $wishlist['is_owner'];
302
- $nonce = filter_input( INPUT_POST, 'wishlist_nonce' );
303
- if ( $nonce && wp_verify_nonce( $nonce, 'tinvwl_wishlist_owner' ) && $is_owner ) {
304
- do_action( 'tinvwl_before_action_owner', $wishlist );
305
- $this->wishlist_actions( $wishlist, true );
306
- do_action( 'tinvwl_after_action_owner', $wishlist );
307
- }
308
- if ( $nonce && wp_verify_nonce( $nonce, 'tinvwl_wishlist_user' ) && ! $is_owner ) {
309
- do_action( 'tinvwl_before_action_user', $wishlist );
310
- $this->wishlist_actions( $wishlist, false );
311
- do_action( 'tinvwl_after_action_user', $wishlist );
312
- }
313
- }
314
- }
315
-
316
- /**
317
- * Basic actions
318
- *
319
- * @param array $wishlist Wishlist object.
320
- * @param boolean $owner Is Owner.
321
- *
322
- * @return boolean
323
- */
324
- function wishlist_actions( $wishlist, $owner = false ) {
325
- $post = filter_input_array( INPUT_POST, array(
326
- 'wishlist_pr' => array(
327
- 'filter' => FILTER_VALIDATE_INT,
328
- 'flags' => FILTER_FORCE_ARRAY,
329
- ),
330
- 'wishlist_qty' => array(
331
- 'filter' => FILTER_VALIDATE_INT,
332
- 'flags' => FILTER_FORCE_ARRAY,
333
- 'options' => array( 'min_range' => 0, 'default' => 1 ),
334
- ),
335
- 'tinvwl-add-to-cart' => FILTER_VALIDATE_INT,
336
- 'tinvwl-remove' => FILTER_VALIDATE_INT,
337
- 'tinvwl-action' => FILTER_SANITIZE_STRING,
338
- ) );
339
-
340
- if ( ! empty( $post['tinvwl-add-to-cart'] ) ) {
341
- $product = $post['tinvwl-add-to-cart'];
342
- $quantity = array_key_exists( $product, (array) $post['wishlist_qty'] ) ? $post['wishlist_qty'][ $product ] : 1;
343
-
344
- return $this->button_addtocart( $wishlist, $product, $quantity, $owner );
345
- }
346
- if ( ! empty( $post['tinvwl-remove'] ) ) {
347
- if ( ! $wishlist['is_owner'] ) {
348
- return false;
349
- }
350
- $product = $post['tinvwl-remove'];
351
- if ( 0 === $wishlist['ID'] ) {
352
- $wlp = TInvWL_Product_Local::instance();
353
- } else {
354
- $wlp = new TInvWL_Product( $wishlist );
355
- }
356
- if ( empty( $wlp ) ) {
357
- return false;
358
- }
359
- $product_data = $wlp->get_wishlist( array( 'ID' => $product ) );
360
- $product_data = array_shift( $product_data );
361
- if ( empty( $product_data ) ) {
362
- return false;
363
- }
364
- $title = sprintf( __( '&ldquo;%s&rdquo;', 'ti-woocommerce-wishlist' ), $product_data['data']->get_title() );
365
- if ( $wlp->remove( $product_data ) ) {
366
- add_action( 'tinvwl_before_wishlist', array(
367
- 'TInvWL_Public_Wishlist_View',
368
- 'check_cart_hash'
369
- ), 99, 1 );
370
- add_action( 'woocommerce_set_cart_cookies', array(
371
- 'TInvWL_Public_Wishlist_View',
372
- 'reset_cart_hash'
373
- ), 99, 1 );
374
- wc_add_notice( sprintf( __( '%s has been removed from wishlist.', 'ti-woocommerce-wishlist' ), $title ) );
375
- } else {
376
- wc_add_notice( sprintf( __( '%s has not been removed from wishlist.', 'ti-woocommerce-wishlist' ), $title ), 'error' );
377
- }
378
-
379
- return true;
380
- }
381
- do_action( 'tinvwl_action_' . $post['tinvwl-action'], $wishlist, $post['wishlist_pr'], $post['wishlist_qty'], $owner ); // @codingStandardsIgnoreLine WordPress.NamingConventions.ValidHookName.UseUnderscores
382
- }
383
-
384
- /**
385
- * Check cart hash to trigger WC fragments refresh on wishlist update.
386
- *
387
- * @param $wishlist
388
- */
389
- public static function check_cart_hash( $wishlist ) {
390
- wp_add_inline_script( 'woocommerce', "
391
- jQuery(document).ready(function($){
392
- if ( typeof wc_cart_fragments_params === 'undefined' ) {
393
- return false;
394
- }
395
-
396
- var cart_hash_key = wc_cart_fragments_params.cart_hash_key,
397
- cart_hash = sessionStorage.getItem( cart_hash_key );
398
-
399
- if ( cart_hash === null || cart_hash === undefined || cart_hash === '' ) {
400
- sessionStorage.setItem( cart_hash_key, 'empty' );
401
- }
402
- });
403
- " );
404
- }
405
-
406
- /**
407
- * Reset cart hash to trigger WC fragments refresh on wishlist update.
408
- *
409
- * @param bool $set
410
- */
411
- public static function reset_cart_hash( $set ) {
412
- wc_setcookie( 'woocommerce_cart_hash', 'reset', time() - HOUR_IN_SECONDS );
413
- }
414
-
415
- /**
416
- * Apply action add to cart
417
- *
418
- * @param array $wishlist Wishlist object.
419
- * @param integer $id Product id in wishlist.
420
- * @param integer $quantity Product quantity.
421
- * @param boolean $owner Is Owner.
422
- *
423
- * @return boolean
424
- */
425
- function button_addtocart( $wishlist, $id, $quantity = 1, $owner = false ) {
426
- $id = absint( $id );
427
- $quantity = absint( $quantity );
428
- if ( empty( $id ) || empty( $quantity ) ) {
429
- return false;
430
- }
431
-
432
- $wlp = null;
433
- if ( 0 === $wishlist['ID'] ) {
434
- $wlp = TInvWL_Product_Local::instance();
435
- } else {
436
- $wlp = new TInvWL_Product( $wishlist );
437
- }
438
- if ( empty( $wlp ) ) {
439
- return false;
440
- }
441
-
442
- $_product = $wlp->get_wishlist( array( 'ID' => $id ) );
443
- $_product = array_shift( $_product );
444
- if ( empty( $_product ) || empty( $_product['data'] ) ) {
445
- return false;
446
- }
447
-
448
- global $product;
449
- // store global product data.
450
- $_product_tmp = $product;
451
- // override global product data.
452
- $product = $_product['data'];
453
-
454
- add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
455
- $redirect_url = $_product['data']->add_to_cart_url();
456
- remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
457
-
458
- // restore global product data.
459
- $product = $_product_tmp;
460
-
461
- $quantity = apply_filters( 'tinvwl_product_add_to_cart_quantity', $quantity, $_product['data'] );
462
-
463
- if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $_product['data'], $redirect_url, $_product ) ) {
464
- wp_redirect( apply_filters( 'tinvwl_product_add_to_cart_redirect_url', $redirect_url, $_product['data'], $_product ) ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.wp_redirect
465
- exit;
466
- } elseif ( apply_filters( 'tinvwl_allow_addtocart_in_wishlist', true, $wishlist, $owner ) ) {
467
- $add = TInvWL_Public_Cart::add( $wishlist, $id, $quantity );
468
- if ( $add ) {
469
- wc_add_to_cart_message( $add, true );
470
-
471
- if ( tinv_get_option( 'processing', 'redirect_checkout' ) ) {
472
- wp_safe_redirect( wc_get_checkout_url() );
473
- exit;
474
- }
475
-
476
- if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
477
- wp_safe_redirect( wc_get_cart_url() );
478
- exit;
479
- }
480
-
481
- return true;
482
- }
483
- }
484
-
485
- return false;
486
- }
487
-
488
- /**
489
- * Output page
490
- *
491
- * @param array $atts Array parameter for shortcode.
492
- *
493
- * @return mixed
494
- */
495
- function htmloutput( $atts ) {
496
- $wishlist = $this->get_current_wishlist();
497
-
498
- if ( empty( $wishlist ) ) {
499
- $id = get_query_var( 'tinvwlID', null );
500
- if ( empty( $id ) && ( is_user_logged_in() || ! tinv_get_option( 'general', 'require_login' ) ) ) {
501
- return $this->wishlist_empty( array(), array(
502
- 'ID' => '',
503
- 'author' => get_current_user_id(),
504
- 'title' => apply_filters( 'tinvwl-general-default_title', tinv_get_option( 'general', 'default_title' ) ),
505
- 'status' => 'private',
506
- 'type' => 'default',
507
- 'share_key' => '',
508
- ) );
509
- }
510
-
511
- return $this->wishlist_null();
512
- }
513
-
514
- if ( 'private' === $wishlist['status'] && ! $wishlist['is_owner'] ) {
515
- return $this->wishlist_null();
516
- }
517
- if ( 'default' !== $wishlist['type'] && ! tinv_get_option( 'general', 'multi' ) ) {
518
- if ( $wishlist['is_owner'] ) {
519
- printf( '<p><a href="%s">%s</p><script type="text/javascript">window.location.href="%s"</script>', esc_attr( tinv_url_wishlist_default() ), esc_html__( 'Return to Wishlist', 'ti-woocommerce-wishlist' ), esc_attr( tinv_url_wishlist_default() ) );
520
-
521
- return false;
522
- } else {
523
- return $this->wishlist_null();
524
- }
525
- }
526
-
527
- $products = $this->get_current_products( $wishlist, true, absint( $atts['lists_per_page'] ) );
528
-
529
- $this->lists_per_page = $atts['lists_per_page'];
530
-
531
- $wla = new TInvWL_Analytics( $wishlist, $this->_name );
532
- $wla->wishlist_view( 0, $wishlist['is_owner'] );
533
-
534
- foreach ( $products as $key => $product ) {
535
- if ( ! isset( $product['data'] ) ) {
536
- unset( $products[ $key ] );
537
- }
538
- }
539
-
540
- if ( empty( $products ) ) {
541
- return $this->wishlist_empty( $products, $wishlist );
542
- }
543
-
544
- $wishlist_table_row = tinv_get_option( 'product_table' );
545
- $wishlist_table_row['text_add_to_cart'] = apply_filters( 'tinvwl-product_table-text_add_to_cart', tinv_get_option( 'product_table', 'text_add_to_cart' ) );
546
-
547
- $data = array(
548
- 'products' => $products,
549
- 'wishlist' => $wishlist,
550
- 'wishlist_table' => tinv_get_option( 'table' ),
551
- 'wishlist_table_row' => $wishlist_table_row,
552
- );
553
-
554
- if ( $wishlist['is_owner'] ) {
555
- tinv_wishlist_template( 'ti-wishlist.php', $data );
556
- } else {
557
- if ( class_exists( 'WC_Catalog_Visibility_Options' ) ) {
558
- global $wc_cvo;
559
- if ( 'secured' === $wc_cvo->setting( 'wc_cvo_atc' && isset( $data['wishlist_table_row']['add_to_cart'] ) ) ) {
560
- unset( $data['wishlist_table_row']['add_to_cart'] );
561
- }
562
- if ( 'secured' === $wc_cvo->setting( 'wc_cvo_prices' && isset( $data['wishlist_table_row']['colm_price'] ) ) ) {
563
- unset( $data['wishlist_table_row']['colm_price'] );
564
- }
565
- }
566
-
567
- tinv_wishlist_template( 'ti-wishlist-user.php', $data );
568
- }
569
- }
570
-
571
- /**
572
- * Not Found Wishlist
573
- *
574
- * @param array $wishlist Wishlist object.
575
- */
576
- function wishlist_null( $wishlist = array() ) {
577
- $data = array(
578
- 'wishlist' => $wishlist,
579
- );
580
- tinv_wishlist_template( 'ti-wishlist-null.php', $data );
581
- }
582
-
583
- /**
584
- * Empty Wishlist
585
- *
586
- * @param array $products Products wishlist.
587
- * @param array $wishlist Wishlist object.
588
- */
589
- function wishlist_empty( $products = array(), $wishlist = array() ) {
590
- $data = array(
591
- 'products' => $products,
592
- 'wishlist' => $wishlist,
593
- 'wishlist_table' => tinv_get_option( 'table' ),
594
- );
595
- tinv_wishlist_template( 'ti-wishlist-empty.php', $data );
596
- }
597
-
598
- /**
599
- * Header Wishlist
600
- *
601
- * @param array $wishlist Wishlist object.
602
- */
603
- function wishlist_header( $wishlist ) {
604
-
605
- $data = array(
606
- 'wishlist' => $wishlist,
607
- );
608
- tinv_wishlist_template( 'ti-wishlist-header.php', $data );
609
- }
610
-
611
- /**
612
- * Prev page button
613
- */
614
- function page_prev() {
615
- $paged = get_query_var( 'wl_paged', 1 );
616
- $paged = 1 < $paged ? $paged - 1 : 0;
617
- $this->page( $paged, sprintf( '<i class="ftinvwl ftinvwl-chevron-left"></i><span>%s</span>', __( 'Previous Page', 'ti-woocommerce-wishlist' ) ), array( 'class' => 'button tinv-prev' ) );
618
- }
619
-
620
- /**
621
- * Pages
622
- */
623
- function pages() {
624
-
625
- $paged = get_query_var( 'wl_paged', 1 );
626
- if ( 1 === (int) $paged ) {
627
- echo '<span></span>';
628
- }
629
-
630
- echo '<span>' . $paged . '/' . $this->pages . '</span>';
631
-
632
- if ( (int) $this->pages === (int) $paged ) {
633
- echo '<span></span>';
634
- }
635
- }
636
-
637
- /**
638
- * Next page button
639
- */
640
- function page_next() {
641
- $paged = get_query_var( 'wl_paged', 1 );
642
- $paged = 1 < $paged ? $paged + 1 : 2;
643
- $this->page( $paged, sprintf( '<span>%s</span><i class="ftinvwl ftinvwl-chevron-right"></i>', __( 'Next Page', 'ti-woocommerce-wishlist' ) ), array( 'class' => 'button tinv-next' ) );
644
- }
645
-
646
- /**
647
- * Page button
648
- *
649
- * @param integer $paged Index page.
650
- * @param string $text Text button.
651
- * @param style $style Style attribute.
652
- */
653
- function page( $paged, $text, $style = array() ) {
654
- $paged = absint( $paged );
655
- $wishlist = tinv_wishlist_get();
656
- $link = tinv_url_wishlist( $wishlist['share_key'], $paged, true );
657
- if ( is_array( $style ) ) {
658
- $style = TInvWL_Form::__atrtostr( $style );
659
- }
660
- printf( '<a href="%s" %s>%s</a>', esc_url( $link ), $style, $text ); // WPCS: xss ok.
661
- }
662
-
663
- /**
664
- * Shortcode basic function
665
- *
666
- * @param array $atts Array parameter from shortcode.
667
- *
668
- * @return string
669
- */
670
- function shortcode( $atts = array() ) {
671
- $default = array(
672
- 'lists_per_page' => 10,
673
- );
674
- $atts = shortcode_atts( $default, $atts );
675
-
676
- ob_start();
677
- $this->htmloutput( $atts );
678
-
679
- return ob_get_clean();
680
- }
681
-
682
- /**
683
- * Get per page items for buttons
684
- */
685
- function get_per_page() {
686
- if ( ! empty( $this->lists_per_page ) ) {
687
- echo TInvWL_Form::_text( array( // WPCS: xss ok.
688
- 'type' => 'hidden',
689
- 'name' => 'lists_per_page',
690
- ), $this->lists_per_page );
691
- }
692
- }
693
- }
1
+ <?php
2
+ /**
3
+ * Wishlist shortcode
4
+ *
5
+ * @since 1.0.0
6
+ * @package TInvWishlist\Public
7
+ */
8
+
9
+ // If this file is called directly, abort.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ die;
12
+ }
13
+
14
+ /**
15
+ * Wishlist shortcode
16
+ */
17
+ class TInvWL_Public_Wishlist_View {
18
+
19
+ /**
20
+ * Plugin name
21
+ *
22
+ * @var string
23
+ */
24
+ private $_name;
25
+
26
+ /**
27
+ * List per page
28
+ *
29
+ * @var integer
30
+ */
31
+ private $lists_per_page;
32
+
33
+ /**
34
+ * Current wishlist
35
+ *
36
+ * @var array
37
+ */
38
+ private $current_wishlist;
39
+ /**
40
+ * This class
41
+ *
42
+ * @var \TInvWL_Public_Wishlist_View
43
+ */
44
+ protected static $_instance = null;
45
+
46
+ /**
47
+ * Get this class object
48
+ *
49
+ * @param string $plugin_name Plugin name.
50
+ *
51
+ * @return \TInvWL_Public_Wishlist_View
52
+ */
53
+ public static function instance( $plugin_name = TINVWL_PREFIX ) {
54
+ if ( is_null( self::$_instance ) ) {
55
+ self::$_instance = new self( $plugin_name );
56
+ }
57
+
58
+ return self::$_instance;
59
+ }
60
+
61
+ /**
62
+ * Constructor
63
+ *
64
+ * @param string $plugin_name Plugin name.
65
+ */
66
+ function __construct( $plugin_name ) {
67
+ $this->_name = $plugin_name;
68
+ $this->define_hooks();
69
+ }
70
+
71
+ /**
72
+ * Defined shortcode and hooks
73
+ */
74
+ function define_hooks() {
75
+ add_action( 'template_redirect', array( $this, 'login_redirect' ) );
76
+
77
+ add_action( 'wp_loaded', array( $this, 'login_post_redirect' ), 19 );
78
+
79
+ add_action( 'wp', array( $this, 'wishlist_action' ), 0 );
80
+
81
+ add_action( 'tinvwl_before_wishlist', array( $this, 'wishlist_header' ) );
82
+
83
+ add_action( 'tinvwl_after_wishlist', array( 'TInvWL_Public_Wishlist_Social', 'init' ) );
84
+
85
+ add_filter( 'tinvwl_wishlist_item_action_add_to_cart', array( $this, 'product_allow_add_to_cart' ), 10, 3 );
86
+ add_filter( 'tinvwl_wishlist_item_add_to_cart', array( $this, 'external_text' ), 10, 3 );
87
+ add_filter( 'tinvwl_wishlist_item_add_to_cart', array( $this, 'variable_text' ), 10, 3 );
88
+ add_action( 'tinvwl_after_wishlist_table', array( $this, 'get_per_page' ) );
89
+
90
+ TInvWL_Public_Wishlist_Buttons::init( $this->_name );
91
+ }
92
+
93
+ /**
94
+ * Redirect back after successful login.
95
+ */
96
+ public function login_post_redirect() {
97
+ $nonce_value = isset( $_REQUEST['woocommerce-login-nonce'] ) ? $_REQUEST['woocommerce-login-nonce'] : ( isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : '' );
98
+ if ( ! empty( $_POST['login'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) && ! empty( $_GET['tinvwl_redirect'] ) ) {
99
+ $_POST['redirect'] = $_GET['tinvwl_redirect']; // Force WC Login form handler to do redirect.
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Redirect guests to login page.
105
+ */
106
+ public function login_redirect() {
107
+ if ( ! wc_get_page_id( 'myaccount' ) && is_page( apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true ) ) && ! is_user_logged_in() && tinv_get_option( 'general', 'require_login' ) ) {
108
+ $full_link = get_permalink();
109
+ $share_key = get_query_var( 'tinvwlID', null );
110
+ if ( ! empty( $share_key ) ) {
111
+ if ( get_option( 'permalink_structure' ) ) {
112
+ if ( ! preg_match( '/\/$/', $full_link ) ) {
113
+ $full_link .= '/';
114
+ }
115
+ $full_link .= $share_key . '/';
116
+ } else {
117
+ $full_link = add_query_arg( 'tinvwlID', $share_key, $full_link );
118
+ }
119
+ }
120
+
121
+ wp_safe_redirect( add_query_arg( 'tinvwl_redirect', esc_url( $full_link ), wc_get_page_permalink( 'myaccount' ) ) );
122
+ exit;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Change Text for external product
128
+ *
129
+ * @param string $text Text for button add to cart.
130
+ * @param array $wl_product Wishlist Product.
131
+ * @param WC_Product $_product Product.
132
+ *
133
+ * @return string
134
+ */
135
+ function external_text( $text, $wl_product, $_product ) {
136
+ global $product;
137
+ // store global product data.
138
+ $_product_tmp = $product;
139
+ // override global product data.
140
+ $product = $_product;
141
+
142
+ if ( 'external' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
143
+
144
+ $text = $product->single_add_to_cart_text();
145
+
146
+ // restore global product data.
147
+ $product = $_product_tmp;
148
+ }
149
+
150
+ return $text;
151
+ }
152
+
153
+ /**
154
+ * Change Text for variable product that requires to select some variations.
155
+ *
156
+ * @param string $text Text for button add to cart.
157
+ * @param array $wl_product Wishlist Product.
158
+ * @param WC_Product $_product Product.
159
+ *
160
+ * @return string
161
+ */
162
+ function variable_text( $text, $wl_product, $_product ) {
163
+ global $product;
164
+ // store global product data.
165
+ $_product_tmp = $product;
166
+ // override global product data.
167
+ $product = $_product;
168
+ if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $product, $product->get_permalink(), $wl_product )
169
+ && in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), array(
170
+ 'variable',
171
+ 'variable-subscription'
172
+ ) ) ) {
173
+
174
+ $text = $product->add_to_cart_text();
175
+
176
+ // restore global product data.
177
+ $product = $_product_tmp;
178
+ }
179
+
180
+ return $text;
181
+ }
182
+
183
+ /**
184
+ * Get current wishlist
185
+ *
186
+ * @return array
187
+ */
188
+ function get_current_wishlist() {
189
+ if ( empty( $this->current_wishlist ) ) {
190
+ $this->current_wishlist = apply_filters( 'tinvwl_get_current_wishlist', tinv_wishlist_get() );
191
+ }
192
+
193
+ return $this->current_wishlist;
194
+ }
195
+
196
+ /**
197
+ * Get current products from wishlist
198
+ *
199
+ * @param array $wishlist Wishlist object.
200
+ * @param boolean $external Get woocommerce product info.
201
+ * @param integer $lists_per_page Count per page.
202
+ *
203
+ * @return array
204
+ */
205
+ function get_current_products( $wishlist = null, $external = true, $lists_per_page = 10 ) {
206
+ if ( empty( $wishlist ) ) {
207
+ $wishlist = $this->get_current_wishlist();
208
+ }
209
+ $wlp = null;
210
+ if ( isset( $wishlist['ID'] ) && 0 === $wishlist['ID'] ) {
211
+ $wlp = TInvWL_Product_Local::instance();
212
+ } else {
213
+ $wlp = new TInvWL_Product( $wishlist );
214
+ }
215
+ if ( empty( $wlp ) ) {
216
+ return array();
217
+ }
218
+
219
+ $paged = get_query_var( 'wl_paged', 1 );
220
+ $paged = 1 < $paged ? $paged : 1;
221
+
222
+ $product_data = array(
223
+ 'count' => $lists_per_page,
224
+ 'offset' => $lists_per_page * ( $paged - 1 ),
225
+ 'external' => $external,
226
+ 'order_by' => 'date',
227
+ 'order' => 'DESC',
228
+ );
229
+ $pages = ceil( count( $wlp->get_wishlist( array(
230
+ 'count' => 9999999,
231
+ 'external' => false,
232
+ ) ) ) / absint( $lists_per_page ) );
233
+
234
+ if ( 1 < $paged ) {
235
+ add_action( 'tinvwl_pagenation_wishlist', array( $this, 'page_prev' ) );
236
+ }
237
+ if ( 1 < $pages ) {
238
+ $this->pages = $pages;
239
+ add_action( 'tinvwl_pagenation_wishlist', array( $this, 'pages' ) );
240
+ }
241
+ if ( $pages > $paged ) {
242
+ add_action( 'tinvwl_pagenation_wishlist', array( $this, 'page_next' ) );
243
+ }
244
+
245
+ $product_data = apply_filters( 'tinvwl_before_get_current_product', $product_data );
246
+ $products = $wlp->get_wishlist( $product_data );
247
+ $products = apply_filters( 'tinvwl_after_get_current_product', $products );
248
+
249
+ return $products;
250
+ }
251
+
252
+ /**
253
+ * Allow show button add to cart
254
+ *
255
+ * @param boolean $allow Settings flag.
256
+ * @param array $wlproduct Wishlist Product.
257
+ * @param WC_Product $product Product.
258
+ *
259
+ * @return boolean
260
+ */
261
+ function product_allow_add_to_cart( $allow, $wlproduct, $product ) {
262
+ if ( ! $allow ) {
263
+ return false;
264
+ }
265
+
266
+ return ( $product->is_purchasable() || 'external' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) && ( $product->is_in_stock() || $product->backorders_allowed() );
267
+ }
268
+
269
+ /**
270
+ * Basic validation actions
271
+ *
272
+ * @return boolean
273
+ */
274
+ function wishlist_action() {
275
+
276
+ $wishlist_page_id = apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true );
277
+
278
+ if ( is_page( $wishlist_page_id )
279
+ || ( is_home() && 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) === $wishlist_page_id )
280
+ || ( is_shop() && wc_get_page_id( 'shop' ) === $wishlist_page_id ) ) {
281
+ $wishlist = $this->get_current_wishlist();
282
+ if ( empty( $wishlist ) ) {
283
+ return false;
284
+ }
285
+
286
+ if ( version_compare( WC_VERSION, '3.2.0', '<' ) ) {
287
+ if ( ! defined( 'DONOTCACHEPAGE' ) ) {
288
+ define( 'DONOTCACHEPAGE', true );
289
+ }
290
+ if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
291
+ define( 'DONOTCACHEOBJECT', true );
292
+ }
293
+ if ( ! defined( 'DONOTCACHEDB' ) ) {
294
+ define( 'DONOTCACHEDB', true );
295
+ }
296
+ } else {
297
+ WC_Cache_Helper::set_nocache_constants( true );
298
+ nocache_headers();
299
+ }
300
+
301
+ $is_owner = is_user_logged_in() ? ( get_current_user_id() === $wishlist['author'] ) : $wishlist['is_owner'];
302
+ $nonce = filter_input( INPUT_POST, 'wishlist_nonce' );
303
+ if ( $nonce && wp_verify_nonce( $nonce, 'tinvwl_wishlist_owner' ) && $is_owner ) {
304
+ do_action( 'tinvwl_before_action_owner', $wishlist );
305
+ $this->wishlist_actions( $wishlist, true );
306
+ do_action( 'tinvwl_after_action_owner', $wishlist );
307
+ }
308
+ if ( $nonce && wp_verify_nonce( $nonce, 'tinvwl_wishlist_user' ) && ! $is_owner ) {
309
+ do_action( 'tinvwl_before_action_user', $wishlist );
310
+ $this->wishlist_actions( $wishlist, false );
311
+ do_action( 'tinvwl_after_action_user', $wishlist );
312
+ }
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Basic actions
318
+ *
319
+ * @param array $wishlist Wishlist object.
320
+ * @param boolean $owner Is Owner.
321
+ *
322
+ * @return boolean
323
+ */
324
+ function wishlist_actions( $wishlist, $owner = false ) {
325
+ $post = filter_input_array( INPUT_POST, array(
326
+ 'wishlist_pr' => array(
327
+ 'filter' => FILTER_VALIDATE_INT,
328
+ 'flags' => FILTER_FORCE_ARRAY,
329
+ ),
330
+ 'wishlist_qty' => array(
331
+ 'filter' => FILTER_VALIDATE_INT,
332
+ 'flags' => FILTER_FORCE_ARRAY,
333
+ 'options' => array( 'min_range' => 0, 'default' => 1 ),
334
+ ),
335
+ 'tinvwl-add-to-cart' => FILTER_VALIDATE_INT,
336
+ 'tinvwl-remove' => FILTER_VALIDATE_INT,
337
+ 'tinvwl-action' => FILTER_SANITIZE_STRING,
338
+ ) );
339
+
340
+ if ( ! empty( $post['tinvwl-add-to-cart'] ) ) {
341
+ $product = $post['tinvwl-add-to-cart'];
342
+ $quantity = array_key_exists( $product, (array) $post['wishlist_qty'] ) ? $post['wishlist_qty'][ $product ] : 1;
343
+
344
+ return $this->button_addtocart( $wishlist, $product, $quantity, $owner );
345
+ }
346
+ if ( ! empty( $post['tinvwl-remove'] ) ) {
347
+ if ( ! $wishlist['is_owner'] ) {
348
+ return false;
349
+ }
350
+ $product = $post['tinvwl-remove'];
351
+ if ( 0 === $wishlist['ID'] ) {
352
+ $wlp = TInvWL_Product_Local::instance();
353
+ } else {
354
+ $wlp = new TInvWL_Product( $wishlist );
355
+ }
356
+ if ( empty( $wlp ) ) {
357
+ return false;
358
+ }
359
+ $product_data = $wlp->get_wishlist( array( 'ID' => $product ) );
360
+ $product_data = array_shift( $product_data );
361
+ if ( empty( $product_data ) ) {
362
+ return false;
363
+ }
364
+ $title = sprintf( __( '&ldquo;%s&rdquo;', 'ti-woocommerce-wishlist' ), $product_data['data']->get_title() );
365
+ if ( $wlp->remove( $product_data ) ) {
366
+ add_action( 'tinvwl_before_wishlist', array(
367
+ 'TInvWL_Public_Wishlist_View',
368
+ 'check_cart_hash'
369
+ ), 99, 1 );
370
+ add_action( 'woocommerce_set_cart_cookies', array(
371
+ 'TInvWL_Public_Wishlist_View',
372
+ 'reset_cart_hash'
373
+ ), 99, 1 );
374
+ wc_add_notice( sprintf( __( '%s has been removed from wishlist.', 'ti-woocommerce-wishlist' ), $title ) );
375
+ } else {
376
+ wc_add_notice( sprintf( __( '%s has not been removed from wishlist.', 'ti-woocommerce-wishlist' ), $title ), 'error' );
377
+ }
378
+
379
+ return true;
380
+ }
381
+ do_action( 'tinvwl_action_' . $post['tinvwl-action'], $wishlist, $post['wishlist_pr'], $post['wishlist_qty'], $owner ); // @codingStandardsIgnoreLine WordPress.NamingConventions.ValidHookName.UseUnderscores
382
+ }
383
+
384
+ /**
385
+ * Check cart hash to trigger WC fragments refresh on wishlist update.
386
+ *
387
+ * @param $wishlist
388
+ */
389
+ public static function check_cart_hash( $wishlist ) {
390
+ wp_add_inline_script( 'woocommerce', "
391
+ jQuery(document).ready(function($){
392
+ if ( typeof wc_cart_fragments_params === 'undefined' ) {
393
+ return false;
394
+ }
395
+
396
+ var cart_hash_key = wc_cart_fragments_params.cart_hash_key,
397
+ cart_hash = sessionStorage.getItem( cart_hash_key );
398
+
399
+ if ( cart_hash === null || cart_hash === undefined || cart_hash === '' ) {
400
+ sessionStorage.setItem( cart_hash_key, 'empty' );
401
+ }
402
+ });
403
+ " );
404
+ }
405
+
406
+ /**
407
+ * Reset cart hash to trigger WC fragments refresh on wishlist update.
408
+ *
409
+ * @param bool $set
410
+ */
411
+ public static function reset_cart_hash( $set ) {
412
+ wc_setcookie( 'woocommerce_cart_hash', 'reset', time() - HOUR_IN_SECONDS );
413
+ }
414
+
415
+ /**
416
+ * Apply action add to cart
417
+ *
418
+ * @param array $wishlist Wishlist object.
419
+ * @param integer $id Product id in wishlist.
420
+ * @param integer $quantity Product quantity.
421
+ * @param boolean $owner Is Owner.
422
+ *
423
+ * @return boolean
424
+ */
425
+ function button_addtocart( $wishlist, $id, $quantity = 1, $owner = false ) {
426
+ $id = absint( $id );
427
+ $quantity = absint( $quantity );
428
+ if ( empty( $id ) || empty( $quantity ) ) {
429
+ return false;
430
+ }
431
+
432
+ $wlp = null;
433
+ if ( 0 === $wishlist['ID'] ) {
434
+ $wlp = TInvWL_Product_Local::instance();
435
+ } else {
436
+ $wlp = new TInvWL_Product( $wishlist );
437
+ }
438
+ if ( empty( $wlp ) ) {
439
+ return false;
440
+ }
441
+
442
+ $_product = $wlp->get_wishlist( array( 'ID' => $id ) );
443
+ $_product = array_shift( $_product );
444
+ if ( empty( $_product ) || empty( $_product['data'] ) ) {
445
+ return false;
446
+ }
447
+
448
+ global $product;
449
+ // store global product data.
450
+ $_product_tmp = $product;
451
+ // override global product data.
452
+ $product = $_product['data'];
453
+
454
+ add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
455
+ $redirect_url = $_product['data']->add_to_cart_url();
456
+ remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
457
+
458
+ // restore global product data.
459
+ $product = $_product_tmp;
460
+
461
+ $quantity = apply_filters( 'tinvwl_product_add_to_cart_quantity', $quantity, $_product['data'] );
462
+
463
+ if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $_product['data'], $redirect_url, $_product ) ) {
464
+ wp_redirect( apply_filters( 'tinvwl_product_add_to_cart_redirect_url', $redirect_url, $_product['data'], $_product ) ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.wp_redirect
465
+ exit;
466
+ } elseif ( apply_filters( 'tinvwl_allow_addtocart_in_wishlist', true, $wishlist, $owner ) ) {
467
+ $add = TInvWL_Public_Cart::add( $wishlist, $id, $quantity );
468
+ if ( $add ) {
469
+ wc_add_to_cart_message( $add, true );
470
+
471
+ if ( tinv_get_option( 'processing', 'redirect_checkout' ) ) {
472
+ wp_safe_redirect( wc_get_checkout_url() );
473
+ exit;
474
+ }
475
+
476
+ if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
477
+ wp_safe_redirect( wc_get_cart_url() );
478
+ exit;
479
+ }
480
+
481
+ return true;
482
+ }
483
+ }
484
+
485
+ return false;
486
+ }
487
+
488
+ /**
489
+ * Output page
490
+ *
491
+ * @param array $atts Array parameter for shortcode.
492
+ *
493
+ * @return mixed
494
+ */
495
+ function htmloutput( $atts ) {
496
+ $wishlist = $this->get_current_wishlist();
497
+
498
+ if ( empty( $wishlist ) ) {
499
+ $id = get_query_var( 'tinvwlID', null );
500
+ if ( empty( $id ) && ( is_user_logged_in() || ! tinv_get_option( 'general', 'require_login' ) ) ) {
501
+ return $this->wishlist_empty( array(), array(
502
+ 'ID' => '',
503
+ 'author' => get_current_user_id(),
504
+ 'title' => apply_filters( 'tinvwl-general-default_title', tinv_get_option( 'general', 'default_title' ) ),
505
+ 'status' => 'private',
506
+ 'type' => 'default',
507
+ 'share_key' => '',
508
+ ) );
509
+ }
510
+
511
+ return $this->wishlist_null();
512
+ }
513
+
514
+ if ( 'private' === $wishlist['status'] && ! $wishlist['is_owner'] ) {
515
+ return $this->wishlist_null();
516
+ }
517
+ if ( 'default' !== $wishlist['type'] && ! tinv_get_option( 'general', 'multi' ) ) {
518
+ if ( $wishlist['is_owner'] ) {
519
+ printf( '<p><a href="%s">%s</p><script type="text/javascript">window.location.href="%s"</script>', esc_attr( tinv_url_wishlist_default() ), esc_html__( 'Return to Wishlist', 'ti-woocommerce-wishlist' ), esc_attr( tinv_url_wishlist_default() ) );
520
+
521
+ return false;
522
+ } else {
523
+ return $this->wishlist_null();
524
+ }
525
+ }
526
+
527
+ $products = $this->get_current_products( $wishlist, true, absint( $atts['lists_per_page'] ) );
528
+
529
+ $this->lists_per_page = $atts['lists_per_page'];
530
+
531
+ $wla = new TInvWL_Analytics( $wishlist, $this->_name );
532
+ $wla->wishlist_view( 0, $wishlist['is_owner'] );
533
+
534
+ foreach ( $products as $key => $product ) {
535
+ if ( ! isset( $product['data'] ) ) {
536
+ unset( $products[ $key ] );
537
+ }
538
+ }
539
+
540
+ if ( empty( $products ) ) {
541
+ return $this->wishlist_empty( $products, $wishlist );
542
+ }
543
+
544
+ $wishlist_table_row = tinv_get_option( 'product_table' );
545
+ $wishlist_table_row['text_add_to_cart'] = apply_filters( 'tinvwl-product_table-text_add_to_cart', tinv_get_option( 'product_table', 'text_add_to_cart' ) );
546
+
547
+ $data = array(
548
+ 'products' => $products,
549
+ 'wishlist' => $wishlist,
550
+ 'wishlist_table' => tinv_get_option( 'table' ),
551
+ 'wishlist_table_row' => $wishlist_table_row,
552
+ );
553
+
554
+ if ( $wishlist['is_owner'] ) {
555
+ tinv_wishlist_template( 'ti-wishlist.php', $data );
556
+ } else {
557
+ if ( class_exists( 'WC_Catalog_Visibility_Options' ) ) {
558
+ global $wc_cvo;
559
+ if ( 'secured' === $wc_cvo->setting( 'wc_cvo_atc' && isset( $data['wishlist_table_row']['add_to_cart'] ) ) ) {
560
+ unset( $data['wishlist_table_row']['add_to_cart'] );
561
+ }
562
+ if ( 'secured' === $wc_cvo->setting( 'wc_cvo_prices' && isset( $data['wishlist_table_row']['colm_price'] ) ) ) {
563
+ unset( $data['wishlist_table_row']['colm_price'] );
564
+ }
565
+ }
566
+
567
+ tinv_wishlist_template( 'ti-wishlist-user.php', $data );
568
+ }
569
+ }
570
+
571
+ /**
572
+ * Not Found Wishlist
573
+ *
574
+ * @param array $wishlist Wishlist object.
575
+ */
576
+ function wishlist_null( $wishlist = array() ) {
577
+ $data = array(
578
+ 'wishlist' => $wishlist,
579
+ );
580
+ tinv_wishlist_template( 'ti-wishlist-null.php', $data );
581
+ }
582
+
583
+ /**
584
+ * Empty Wishlist
585
+ *
586
+ * @param array $products Products wishlist.
587
+ * @param array $wishlist Wishlist object.
588
+ */
589
+ function wishlist_empty( $products = array(), $wishlist = array() ) {
590
+ $data = array(
591
+ 'products' => $products,
592
+ 'wishlist' => $wishlist,
593
+ 'wishlist_table' => tinv_get_option( 'table' ),
594
+ );
595
+ tinv_wishlist_template( 'ti-wishlist-empty.php', $data );
596
+ }
597
+
598
+ /**
599
+ * Header Wishlist
600
+ *
601
+ * @param array $wishlist Wishlist object.
602
+ */
603
+ function wishlist_header( $wishlist ) {
604
+
605
+ $data = array(
606
+ 'wishlist' => $wishlist,
607
+ );
608
+ tinv_wishlist_template( 'ti-wishlist-header.php', $data );
609
+ }
610
+
611
+ /**
612
+ * Prev page button
613
+ */
614
+ function page_prev() {
615
+ $paged = get_query_var( 'wl_paged', 1 );
616
+ $paged = 1 < $paged ? $paged - 1 : 0;
617
+ $this->page( $paged, sprintf( '<i class="ftinvwl ftinvwl-chevron-left"></i><span>%s</span>', __( 'Previous Page', 'ti-woocommerce-wishlist' ) ), array( 'class' => 'button tinv-prev' ) );
618
+ }
619
+
620
+ /**
621
+ * Pages
622
+ */
623
+ function pages() {
624
+
625
+ $paged = get_query_var( 'wl_paged', 1 );
626
+ if ( 1 === (int) $paged ) {
627
+ echo '<span></span>';
628
+ }
629
+
630
+ echo '<span>' . $paged . '/' . $this->pages . '</span>';
631
+
632
+ if ( (int) $this->pages === (int) $paged ) {
633
+ echo '<span></span>';
634
+ }
635
+ }
636
+
637
+ /**
638
+ * Next page button
639
+ */
640
+ function page_next() {
641
+ $paged = get_query_var( 'wl_paged', 1 );
642
+ $paged = 1 < $paged ? $paged + 1 : 2;
643
+ $this->page( $paged, sprintf( '<span>%s</span><i class="ftinvwl ftinvwl-chevron-right"></i>', __( 'Next Page', 'ti-woocommerce-wishlist' ) ), array( 'class' => 'button tinv-next' ) );
644
+ }
645
+
646
+ /**
647
+ * Page button
648
+ *
649
+ * @param integer $paged Index page.
650
+ * @param string $text Text button.
651
+ * @param style $style Style attribute.
652
+ */
653
+ function page( $paged, $text, $style = array() ) {
654
+ $paged = absint( $paged );
655
+ $wishlist = tinv_wishlist_get();
656
+ $link = tinv_url_wishlist( $wishlist['share_key'], $paged, true );
657
+ if ( is_array( $style ) ) {
658
+ $style = TInvWL_Form::__atrtostr( $style );
659
+ }
660
+ printf( '<a href="%s" %s>%s</a>', esc_url( $link ), $style, $text ); // WPCS: xss ok.
661
+ }
662
+
663
+ /**
664
+ * Shortcode basic function
665
+ *
666
+ * @param array $atts Array parameter from shortcode.
667
+ *
668
+ * @return string
669
+ */
670
+ function shortcode( $atts = array() ) {
671
+ $default = array(
672
+ 'lists_per_page' => 10,
673
+ );
674
+ $atts = shortcode_atts( $default, $atts );
675
+
676
+ ob_start();
677
+ $this->htmloutput( $atts );
678
+
679
+ return ob_get_clean();
680
+ }
681
+
682
+ /**
683
+ * Get per page items for buttons
684
+ */
685
+ function get_per_page() {
686
+ if ( ! empty( $this->lists_per_page ) ) {
687
+ echo TInvWL_Form::_text( array( // WPCS: xss ok.
688
+ 'type' => 'hidden',
689
+ 'name' => 'lists_per_page',
690
+ ), $this->lists_per_page );
691
+ }
692
+ }
693
+ }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === WooCommerce Wishlist Plugin ===
2
  Contributors: templateinvaders
3
  Donate link: https://templateinvaders.com/product/ti-woocommerce-wishlist-wordpress-plugin/?utm_source=wordpressorg&utm_content=donate
4
  Tags: wishlist, woocommerce, woocommerce wishlist, e-commerce, ecommerce
5
  Requires at least: 4.5
6
  Tested up to: 5.1
7
- Stable tag: 1.10.1
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -16,7 +16,7 @@ Add Wishlist functionality to your store for free.
16
  = Increase Sales and Conversions =
17
  WooCommerce Wishlist is a simple but powerful tool that can help you to convert your site visitors into loyal customers. There are many situations when customers can’t buy a product at this time or simply don’t want. Possibility to save products for later encourages users to return to your site and after all, make a purchase. Adding products to Wishlist is easy and convenient so it may also force your customers to buy even more products than they planned. Users can share their wishlist, for example, to help their friends choose a gift for upcoming holiday and so on. By sharing their Wishlists, they are bringing you, new potential customers. All in all this increasing amount of your site visitors, conversion and as a result sales.
18
 
19
- 🔗 [Live Preview](https://woocommercewishlist.com/preview/?utm_source=wordpressorg&utm_content=preview)
20
 
21
  🔗 [View documentation](https://templateinvaders.com/documentation/ti-woocommerce-wishlist-free/?utm_source=wordpressorg&utm_content=documentation)
22
 
@@ -140,6 +140,14 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
140
 
141
 
142
  == Changelog ==
 
 
 
 
 
 
 
 
143
  = 1.10.1 =
144
  *Release Date - 14 April 2019*
145
 
1
+ === TI WooCommerce Wishlist Plugin ===
2
  Contributors: templateinvaders
3
  Donate link: https://templateinvaders.com/product/ti-woocommerce-wishlist-wordpress-plugin/?utm_source=wordpressorg&utm_content=donate
4
  Tags: wishlist, woocommerce, woocommerce wishlist, e-commerce, ecommerce
5
  Requires at least: 4.5
6
  Tested up to: 5.1
7
+ Stable tag: 1.11.0
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
16
  = Increase Sales and Conversions =
17
  WooCommerce Wishlist is a simple but powerful tool that can help you to convert your site visitors into loyal customers. There are many situations when customers can’t buy a product at this time or simply don’t want. Possibility to save products for later encourages users to return to your site and after all, make a purchase. Adding products to Wishlist is easy and convenient so it may also force your customers to buy even more products than they planned. Users can share their wishlist, for example, to help their friends choose a gift for upcoming holiday and so on. By sharing their Wishlists, they are bringing you, new potential customers. All in all this increasing amount of your site visitors, conversion and as a result sales.
18
 
19
+ 🔗 [Live Preview](https://templateinvaders.com/product/ti-woocommerce-wishlist-wordpress-plugin/preview/?utm_source=wordpressorg&utm_content=preview)
20
 
21
  🔗 [View documentation](https://templateinvaders.com/documentation/ti-woocommerce-wishlist-free/?utm_source=wordpressorg&utm_content=documentation)
22
 
140
 
141
 
142
  == Changelog ==
143
+ = 1.11.0 =
144
+ *Release Date - 18 April 2019*
145
+
146
+ * WooCommerce 3.6.x support
147
+ * Added integration with Improved Product Options for WooCommerce plugin
148
+ * Added custom hook for [myCRED](https://wordpress.org/plugins/mycred/) plugin
149
+ * Minor PHP fixes and improvements
150
+
151
  = 1.10.1 =
152
  *Release Date - 14 April 2019*
153
 
templates/ti-wishlist-user.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * The Template for displaying wishlist if a current user not an owner.
4
  *
5
- * @version 1.10.0
6
  * @package TInvWishlist\Template
7
  */
8
 
@@ -52,8 +52,20 @@ wp_enqueue_script( 'tinvwl' );
52
  <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
53
 
54
  <?php
 
 
 
 
 
 
 
55
  foreach ( $products as $wl_product ) {
 
 
56
  $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
 
 
 
57
  unset( $wl_product['data'] );
58
  if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
59
  $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
@@ -143,6 +155,10 @@ wp_enqueue_script( 'tinvwl' );
143
  do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
144
  } // End if().
145
  } // End foreach().
 
 
 
 
146
  ?>
147
  <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
148
  </tbody>
2
  /**
3
  * The Template for displaying wishlist if a current user not an owner.
4
  *
5
+ * @version 1.11.0
6
  * @package TInvWishlist\Template
7
  */
8
 
52
  <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
53
 
54
  <?php
55
+
56
+ global $product, $post;
57
+ // store global product data.
58
+ $_product_tmp = $product;
59
+ // store global post data.
60
+ $_post_tmp = $post;
61
+
62
  foreach ( $products as $wl_product ) {
63
+
64
+ // override global product data.
65
  $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
66
+ // override global post data.
67
+ $post = get_post( $product->get_id() );
68
+
69
  unset( $wl_product['data'] );
70
  if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
71
  $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
155
  do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
156
  } // End if().
157
  } // End foreach().
158
+ // restore global product data.
159
+ $product = $_product_tmp;
160
+ // restore global post data.
161
+ $post = $_post_tmp;
162
  ?>
163
  <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
164
  </tbody>
templates/ti-wishlist.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * The Template for displaying wishlist if a current user is owner.
4
  *
5
- * @version 1.10.0
6
  * @package TInvWishlist\Template
7
  */
8
 
@@ -53,8 +53,20 @@ wp_enqueue_script( 'tinvwl' );
53
  <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
54
 
55
  <?php
 
 
 
 
 
 
 
56
  foreach ( $products as $wl_product ) {
 
 
57
  $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
 
 
 
58
  unset( $wl_product['data'] );
59
  if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
60
  $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
@@ -151,6 +163,10 @@ wp_enqueue_script( 'tinvwl' );
151
  do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
152
  } // End if().
153
  } // End foreach().
 
 
 
 
154
  ?>
155
  <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
156
  </tbody>
2
  /**
3
  * The Template for displaying wishlist if a current user is owner.
4
  *
5
+ * @version 1.11.0
6
  * @package TInvWishlist\Template
7
  */
8
 
53
  <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
54
 
55
  <?php
56
+
57
+ global $product, $post;
58
+ // store global product data.
59
+ $_product_tmp = $product;
60
+ // store global post data.
61
+ $_post_tmp = $post;
62
+
63
  foreach ( $products as $wl_product ) {
64
+
65
+ // override global product data.
66
  $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
67
+ // override global post data.
68
+ $post = get_post( $product->get_id() );
69
+
70
  unset( $wl_product['data'] );
71
  if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
72
  $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
163
  do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
164
  } // End if().
165
  } // End foreach().
166
+ // restore global product data.
167
+ $product = $_product_tmp;
168
+ // restore global post data.
169
+ $post = $_post_tmp;
170
  ?>
171
  <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
172
  </tbody>
ti-woocommerce-wishlist.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  /**
3
- * WooCommerce Wishlist Plugin.
4
- * Plugin Name: WooCommerce Wishlist Plugin
5
  * Plugin URI: https://wordpress.org/plugins/ti-woocommerce-wishlist/
6
  * Description: Wishlist functionality for your WooCommerce store.
7
- * Version: 1.10.1
8
  * Requires at least: 4.5
9
  * Tested up to: 5.1
10
  * WC requires at least: 2.6
11
- * WC tested up to: 3.5
12
  * Author: TemplateInvaders
13
  * Author URI: https://templateinvaders.com/
14
  * License: GPL-2.0+
@@ -41,7 +41,7 @@ if ( ! defined( 'TINVWL_DOMAIN' ) ) {
41
  }
42
 
43
  if ( ! defined( 'TINVWL_FVERSION' ) ) {
44
- define( 'TINVWL_FVERSION', '1.10.1' );
45
  }
46
 
47
  if ( ! defined( 'TINVWL_LOAD_FREE' ) ) {
1
  <?php
2
  /**
3
+ * TI WooCommerce Wishlist Plugin.
4
+ * Plugin Name: TI WooCommerce Wishlist Plugin
5
  * Plugin URI: https://wordpress.org/plugins/ti-woocommerce-wishlist/
6
  * Description: Wishlist functionality for your WooCommerce store.
7
+ * Version: 1.11.0
8
  * Requires at least: 4.5
9
  * Tested up to: 5.1
10
  * WC requires at least: 2.6
11
+ * WC tested up to: 3.6.1
12
  * Author: TemplateInvaders
13
  * Author URI: https://templateinvaders.com/
14
  * License: GPL-2.0+
41
  }
42
 
43
  if ( ! defined( 'TINVWL_FVERSION' ) ) {
44
+ define( 'TINVWL_FVERSION', '1.11.0' );
45
  }
46
 
47
  if ( ! defined( 'TINVWL_LOAD_FREE' ) ) {
tinv-wishlists-function-integration.php CHANGED
@@ -2279,3 +2279,343 @@ if ( ! function_exists( 'tinv_wishlist_item_meta_woocommerce_custom_product_addo
2279
 
2280
  add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_item_meta_woocommerce_custom_product_addons', 10, 3 );
2281
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2279
 
2280
  add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_item_meta_woocommerce_custom_product_addons', 10, 3 );
2281
  }
2282
+
2283
+
2284
+ if ( ! function_exists( 'tinv_wishlist_meta_support_ivpa' ) ) {
2285
+
2286
+ /**
2287
+ * Set description for meta Improved Product Options for WooCommerce
2288
+ *
2289
+ * @param array $meta Meta array.
2290
+ *
2291
+ * @return array
2292
+ */
2293
+ function tinv_wishlist_meta_support_ivpa( $meta ) {
2294
+
2295
+ if ( class_exists( 'WC_Improved_Variable_Product_Attributes_Init' ) ) {
2296
+
2297
+ $curr_customizations = WC_Improved_Variable_Product_Attributes::get_custom();
2298
+
2299
+ foreach ( $meta as $k => $v ) {
2300
+ $prefix = 'ivpac_';
2301
+ $k_ivpac = ( 0 === strpos( $k, $prefix ) ) ? substr( $k, strlen( $prefix ) ) : $k;
2302
+ if ( isset( $curr_customizations['ivpa_attr'][ $k_ivpac ] ) ) {
2303
+ $v = is_array( $v['display'] ) ? implode( ', ', $v['display'] ) : $v['display'];
2304
+ if ( $curr_customizations['ivpa_attr'][ $k_ivpac ] == 'ivpa_custom' ) {
2305
+ $meta[ $k ] = array(
2306
+ 'key' => $curr_customizations['ivpa_title'][ $k_ivpac ],
2307
+ 'display' => $v,
2308
+ );
2309
+ } else {
2310
+ $meta[ $k ] = array(
2311
+ 'key' => wc_attribute_label( $curr_customizations['ivpa_attr'][ $k_ivpac ] ),
2312
+ 'display' => $v,
2313
+ );
2314
+ }
2315
+ }
2316
+ }
2317
+ }
2318
+
2319
+ return $meta;
2320
+ }
2321
+
2322
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_meta_support_ivpa' );
2323
+ } // End if().
2324
+
2325
+
2326
+ // myCred hooks
2327
+ if ( defined( 'myCRED_VERSION' ) ) {
2328
+
2329
+ /**
2330
+ * Register Hook
2331
+ */
2332
+ add_filter( 'mycred_setup_hooks', 'mycred_register_ti_woocommerce_wishlist_hook', 100 );
2333
+ function mycred_register_ti_woocommerce_wishlist_hook( $installed ) {
2334
+
2335
+ $installed['tinvwl'] = array(
2336
+ 'title' => __( 'WooCommerce Wishlist', 'ti-woocommerce-wishlist' ),
2337
+ 'description' => __( 'Awards %_plural% for users adding products to their wishlist and purchased products from their wishlist.', 'ti-woocommerce-wishlist' ),
2338
+ 'callback' => array( 'myCRED_Hook_TinvWL' )
2339
+ );
2340
+
2341
+ return $installed;
2342
+
2343
+ }
2344
+
2345
+ /**
2346
+ * TI WooCommerce Wihslist Hook
2347
+ */
2348
+ add_action( 'mycred_load_hooks', 'mycred_load_ti_woocommerce_wishlist_hook', 100 );
2349
+ function mycred_load_ti_woocommerce_wishlist_hook() {
2350
+
2351
+ // If the hook has been replaced or if plugin is not installed, exit now
2352
+ if ( class_exists( 'myCRED_Hook_TinvWL' ) ) {
2353
+ return;
2354
+ }
2355
+
2356
+ class myCRED_Hook_TinvWL extends myCRED_Hook {
2357
+
2358
+ /**
2359
+ * Construct
2360
+ */
2361
+ public function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
2362
+
2363
+ parent::__construct( array(
2364
+ 'id' => 'tinvwl',
2365
+ 'defaults' => array(
2366
+ 'tinvwl_added' => array(
2367
+ 'creds' => 1,
2368
+ 'log' => '%plural% for adding a product to a wishlist',
2369
+ 'limit' => '0/x',
2370
+ ),
2371
+ 'tinvwl_purchased' => array(
2372
+ 'creds' => 1,
2373
+ 'log' => '%plural% for purchasing a product from a wishlist',
2374
+ 'limit' => '0/x'
2375
+ ),
2376
+ )
2377
+ ), $hook_prefs, $type );
2378
+
2379
+ }
2380
+
2381
+ /**
2382
+ * Run
2383
+ */
2384
+ public function run() {
2385
+ add_action( 'tinvwl_product_added', array( $this, 'added' ) );
2386
+ add_action( 'tinvwl_product_purchased', array( $this, 'purchased' ), 10, 3 );
2387
+ }
2388
+
2389
+ /**
2390
+ * Added product to a wishlist
2391
+ *
2392
+ * @param array $data product data including author and wishlist IDs.
2393
+ */
2394
+ public function added( $data ) {
2395
+
2396
+ // Must be logged in
2397
+ if ( ! is_user_logged_in() ) {
2398
+ return;
2399
+ }
2400
+
2401
+ $user_id = get_current_user_id();
2402
+
2403
+ // Award the user adding to wishlist
2404
+ if ( $this->prefs['tinvwl_added']['creds'] != 0 && ! $this->core->exclude_user( $user_id ) ) {
2405
+
2406
+ // Limit
2407
+ if ( ! $this->over_hook_limit( 'tinvwl_added', 'added_to_wishlist', $user_id ) ) {
2408
+
2409
+ // Make sure this is unique event
2410
+ if ( ! $this->core->has_entry( 'added_to_wishlist', $data['product_id'], $user_id ) ) {
2411
+
2412
+ // Execute
2413
+ $this->core->add_creds(
2414
+ 'added_to_wishlist',
2415
+ $user_id,
2416
+ $this->prefs['tinvwl_added']['creds'],
2417
+ $this->prefs['tinvwl_added']['log'],
2418
+ $data['product_id'],
2419
+ array( 'ref_type' => 'post' ),
2420
+ $this->mycred_type
2421
+ );
2422
+
2423
+ }
2424
+
2425
+ }
2426
+
2427
+ }
2428
+ }
2429
+
2430
+ /**
2431
+ * Purchased product from a wishlist
2432
+ *
2433
+ * @param WC_order $order Order object.
2434
+ * @param WC_Order_Item_Product $item Order item product object.
2435
+ * @param array $wishlist A wishlist data where product added from.
2436
+ */
2437
+ public function purchased( $order, $item, $wishlist ) {
2438
+
2439
+ // Must be logged in
2440
+ if ( ! is_user_logged_in() ) {
2441
+ return;
2442
+ }
2443
+
2444
+ $user_id = get_current_user_id();
2445
+
2446
+ // Award the user adding to wishlist
2447
+ if ( $this->prefs['tinvwl_purchased']['creds'] != 0 && ! $this->core->exclude_user( $user_id ) ) {
2448
+
2449
+ // Limit
2450
+ if ( ! $this->over_hook_limit( 'tinvwl_purchased', 'purchased_from_wishlist', $user_id ) ) {
2451
+
2452
+ // Make sure this is unique event
2453
+ if ( ! $this->core->has_entry( 'purchased_from_wishlist', $item->get_id(), $user_id ) ) {
2454
+
2455
+ // Execute
2456
+ $this->core->add_creds(
2457
+ 'purchased_from_wishlist',
2458
+ $user_id,
2459
+ $this->prefs['tinvwl_purchased']['creds'],
2460
+ $this->prefs['tinvwl_purchased']['log'],
2461
+ $item->get_id(),
2462
+ array( 'ref_type' => 'post' ),
2463
+ $this->mycred_type
2464
+ );
2465
+
2466
+ }
2467
+
2468
+ }
2469
+
2470
+ }
2471
+
2472
+
2473
+ }
2474
+
2475
+ /**
2476
+ * Preferences
2477
+ */
2478
+ public function preferences() {
2479
+
2480
+ $prefs = $this->prefs;
2481
+
2482
+ ?>
2483
+ <div class="hook-instance">
2484
+ <h3><?php _e( 'Adding Product to Wishlist', 'ti-woocommerce-wishlist' ); ?></h3>
2485
+ <div class="row">
2486
+ <div class="col-lg-2 col-md-6 col-sm-6 col-xs-12">
2487
+ <div class="form-group">
2488
+ <label
2489
+ for="<?php echo $this->field_id( array( 'tinvwl_added' => 'creds' ) ); ?>"><?php _e( 'Points', 'ti-woocommerce-wishlist' ); ?></label>
2490
+ <input type="text"
2491
+ name="<?php echo $this->field_name( array( 'tinvwl_added' => 'creds' ) ); ?>"
2492
+ id="<?php echo $this->field_id( array( 'tinvwl_added' => 'creds' ) ); ?>"
2493
+ value="<?php echo $this->core->number( $prefs['tinvwl_added']['creds'] ); ?>"
2494
+ class="form-control"/>
2495
+ </div>
2496
+ </div>
2497
+ <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
2498
+ <div class="form-group">
2499
+ <label for="<?php echo $this->field_id( array(
2500
+ 'tinvwl_added',
2501
+ 'limit'
2502
+ ) ); ?>"><?php _e( 'Limit', 'ti-woocommerce-wishlist' ); ?></label>
2503
+ <?php echo $this->hook_limit_setting( $this->field_name( array(
2504
+ 'tinvwl_added',
2505
+ 'limit'
2506
+ ) ), $this->field_id( array(
2507
+ 'tinvwl_added',
2508
+ 'limit'
2509
+ ) ), $prefs['tinvwl_added']['limit'] ); ?>
2510
+ </div>
2511
+ </div>
2512
+ <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
2513
+ <div class="form-group">
2514
+ <label
2515
+ for="<?php echo $this->field_id( array( 'tinvwl_added' => 'log' ) ); ?>"><?php _e( 'Log Template', 'ti-woocommerce-wishlist' ); ?></label>
2516
+ <input type="text"
2517
+ name="<?php echo $this->field_name( array( 'tinvwl_added' => 'log' ) ); ?>"
2518
+ id="<?php echo $this->field_id( array( 'tinvwl_added' => 'log' ) ); ?>"
2519
+ placeholder="<?php _e( 'required', 'ti-woocommerce-wishlist' ); ?>"
2520
+ value="<?php echo esc_attr( $prefs['tinvwl_added']['log'] ); ?>"
2521
+ class="form-control"/>
2522
+ <span class="description"><?php echo $this->available_template_tags( array(
2523
+ 'general',
2524
+ 'post'
2525
+ ) ); ?></span>
2526
+ </div>
2527
+ </div>
2528
+ </div>
2529
+ <h3><?php _e( 'Purchasing Product from Wishlist', 'ti-woocommerce-wishlist' ); ?></h3>
2530
+ <div class="row">
2531
+ <div class="col-lg-2 col-md-6 col-sm-6 col-xs-12">
2532
+ <div class="form-group">
2533
+ <label
2534
+ for="<?php echo $this->field_id( array( 'tinvwl_purchased' => 'creds' ) ); ?>"><?php _e( 'Points', 'ti-woocommerce-wishlist' ); ?></label>
2535
+ <input type="text"
2536
+ name="<?php echo $this->field_name( array( 'tinvwl_purchased' => 'creds' ) ); ?>"
2537
+ id="<?php echo $this->field_id( array( 'tinvwl_purchased' => 'creds' ) ); ?>"
2538
+ value="<?php echo $this->core->number( $prefs['tinvwl_purchased']['creds'] ); ?>"
2539
+ class="form-control"/>
2540
+ </div>
2541
+ </div>
2542
+ <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
2543
+ <div class="form-group">
2544
+ <label for="<?php echo $this->field_id( array(
2545
+ 'tinvwl_purchased',
2546
+ 'limit'
2547
+ ) ); ?>"><?php _e( 'Limit', 'ti-woocommerce-wishlist' ); ?></label>
2548
+ <?php echo $this->hook_limit_setting( $this->field_name( array(
2549
+ 'tinvwl_purchased',
2550
+ 'limit'
2551
+ ) ), $this->field_id( array(
2552
+ 'tinvwl_purchased',
2553
+ 'limit'
2554
+ ) ), $prefs['tinvwl_purchased']['limit'] ); ?>
2555
+ </div>
2556
+ </div>
2557
+ <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
2558
+ <div class="form-group">
2559
+ <label
2560
+ for="<?php echo $this->field_id( array( 'tinvwl_purchased' => 'log' ) ); ?>"><?php _e( 'Log Template', 'ti-woocommerce-wishlist' ); ?></label>
2561
+ <input type="text"
2562
+ name="<?php echo $this->field_name( array( 'tinvwl_purchased' => 'log' ) ); ?>"
2563
+ id="<?php echo $this->field_id( array( 'tinvwl_purchased' => 'log' ) ); ?>"
2564
+ placeholder="<?php _e( 'required', 'ti-woocommerce-wishlist' ); ?>"
2565
+ value="<?php echo esc_attr( $prefs['tinvwl_purchased']['log'] ); ?>"
2566
+ class="form-control"/>
2567
+ <span class="description"><?php echo $this->available_template_tags( array(
2568
+ 'general',
2569
+ 'post'
2570
+ ) ); ?></span>
2571
+ </div>
2572
+ </div>
2573
+ </div>
2574
+ </div>
2575
+
2576
+ <?php
2577
+
2578
+ }
2579
+
2580
+ /**
2581
+ * Sanitise Preferences
2582
+ */
2583
+ public function sanitise_preferences( $data ) {
2584
+
2585
+ if ( isset( $data['tinvwl_added']['limit'] ) && isset( $data['tinvwl_added']['limit_by'] ) ) {
2586
+ $limit = sanitize_text_field( $data['tinvwl_added']['limit'] );
2587
+ if ( $limit == '' ) {
2588
+ $limit = 0;
2589
+ }
2590
+ $data['tinvwl_added']['limit'] = $limit . '/' . $data['tinvwl_added']['limit_by'];
2591
+ unset( $data['tinvwl_added']['limit_by'] );
2592
+ }
2593
+
2594
+ if ( isset( $data['tinvwl_purchased']['limit'] ) && isset( $data['tinvwl_purchased']['limit_by'] ) ) {
2595
+ $limit = sanitize_text_field( $data['tinvwl_purchased']['limit'] );
2596
+ if ( $limit == '' ) {
2597
+ $limit = 0;
2598
+ }
2599
+ $data['tinvwl_purchased']['limit'] = $limit . '/' . $data['tinvwl_purchased']['limit_by'];
2600
+ unset( $data['tinvwl_purchased']['limit_by'] );
2601
+ }
2602
+
2603
+ return $data;
2604
+
2605
+ }
2606
+
2607
+ }
2608
+
2609
+ }
2610
+
2611
+ add_filter( 'mycred_all_references', 'tinvwl_mycred_references' );
2612
+
2613
+ function tinvwl_mycred_references( $references ) {
2614
+
2615
+ $references['purchased_from_wishlist'] = __( 'Purchased From Wishlist', 'ti-woocommerce-wishlist' );
2616
+ $references['added_to_wishlist'] = __( 'Added To Wishlist', 'ti-woocommerce-wishlist' );
2617
+
2618
+ return $references;
2619
+ }
2620
+
2621
+ }