WooCommerce Wishlist Plugin - Version 1.6.1

Version Description

Release Date - 01 March 2018

  • Fixed an issue with deprecated function create_function(); on PHP 7.2+
  • Fixed an issue with duplicated products in Wishlist
  • Fixed an issue with empty wishlists in database and added cleanup on plugin upgrade
  • Fixed an issue when variable products were not removed from wishlist after adding to cart
  • Fixed PHP undefined notices in Wishlist table
  • Fixed warnings for non-existent products in Wishlist
  • Added new option "Show button text" that allows displaying the only add to wishlist icon
  • Added custom classes for buttons
  • Added "nofollow" attribute for button links
  • Improved compatibility with WP Multilang plugin
  • Improved compatibility with WooCommerce Multilingual plugin
  • Improved compatibility with Personalized Product Option Manager plugin
Download this release

Release Info

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

Code changes from version 1.6.0 to 1.6.1

admin/settings/general.class.php CHANGED
@@ -1,715 +1,745 @@
1
- <?php
2
- /**
3
- * Admin settings class
4
- *
5
- * @since 1.0.0
6
- * @package TInvWishlist\Admin
7
- * @subpackage Settings
8
- */
9
-
10
- // If this file is called directly, abort.
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- die;
13
- }
14
-
15
- /**
16
- * Admin settings class
17
- */
18
- class TInvWL_Admin_Settings_General extends TInvWL_Admin_BaseSection {
19
-
20
- /**
21
- * Priority for admin menu
22
- *
23
- * @var integer
24
- */
25
- public $priority = 20;
26
-
27
- /**
28
- * Menu array
29
- *
30
- * @return array
31
- */
32
- function menu() {
33
- return array(
34
- 'title' => __( 'General Settings', 'ti-woocommerce-wishlist' ),
35
- 'method' => array( $this, '_print_' ),
36
- 'slug' => '',
37
- );
38
- }
39
-
40
- /**
41
- * Create sections for this settings
42
- *
43
- * @return array
44
- */
45
- function constructor_data() {
46
- add_action( $this->_n . '_section_general_before', array( $this, 'premium_features' ) );
47
- $lists = get_pages( array( 'number' => 999999 ) ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.get_pages
48
- $page_list = array( '' => '' );
49
- foreach ( $lists as $list ) {
50
- $page_list[ $list->ID ] = $list->post_title;
51
- }
52
-
53
- return array(
54
- array(
55
- 'id' => 'general',
56
- 'title' => __( 'General Settings', 'ti-woocommerce-wishlist' ),
57
- 'desc' => __( 'Wishlist page need to be selected so the plugin knows where it is. This page should have been created upon installation of the plugin, if not you will need to create it manually.', 'ti-woocommerce-wishlist' ),
58
- 'show_names' => true,
59
- 'fields' => array(
60
- array(
61
- 'type' => 'text',
62
- 'name' => 'default_title',
63
- 'text' => __( 'Default Wishlist Name', 'ti-woocommerce-wishlist' ),
64
- 'std' => 'Default wishlist',
65
- ),
66
- array(
67
- 'type' => 'select',
68
- 'name' => 'page_wishlist',
69
- 'text' => __( 'Wishlist Page', 'ti-woocommerce-wishlist' ),
70
- 'std' => '',
71
- 'options' => $page_list,
72
- 'validate' => FILTER_VALIDATE_INT,
73
- ),
74
- array(
75
- 'type' => 'checkboxonoff',
76
- 'name' => 'require_login',
77
- 'text' => __( 'Require Login', 'ti-woocommerce-wishlist' ),
78
- 'desc' => __( 'Disallows guests to use Wishlist functionality until they sign-in.', 'ti-woocommerce-wishlist' ),
79
- 'std' => false,
80
- 'extra' => array(
81
- 'tiwl-show' => '.tiwl-general-redirect-require-login',
82
- ),
83
- ),
84
- array(
85
- 'type' => 'checkboxonoff',
86
- 'name' => 'redirect_require_login',
87
- 'text' => __( 'Redirect to Login Page', 'ti-woocommerce-wishlist' ),
88
- 'desc' => '<span class="tiwl-button-show-notice-warning-popup"><strong>' . __( 'Currently this option could not be changed because "Show successful notice in popup" is disabled. Guests will be redirected automatically to a login page.', 'ti-woocommerce-wishlist' ) . '</strong></span><span class="tiwl-button-show-notice">' . __( 'If enabled, guests will be redirected to a login page once clicking the "Add to Wishlist" button or "Wishlist Products Counter" link. Otherwise a popup with login required notice will appear.', 'ti-woocommerce-wishlist' ) . '</span>',
89
- 'std' => false,
90
- 'class' => 'tiwl-general-redirect-require-login',
91
- ),
92
- array(
93
- 'type' => 'checkboxonoff',
94
- 'name' => 'link_in_myaccount',
95
- 'text' => __( 'Show Link to Wishlist in my account', 'ti-woocommerce-wishlist' ),
96
- 'std' => true,
97
- ),
98
- array(
99
- 'type' => 'checkboxonoff',
100
- 'name' => 'processing_autoremove',
101
- 'text' => __( 'Remove Product from Wishlist if added to cart', 'ti-woocommerce-wishlist' ),
102
- 'std' => true,
103
- 'extra' => array( 'tiwl-show' => '.tiwl-processing-autoremove-anyone' ),
104
- ),
105
- array(
106
- 'type' => 'checkboxonoff',
107
- 'name' => 'processing_autoremove_anyone',
108
- 'text' => __( 'Remove by anyone', 'ti-woocommerce-wishlist' ),
109
- 'std' => false,
110
- 'class' => 'tiwl-processing-autoremove-anyone',
111
- ),
112
- array(
113
- 'type' => 'checkboxonoff',
114
- 'name' => 'simple_flow',
115
- 'text' => __( 'Remove product from Wishlist on second click', 'ti-woocommerce-wishlist' ),
116
- 'std' => false,
117
- 'extra' => array(
118
- 'tiwl-show' => '.tiwl-general-simple-flow>td, .tiwl-button-simple-flow',
119
- 'tiwl-hide' => '.tiwl-general-simple-flow-hide>td',
120
- ),
121
- ),
122
- array(
123
- 'type' => 'group',
124
- 'id' => 'show_notice',
125
- ),
126
- array(
127
- 'type' => 'checkboxonoff',
128
- 'name' => 'show_notice',
129
- 'text' => __( 'Show successful notice in popup', 'ti-woocommerce-wishlist' ),
130
- 'desc' => __( 'This option allows to show/hide a popup with successful or error notices after addition or removing products from a Wishlist.', 'ti-woocommerce-wishlist' ),
131
- 'std' => true,
132
- 'extra' => array(
133
- 'tiwl-show' => '.tiwl-button-show-notice',
134
- 'tiwl-hide' => '.tiwl-button-show-notice-warning-popup',
135
- ),
136
- ),
137
- array(
138
- 'type' => 'text',
139
- 'name' => 'text_browse',
140
- 'text' => __( '"View Wishlist" button Text', 'ti-woocommerce-wishlist' ),
141
- 'std' => 'View Wishlist',
142
- 'class' => 'tiwl-button-show-notice',
143
- ),
144
- array(
145
- 'type' => 'checkboxonoff',
146
- 'name' => 'redirect',
147
- 'text' => __( 'Redirect to Wishlist', 'ti-woocommerce-wishlist' ),
148
- 'desc' => __( 'If enabled, user will be redirected to wishlist page after 5 sec from adding product to wishlist.', 'ti-woocommerce-wishlist' ),
149
- 'std' => true,
150
- 'class' => 'tiwl-button-show-notice',
151
- ),
152
- array(
153
- 'type' => 'text',
154
- 'name' => 'text_added_to',
155
- 'text' => __( '"Product added to Wishlist" Text', 'ti-woocommerce-wishlist' ),
156
- 'std' => 'Product added to Wishlist',
157
- 'class' => 'tiwl-button-show-notice',
158
- ),
159
- array(
160
- 'type' => 'text',
161
- 'name' => 'text_already_in',
162
- 'text' => __( '"Product already in Wishlist" Text', 'ti-woocommerce-wishlist' ),
163
- 'desc' => __( 'This notification will be shown if user will try to add a product that is already in the wishlist.', 'ti-woocommerce-wishlist' ),
164
- 'std' => 'Product already in Wishlist',
165
- 'class' => 'tiwl-button-show-notice tiwl-general-simple-flow-hide',
166
- ),
167
- array(
168
- 'type' => 'text',
169
- 'name' => 'text_removed_from',
170
- 'text' => __( '"Product removed from Wishlist" Text', 'ti-woocommerce-wishlist' ),
171
- 'desc' => __( 'This notification will be shown once the product is removed from Wishlist on a single or a catalog page.', 'ti-woocommerce-wishlist' ),
172
- 'std' => 'Product removed from Wishlist',
173
- 'class' => 'tiwl-button-show-notice tiwl-general-simple-flow',
174
- ),
175
- ),
176
- ),
177
- array(
178
- 'id' => 'page',
179
- 'title' => __( 'Wishlist Page Options', 'ti-woocommerce-wishlist' ),
180
- 'desc' => __( 'Coming soon', 'ti-woocommerce-wishlist' ),
181
- 'show_names' => true,
182
- 'style' => 'display:none;',
183
- 'fields' => array(
184
- array(
185
- 'type' => 'select',
186
- 'name' => 'wishlist',
187
- 'text' => __( 'My Wishlist', 'ti-woocommerce-wishlist' ),
188
- 'std' => '',
189
- 'options' => $page_list,
190
- 'validate' => FILTER_VALIDATE_INT,
191
- ),
192
- ),
193
- ),
194
- array(
195
- 'id' => 'processing',
196
- 'title' => __( 'Wishlist Processing Options', 'ti-woocommerce-wishlist' ),
197
- 'desc' => __( 'Coming soon', 'ti-woocommerce-wishlist' ),
198
- 'style' => 'display:none;',
199
- 'show_names' => true,
200
- 'fields' => array(
201
- array(
202
- 'type' => 'checkboxonoff',
203
- 'name' => 'autoremove',
204
- 'text' => __( 'Automatic removal', 'ti-woocommerce-wishlist' ),
205
- 'std' => true,
206
- 'extra' => array( 'tiwl-show' => '.tiwl-processing-autoremove' ),
207
- ),
208
- array(
209
- 'type' => 'select',
210
- 'name' => 'autoremove_status',
211
- 'text' => __( 'Remove condition', 'ti-woocommerce-wishlist' ),
212
- 'std' => 'tinvwl-addcart',
213
- 'options' => array(
214
- 'tinvwl-addcart' => __( 'Add to Cart', 'ti-woocommerce-wishlist' ),
215
- ),
216
- 'class' => 'tiwl-processing-autoremove',
217
- ),
218
- array(
219
- 'type' => 'checkboxonoff',
220
- 'name' => 'autoremove_anyone',
221
- 'text' => __( 'Remove by anyone', 'ti-woocommerce-wishlist' ),
222
- 'std' => false,
223
- 'class' => 'tiwl-processing-autoremove',
224
- ),
225
- ),
226
- ),
227
- array(
228
- 'id' => 'add_to_wishlist',
229
- 'title' => __( 'Product page "Add to Wishlist" Button Settings', 'ti-woocommerce-wishlist' ),
230
- 'show_names' => true,
231
- 'fields' => array(
232
- array(
233
- 'type' => 'select',
234
- 'name' => 'position',
235
- 'text' => __( 'Button position', 'ti-woocommerce-wishlist' ),
236
- 'desc' => __( 'Add this shortcode <code>[ti_wishlists_addtowishlist]</code> anywhere on product page, if you have chosen custom position for product button. You will have to do this for each product.', 'ti-woocommerce-wishlist' ),
237
- 'std' => 'after',
238
- 'options' => array(
239
- 'after' => __( 'After "Add to Cart" button', 'ti-woocommerce-wishlist' ),
240
- 'before' => __( 'Before "Add to Cart" button', 'ti-woocommerce-wishlist' ),
241
- 'shortcode' => __( 'Custom position with code', 'ti-woocommerce-wishlist' ),
242
- ),
243
- ),
244
- array(
245
- 'type' => 'select',
246
- 'name' => 'type',
247
- 'text' => __( 'Button type', 'ti-woocommerce-wishlist' ),
248
- 'std' => 'link',
249
- 'options' => array(
250
- 'link' => __( 'Link', 'ti-woocommerce-wishlist' ),
251
- 'button' => __( 'Button', 'ti-woocommerce-wishlist' ),
252
- ),
253
- ),
254
- array(
255
- 'type' => 'select',
256
- 'name' => 'icon',
257
- 'text' => __( '"Add to Wishlist" Icon', 'ti-woocommerce-wishlist' ),
258
- 'desc' => __( 'You can choose from our predefined icons or upload your custom icon. Custom icon size is limited to 16x16 px.', 'ti-woocommerce-wishlist' ),
259
- 'std' => '',
260
- 'options' => array(
261
- '' => __( 'None', 'ti-woocommerce-wishlist' ),
262
- 'heart' => __( 'Heart', 'ti-woocommerce-wishlist' ),
263
- 'heart-plus' => __( 'Heart+', 'ti-woocommerce-wishlist' ),
264
- 'custom' => __( 'Custom', 'ti-woocommerce-wishlist' ),
265
- ),
266
- 'extra' => array(
267
- 'class' => 'tiwl-button-icon',
268
- 'tiwl-show' => '.tiwl-button-icon-custom',
269
- 'tiwl-hide' => '.tiwl-button-icon-style',
270
- 'tiwl-value' => 'custom',
271
- ),
272
- ),
273
- array(
274
- 'type' => 'uploadfile',
275
- 'name' => 'icon_upload',
276
- 'std' => '',
277
- 'text' => ' ',
278
- 'class' => 'tiwl-button-icon-custom',
279
- 'extra' => array(
280
- 'button' => array(
281
- 'value' => __( 'Upload', 'ti-woocommerce-wishlist' ),
282
- ),
283
- 'type' => array( 'image' ),
284
- ),
285
- ),
286
- array(
287
- 'type' => 'select',
288
- 'name' => 'icon_style',
289
- 'std' => 'black',
290
- 'text' => __( '"Add to Wishlist" Icon Color', 'ti-woocommerce-wishlist' ),
291
- 'options' => array(
292
- 'black' => __( 'Black', 'ti-woocommerce-wishlist' ),
293
- 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
294
- ),
295
- 'class' => 'tiwl-button-icon-style',
296
- ),
297
- array(
298
- 'type' => 'text',
299
- 'name' => 'text',
300
- 'text' => __( '"Add to Wishlist" button Text', 'ti-woocommerce-wishlist' ),
301
- 'std' => 'Add to Wishlist',
302
- ),
303
- array(
304
- 'type' => 'text',
305
- 'name' => 'text_remove',
306
- 'text' => __( '"Remove from Wishlist" Button Text', 'ti-woocommerce-wishlist' ),
307
- 'std' => 'Remove from Wishlist',
308
- 'class' => 'tiwl-button-simple-flow',
309
- ),
310
- ),
311
- ),
312
- array(
313
- 'id' => 'add_to_wishlist_catalog',
314
- 'title' => __( 'Product listing Button Settings', 'ti-woocommerce-wishlist' ),
315
- 'desc' => __( 'These are separate settings for the "Add to Wishlist" button on a product listing (Shop page, categories, etc.). You can also adjust button and text colors, size, etc. in a <code>TI Wishlist > Style Options.</code>', 'ti-woocommerce-wishlist' ),
316
- 'show_names' => true,
317
- 'fields' => array(
318
- array(
319
- 'type' => 'checkboxonoff',
320
- 'name' => 'show_in_loop',
321
- 'text' => __( 'Show in Product Listing', 'ti-woocommerce-wishlist' ),
322
- 'std' => true,
323
- 'extra' => array(
324
- 'tiwl-show' => '.tiwl-buttoncat-button',
325
- ),
326
- ),
327
- array(
328
- 'type' => 'group',
329
- 'id' => 'add_to_wishlist_catalog',
330
- 'class' => 'tiwl-buttoncat-button',
331
- 'style' => 'border-top: 0px; padding-top: 0px;',
332
- ),
333
- array(
334
- 'type' => 'select',
335
- 'name' => 'position',
336
- 'text' => __( 'Button position', 'ti-woocommerce-wishlist' ),
337
- 'std' => 'after',
338
- 'options' => array(
339
- 'after' => __( 'After "Add to Cart" button', 'ti-woocommerce-wishlist' ),
340
- 'before' => __( 'Before "Add to Cart" button', 'ti-woocommerce-wishlist' ),
341
- 'above_thumb' => __( 'Above Thumbnail', 'ti-woocommerce-wishlist' ),
342
- 'shortcode' => __( 'Custom position with code', 'ti-woocommerce-wishlist' ),
343
- ),
344
- 'desc' => __( 'Note: if "Custom position with code" option is applied, the "Add to Wishlist" button should be added into template using <code>do_shortcode()</code> function like this:<br /><code>do_shortcode("[ti_wishlists_addtowishlist loop=yes]")</code>', 'ti-woocommerce-wishlist' ),
345
- ),
346
- array(
347
- 'type' => 'select',
348
- 'name' => 'type',
349
- 'text' => __( 'Button type', 'ti-woocommerce-wishlist' ),
350
- 'std' => 'button',
351
- 'options' => array(
352
- 'link' => __( 'Link', 'ti-woocommerce-wishlist' ),
353
- 'button' => __( 'Button', 'ti-woocommerce-wishlist' ),
354
- ),
355
- ),
356
- array(
357
- 'type' => 'select',
358
- 'name' => 'icon',
359
- 'text' => __( '"Add to Wishlist" Icon', 'ti-woocommerce-wishlist' ),
360
- 'std' => '',
361
- 'options' => array(
362
- '' => __( 'None', 'ti-woocommerce-wishlist' ),
363
- 'heart' => __( 'Heart', 'ti-woocommerce-wishlist' ),
364
- 'heart-plus' => __( 'Heart+', 'ti-woocommerce-wishlist' ),
365
- 'custom' => __( 'Custom', 'ti-woocommerce-wishlist' ),
366
- ),
367
- 'extra' => array(
368
- 'tiwl-show' => '.tiwl-buttoncat-icon-custom',
369
- 'tiwl-hide' => '.tiwl-buttoncat-icon-style',
370
- 'tiwl-value' => 'custom',
371
- ),
372
- ),
373
- array(
374
- 'type' => 'uploadfile',
375
- 'name' => 'icon_upload',
376
- 'std' => '',
377
- 'text' => ' ',
378
- 'class' => 'tiwl-buttoncat-icon-custom',
379
- 'extra' => array(
380
- 'button' => array(
381
- 'value' => __( 'Upload', 'ti-woocommerce-wishlist' ),
382
- ),
383
- 'type' => array( 'image' ),
384
- ),
385
- ),
386
- array(
387
- 'type' => 'select',
388
- 'name' => 'icon_style',
389
- 'std' => 'black',
390
- 'text' => __( '"Add to Wishlist" Icon Color', 'ti-woocommerce-wishlist' ),
391
- 'options' => array(
392
- 'black' => __( 'Black', 'ti-woocommerce-wishlist' ),
393
- 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
394
- ),
395
- 'class' => 'tiwl-buttoncat-icon-style',
396
- ),
397
- array(
398
- 'type' => 'text',
399
- 'name' => 'text',
400
- 'text' => __( '"Add to Wishlist" Text', 'ti-woocommerce-wishlist' ),
401
- 'std' => 'Add to Wishlist',
402
- ),
403
- array(
404
- 'type' => 'text',
405
- 'name' => 'text_remove',
406
- 'text' => __( '"Remove from Wishlist" Button Text', 'ti-woocommerce-wishlist' ),
407
- 'std' => 'Remove from Wishlist',
408
- 'class' => 'tiwl-button-simple-flow',
409
- ),
410
- ),
411
- ),
412
- array(
413
- 'id' => 'product_table',
414
- 'title' => __( 'Wishlist Product Settings', 'ti-woocommerce-wishlist' ),
415
- 'desc' => __( 'Following options allows you to choose what information/functionality to show/enable in wishlist table on wishlist page.', 'ti-woocommerce-wishlist' ),
416
- 'show_names' => true,
417
- 'fields' => array(
418
- array(
419
- 'type' => 'checkboxonoff',
420
- 'name' => 'add_to_cart',
421
- 'text' => __( 'Show "Add to Cart" button', 'ti-woocommerce-wishlist' ),
422
- 'std' => true,
423
- 'extra' => array( 'tiwl-show' => '.tiwl-table-action-addcart' ),
424
- ),
425
- array(
426
- 'type' => 'text',
427
- 'name' => 'text_add_to_cart',
428
- 'text' => __( '"Add to Cart" Text', 'ti-woocommerce-wishlist' ),
429
- 'std' => 'Add to Cart',
430
- 'class' => 'tiwl-table-action-addcart',
431
- ),
432
- array(
433
- 'type' => 'checkboxonoff',
434
- 'name' => 'colm_price',
435
- 'text' => __( 'Show Unit price', 'ti-woocommerce-wishlist' ),
436
- 'std' => true,
437
- ),
438
- array(
439
- 'type' => 'checkboxonoff',
440
- 'name' => 'colm_stock',
441
- 'text' => __( 'Show Stock status', 'ti-woocommerce-wishlist' ),
442
- 'std' => true,
443
- ),
444
- array(
445
- 'type' => 'checkboxonoff',
446
- 'name' => 'colm_date',
447
- 'text' => __( 'Show Date of addition', 'ti-woocommerce-wishlist' ),
448
- 'std' => true,
449
- ),
450
- ),
451
- ),
452
- array(
453
- 'id' => 'table',
454
- 'title' => __( 'Wishlist Table Settings', 'ti-woocommerce-wishlist' ),
455
- 'desc' => __( 'Following options will help user to manage and add products to cart from wishlist table in bulk.', 'ti-woocommerce-wishlist' ),
456
- 'show_names' => true,
457
- 'fields' => array(
458
- array(
459
- 'type' => 'checkboxonoff',
460
- 'name' => 'colm_checkbox',
461
- 'text' => __( 'Show Checkboxes', 'ti-woocommerce-wishlist' ),
462
- 'std' => true,
463
- 'extra' => array( 'tiwl-show' => '.tiwl-table-cb-button' ),
464
- ),
465
- array(
466
- 'type' => 'group',
467
- 'id' => 'cb_button',
468
- 'class' => 'tiwl-table-cb-button',
469
- ),
470
- array(
471
- 'type' => 'checkboxonoff',
472
- 'name' => 'colm_actions',
473
- 'text' => __( 'Show Actions button', 'ti-woocommerce-wishlist' ),
474
- 'desc' => __( 'Bulk actions drop down at the bottom of wishlist table', 'ti-woocommerce-wishlist' ),
475
- 'std' => true,
476
- ),
477
- array(
478
- 'type' => 'checkboxonoff',
479
- 'name' => 'add_select_to_cart',
480
- 'text' => __( 'Show "Add Selected to Cart" button', 'ti-woocommerce-wishlist' ),
481
- 'std' => true,
482
- 'extra' => array( 'tiwl-show' => '.tiwl-table-addcart-sel' ),
483
- ),
484
- array(
485
- 'type' => 'text',
486
- 'name' => 'text_add_select_to_cart',
487
- 'text' => __( '"Add Selected to Cart" Button Text', 'ti-woocommerce-wishlist' ),
488
- 'std' => 'Add Selected to Cart',
489
- 'class' => 'tiwl-table-addcart-sel',
490
- ),
491
- array(
492
- 'type' => 'group',
493
- 'id' => '_button',
494
- ),
495
- array(
496
- 'type' => 'checkboxonoff',
497
- 'name' => 'add_all_to_cart',
498
- 'text' => __( 'Show "Add All to Cart" button', 'ti-woocommerce-wishlist' ),
499
- 'std' => true,
500
- 'extra' => array( 'tiwl-show' => '.tiwl-table-addcart-all' ),
501
- ),
502
- array(
503
- 'type' => 'text',
504
- 'name' => 'text_add_all_to_cart',
505
- 'text' => __( '"Add All to Cart" Button Text', 'ti-woocommerce-wishlist' ),
506
- 'std' => 'Add All to Cart',
507
- 'class' => 'tiwl-table-addcart-all',
508
- ),
509
- ),
510
- ),
511
- array(
512
- 'id' => 'social',
513
- 'show_names' => true,
514
- 'fields' => array(
515
- array(
516
- 'type' => 'group',
517
- 'id' => 'social',
518
- 'desc' => __( 'Following options enable/disable Social share icons below wishlist table on wishlist page. Wishlist owner can easily share their wishlists using this button on social networks. Wishlist privacy should be set to public or shared status, private wishlists can\'t be shared.', 'ti-woocommerce-wishlist' ),
519
- 'class' => 'tinvwl-info-top',
520
- ),
521
- array(
522
- 'type' => 'html',
523
- 'name' => 'social',
524
- 'text' => __( 'Social Networks Sharing Options', 'ti-woocommerce-wishlist' ),
525
- 'class' => 'tinvwl-header-row tinvwl-line-border',
526
- ),
527
- array(
528
- 'type' => 'checkboxonoff',
529
- 'name' => 'facebook',
530
- 'text' => __( 'Show "Facebook" Button', 'ti-woocommerce-wishlist' ),
531
- 'std' => true,
532
- ),
533
- array(
534
- 'type' => 'checkboxonoff',
535
- 'name' => 'twitter',
536
- 'text' => __( 'Show "Twitter" Button', 'ti-woocommerce-wishlist' ),
537
- 'std' => true,
538
- ),
539
- array(
540
- 'type' => 'checkboxonoff',
541
- 'name' => 'pinterest',
542
- 'text' => __( 'Show "Pinterest" Button', 'ti-woocommerce-wishlist' ),
543
- 'std' => true,
544
- ),
545
- array(
546
- 'type' => 'checkboxonoff',
547
- 'name' => 'google',
548
- 'text' => __( 'Show "Google+" Button', 'ti-woocommerce-wishlist' ),
549
- 'std' => true,
550
- ),
551
- array(
552
- 'type' => 'checkboxonoff',
553
- 'name' => 'email',
554
- 'text' => __( 'Show "Share by Email" Button', 'ti-woocommerce-wishlist' ),
555
- 'std' => true,
556
- ),
557
- array(
558
- 'type' => 'text',
559
- 'name' => 'share_on',
560
- 'text' => __( '"Share on" Text', 'ti-woocommerce-wishlist' ),
561
- 'std' => 'Share on',
562
- ),
563
- array(
564
- 'type' => 'select',
565
- 'name' => 'icon_style',
566
- 'text' => __( 'Social Icons Color', 'ti-woocommerce-wishlist' ),
567
- 'options' => array(
568
- 'dark' => __( 'Dark', 'ti-woocommerce-wishlist' ),
569
- 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
570
- ),
571
- 'validate' => FILTER_DEFAULT,
572
- ),
573
- ),
574
- ),
575
- array(
576
- 'id' => 'topline',
577
- 'title' => __( 'Wishlist Products Counter', 'ti-woocommerce-wishlist' ),
578
- 'desc' => sprintf( __( 'Add this shortcode <code>[ti_wishlist_products_counter]</code> anywhere into a page content to show Wishlist Counter.<br/><br/>It can be also added as a widget <code>Wishlist Products Counter</code> under the <a href="%s">Appearance -> Widgets</a> section.', 'ti-woocommerce-wishlist' ), esc_url( admin_url( 'widgets.php' ) ) ),
579
- 'show_names' => true,
580
- 'fields' => array(
581
- array(
582
- 'type' => 'select',
583
- 'name' => 'icon',
584
- 'text' => __( '"Wishlist" Icon', 'ti-woocommerce-wishlist' ),
585
- 'std' => '',
586
- 'options' => array(
587
- '' => __( 'None', 'ti-woocommerce-wishlist' ),
588
- 'heart' => __( 'Heart', 'ti-woocommerce-wishlist' ),
589
- 'heart-plus' => __( 'Heart+', 'ti-woocommerce-wishlist' ),
590
- 'custom' => __( 'Custom', 'ti-woocommerce-wishlist' ),
591
- ),
592
- 'desc' => __( 'You can choose from our predefined icons or upload your custom icon. Custom icon size is limited to 16x16 px.', 'ti-woocommerce-wishlist' ),
593
- 'extra' => array(
594
- 'tiwl-show' => '.tiwl-dropdown-icon-custom',
595
- 'tiwl-hide' => '.tiwl-dropdown-icon-style',
596
- 'tiwl-value' => 'custom',
597
- ),
598
- ),
599
- array(
600
- 'type' => 'uploadfile',
601
- 'name' => 'icon_upload',
602
- 'std' => '',
603
- 'text' => ' ',
604
- 'class' => 'tiwl-dropdown-icon-custom',
605
- 'extra' => array(
606
- 'button' => array(
607
- 'value' => __( 'Upload', 'ti-woocommerce-wishlist' ),
608
- ),
609
- 'type' => array( 'image' ),
610
- ),
611
- ),
612
- array(
613
- 'type' => 'select',
614
- 'name' => 'icon_style',
615
- 'std' => 'black',
616
- 'text' => __( '"Wishlist" Icon Color', 'ti-woocommerce-wishlist' ),
617
- 'options' => array(
618
- 'black' => __( 'Black', 'ti-woocommerce-wishlist' ),
619
- 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
620
- ),
621
- 'class' => 'tiwl-dropdown-icon-style',
622
- ),
623
- array(
624
- 'type' => 'checkboxonoff',
625
- 'name' => 'show_text',
626
- 'text' => __( 'Show counter text', 'ti-woocommerce-wishlist' ),
627
- 'std' => true,
628
- 'extra' => array(
629
- 'tiwl-show' => '.tiwl-dropdown-text',
630
- ),
631
- ),
632
- array(
633
- 'type' => 'text',
634
- 'name' => 'text',
635
- 'text' => __( 'Counter Text', 'ti-woocommerce-wishlist' ),
636
- 'std' => __( 'Wishlist - ', 'ti-woocommerce-wishlist' ),
637
- 'class' => 'tiwl-dropdown-text',
638
- ),
639
- ),
640
- ),
641
- array(
642
- 'id' => 'save_buttons',
643
- 'class' => 'only-button',
644
- 'noform' => true,
645
- 'fields' => array(
646
- array(
647
- 'type' => 'button_submit',
648
- 'name' => 'setting_save',
649
- 'std' => '<span><i class="fa fa-check"></i></span>' . __( 'Save Settings', 'ti-woocommerce-wishlist' ),
650
- 'extra' => array( 'class' => 'tinvwl-btn split status-btn-ok' ),
651
- ),
652
- array(
653
- 'type' => 'button_submit',
654
- 'name' => 'setting_reset',
655
- 'std' => '<span><i class="fa fa-times"></i></span>' . __( 'Reset', 'ti-woocommerce-wishlist' ),
656
- 'extra' => array( 'class' => 'tinvwl-btn split status-btn-ok tinvwl-confirm-reset' ),
657
- ),
658
- array(
659
- 'type' => 'button_submit_quick',
660
- 'name' => 'setting_save_quick',
661
- 'std' => '<span><i class="fa fa-floppy-o"></i></span>' . __( 'Save', 'ti-woocommerce-wishlist' ),
662
- ),
663
- ),
664
- ),
665
- );
666
- }
667
-
668
- /**
669
- * Load value from database
670
- *
671
- * @param array $sections Sections array.
672
- *
673
- * @return array
674
- */
675
- function constructor_load( $sections ) {
676
- $data = parent::constructor_load( $sections );
677
- $data['general']['page_wishlist'] = $data['page']['wishlist'];
678
- $data['general']['processing_autoremove'] = $data['processing']['autoremove'];
679
- $data['general']['processing_autoremove_anyone'] = $data['processing']['autoremove_anyone'];
680
-
681
- return $data;
682
- }
683
-
684
- /**
685
- * Save value to database and flush rewrite.
686
- *
687
- * @param array $data Post section data.
688
- */
689
- function constructor_save( $data ) {
690
- parent::constructor_save( $data );
691
- if ( empty( $data ) || ! is_array( $data ) ) {
692
- return false;
693
- }
694
- tinv_update_option( 'page', 'wishlist', $data['general']['page_wishlist'] );
695
- tinv_update_option( 'processing', 'autoremove', $data['general']['processing_autoremove'] );
696
- tinv_update_option( 'processing', 'autoremove_anyone', $data['general']['processing_autoremove_anyone'] );
697
- tinv_update_option( 'processing', 'autoremove_status', 'tinvwl-addcart' );
698
- if ( filter_input( INPUT_POST, 'save_buttons-setting_reset' ) ) {
699
- foreach ( $data as $key => $value ) {
700
- if ( ! in_array( $key, array( 'page' ) ) ) {
701
- $data[ $key ] = array();
702
- }
703
- }
704
- parent::constructor_save( $data );
705
- }
706
- TInvWL_Public_TInvWL::update_rewrite_rules();
707
- }
708
-
709
- /**
710
- * Show Premium Features sections
711
- */
712
- function premium_features() {
713
- TInvWL_View::view( 'premium-features' );
714
- }
715
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin settings class
4
+ *
5
+ * @since 1.0.0
6
+ * @package TInvWishlist\Admin
7
+ * @subpackage Settings
8
+ */
9
+
10
+ // If this file is called directly, abort.
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ die;
13
+ }
14
+
15
+ /**
16
+ * Admin settings class
17
+ */
18
+ class TInvWL_Admin_Settings_General extends TInvWL_Admin_BaseSection {
19
+
20
+ /**
21
+ * Priority for admin menu
22
+ *
23
+ * @var integer
24
+ */
25
+ public $priority = 20;
26
+
27
+ /**
28
+ * Menu array
29
+ *
30
+ * @return array
31
+ */
32
+ function menu() {
33
+ return array(
34
+ 'title' => __( 'General Settings', 'ti-woocommerce-wishlist' ),
35
+ 'method' => array( $this, '_print_' ),
36
+ 'slug' => '',
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Create sections for this settings
42
+ *
43
+ * @return array
44
+ */
45
+ function constructor_data() {
46
+ add_action( $this->_n . '_section_general_before', array( $this, 'premium_features' ) );
47
+ $lists = get_pages( array( 'number' => 999999 ) ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.get_pages
48
+ $page_list = array( '' => '' );
49
+ foreach ( $lists as $list ) {
50
+ $page_list[ $list->ID ] = $list->post_title;
51
+ }
52
+
53
+ return array(
54
+ array(
55
+ 'id' => 'general',
56
+ 'title' => __( 'General Settings', 'ti-woocommerce-wishlist' ),
57
+ 'desc' => __( 'Wishlist page need to be selected so the plugin knows where it is. This page should have been created upon installation of the plugin, if not you will need to create it manually.', 'ti-woocommerce-wishlist' ),
58
+ 'show_names' => true,
59
+ 'fields' => array(
60
+ array(
61
+ 'type' => 'text',
62
+ 'name' => 'default_title',
63
+ 'text' => __( 'Default Wishlist Name', 'ti-woocommerce-wishlist' ),
64
+ 'std' => 'Default wishlist',
65
+ ),
66
+ array(
67
+ 'type' => 'select',
68
+ 'name' => 'page_wishlist',
69
+ 'text' => __( 'Wishlist Page', 'ti-woocommerce-wishlist' ),
70
+ 'std' => '',
71
+ 'options' => $page_list,
72
+ 'validate' => FILTER_VALIDATE_INT,
73
+ ),
74
+ array(
75
+ 'type' => 'checkboxonoff',
76
+ 'name' => 'require_login',
77
+ 'text' => __( 'Require Login', 'ti-woocommerce-wishlist' ),
78
+ 'desc' => __( 'Disallows guests to use Wishlist functionality until they sign-in.', 'ti-woocommerce-wishlist' ),
79
+ 'std' => false,
80
+ 'extra' => array(
81
+ 'tiwl-show' => '.tiwl-general-redirect-require-login',
82
+ ),
83
+ ),
84
+ array(
85
+ 'type' => 'checkboxonoff',
86
+ 'name' => 'redirect_require_login',
87
+ 'text' => __( 'Redirect to Login Page', 'ti-woocommerce-wishlist' ),
88
+ 'desc' => '<span class="tiwl-button-show-notice-warning-popup"><strong>' . __( 'Currently this option could not be changed because "Show successful notice in popup" is disabled. Guests will be redirected automatically to a login page.', 'ti-woocommerce-wishlist' ) . '</strong></span><span class="tiwl-button-show-notice">' . __( 'If enabled, guests will be redirected to a login page once clicking the "Add to Wishlist" button or "Wishlist Products Counter" link. Otherwise a popup with login required notice will appear.', 'ti-woocommerce-wishlist' ) . '</span>',
89
+ 'std' => false,
90
+ 'class' => 'tiwl-general-redirect-require-login',
91
+ ),
92
+ array(
93
+ 'type' => 'checkboxonoff',
94
+ 'name' => 'link_in_myaccount',
95
+ 'text' => __( 'Show Link to Wishlist in my account', 'ti-woocommerce-wishlist' ),
96
+ 'std' => true,
97
+ ),
98
+ array(
99
+ 'type' => 'checkboxonoff',
100
+ 'name' => 'processing_autoremove',
101
+ 'text' => __( 'Remove Product from Wishlist if added to cart', 'ti-woocommerce-wishlist' ),
102
+ 'std' => true,
103
+ 'extra' => array( 'tiwl-show' => '.tiwl-processing-autoremove-anyone' ),
104
+ ),
105
+ array(
106
+ 'type' => 'checkboxonoff',
107
+ 'name' => 'processing_autoremove_anyone',
108
+ 'text' => __( 'Remove by anyone', 'ti-woocommerce-wishlist' ),
109
+ 'std' => false,
110
+ 'class' => 'tiwl-processing-autoremove-anyone',
111
+ ),
112
+ array(
113
+ 'type' => 'checkboxonoff',
114
+ 'name' => 'simple_flow',
115
+ 'text' => __( 'Remove product from Wishlist on second click', 'ti-woocommerce-wishlist' ),
116
+ 'std' => false,
117
+ 'extra' => array(
118
+ 'tiwl-show' => '.tiwl-general-simple-flow>td, .tiwl-button-simple-flow',
119
+ 'tiwl-hide' => '.tiwl-general-simple-flow-hide>td',
120
+ ),
121
+ ),
122
+ array(
123
+ 'type' => 'group',
124
+ 'id' => 'show_notice',
125
+ ),
126
+ array(
127
+ 'type' => 'checkboxonoff',
128
+ 'name' => 'show_notice',
129
+ 'text' => __( 'Show successful notice in popup', 'ti-woocommerce-wishlist' ),
130
+ 'desc' => __( 'This option allows to show/hide a popup with successful or error notices after addition or removing products from a Wishlist.', 'ti-woocommerce-wishlist' ),
131
+ 'std' => true,
132
+ 'extra' => array(
133
+ 'tiwl-show' => '.tiwl-button-show-notice',
134
+ 'tiwl-hide' => '.tiwl-button-show-notice-warning-popup',
135
+ ),
136
+ ),
137
+ array(
138
+ 'type' => 'text',
139
+ 'name' => 'text_browse',
140
+ 'text' => __( '"View Wishlist" button Text', 'ti-woocommerce-wishlist' ),
141
+ 'std' => 'View Wishlist',
142
+ 'class' => 'tiwl-button-show-notice',
143
+ ),
144
+ array(
145
+ 'type' => 'checkboxonoff',
146
+ 'name' => 'redirect',
147
+ 'text' => __( 'Redirect to Wishlist', 'ti-woocommerce-wishlist' ),
148
+ 'desc' => __( 'If enabled, user will be redirected to wishlist page after 5 sec from adding product to wishlist.', 'ti-woocommerce-wishlist' ),
149
+ 'std' => true,
150
+ 'class' => 'tiwl-button-show-notice',
151
+ ),
152
+ array(
153
+ 'type' => 'text',
154
+ 'name' => 'text_added_to',
155
+ 'text' => __( '"Product added to Wishlist" Text', 'ti-woocommerce-wishlist' ),
156
+ 'std' => 'Product added to Wishlist',
157
+ 'class' => 'tiwl-button-show-notice',
158
+ ),
159
+ array(
160
+ 'type' => 'text',
161
+ 'name' => 'text_already_in',
162
+ 'text' => __( '"Product already in Wishlist" Text', 'ti-woocommerce-wishlist' ),
163
+ 'desc' => __( 'This notification will be shown if user will try to add a product that is already in the wishlist.', 'ti-woocommerce-wishlist' ),
164
+ 'std' => 'Product already in Wishlist',
165
+ 'class' => 'tiwl-button-show-notice tiwl-general-simple-flow-hide',
166
+ ),
167
+ array(
168
+ 'type' => 'text',
169
+ 'name' => 'text_removed_from',
170
+ 'text' => __( '"Product removed from Wishlist" Text', 'ti-woocommerce-wishlist' ),
171
+ 'desc' => __( 'This notification will be shown once the product is removed from Wishlist on a single or a catalog page.', 'ti-woocommerce-wishlist' ),
172
+ 'std' => 'Product removed from Wishlist',
173
+ 'class' => 'tiwl-button-show-notice tiwl-general-simple-flow',
174
+ ),
175
+ ),
176
+ ),
177
+ array(
178
+ 'id' => 'page',
179
+ 'title' => __( 'Wishlist Page Options', 'ti-woocommerce-wishlist' ),
180
+ 'desc' => __( 'Coming soon', 'ti-woocommerce-wishlist' ),
181
+ 'show_names' => true,
182
+ 'style' => 'display:none;',
183
+ 'fields' => array(
184
+ array(
185
+ 'type' => 'select',
186
+ 'name' => 'wishlist',
187
+ 'text' => __( 'My Wishlist', 'ti-woocommerce-wishlist' ),
188
+ 'std' => '',
189
+ 'options' => $page_list,
190
+ 'validate' => FILTER_VALIDATE_INT,
191
+ ),
192
+ ),
193
+ ),
194
+ array(
195
+ 'id' => 'processing',
196
+ 'title' => __( 'Wishlist Processing Options', 'ti-woocommerce-wishlist' ),
197
+ 'desc' => __( 'Coming soon', 'ti-woocommerce-wishlist' ),
198
+ 'style' => 'display:none;',
199
+ 'show_names' => true,
200
+ 'fields' => array(
201
+ array(
202
+ 'type' => 'checkboxonoff',
203
+ 'name' => 'autoremove',
204
+ 'text' => __( 'Automatic removal', 'ti-woocommerce-wishlist' ),
205
+ 'std' => true,
206
+ 'extra' => array( 'tiwl-show' => '.tiwl-processing-autoremove' ),
207
+ ),
208
+ array(
209
+ 'type' => 'select',
210
+ 'name' => 'autoremove_status',
211
+ 'text' => __( 'Remove condition', 'ti-woocommerce-wishlist' ),
212
+ 'std' => 'tinvwl-addcart',
213
+ 'options' => array(
214
+ 'tinvwl-addcart' => __( 'Add to Cart', 'ti-woocommerce-wishlist' ),
215
+ ),
216
+ 'class' => 'tiwl-processing-autoremove',
217
+ ),
218
+ array(
219
+ 'type' => 'checkboxonoff',
220
+ 'name' => 'autoremove_anyone',
221
+ 'text' => __( 'Remove by anyone', 'ti-woocommerce-wishlist' ),
222
+ 'std' => false,
223
+ 'class' => 'tiwl-processing-autoremove',
224
+ ),
225
+ ),
226
+ ),
227
+ array(
228
+ 'id' => 'add_to_wishlist',
229
+ 'title' => __( 'Product page "Add to Wishlist" Button Settings', 'ti-woocommerce-wishlist' ),
230
+ 'show_names' => true,
231
+ 'fields' => array(
232
+ array(
233
+ 'type' => 'select',
234
+ 'name' => 'position',
235
+ 'text' => __( 'Button position', 'ti-woocommerce-wishlist' ),
236
+ 'desc' => __( 'Add this shortcode <code>[ti_wishlists_addtowishlist]</code> anywhere on product page, if you have chosen custom position for product button. You will have to do this for each product.', 'ti-woocommerce-wishlist' ),
237
+ 'std' => 'after',
238
+ 'options' => array(
239
+ 'after' => __( 'After "Add to Cart" button', 'ti-woocommerce-wishlist' ),
240
+ 'before' => __( 'Before "Add to Cart" button', 'ti-woocommerce-wishlist' ),
241
+ 'shortcode' => __( 'Custom position with code', 'ti-woocommerce-wishlist' ),
242
+ ),
243
+ ),
244
+ array(
245
+ 'type' => 'select',
246
+ 'name' => 'type',
247
+ 'text' => __( 'Button type', 'ti-woocommerce-wishlist' ),
248
+ 'std' => 'link',
249
+ 'options' => array(
250
+ 'link' => __( 'Link', 'ti-woocommerce-wishlist' ),
251
+ 'button' => __( 'Button', 'ti-woocommerce-wishlist' ),
252
+ ),
253
+ ),
254
+ array(
255
+ 'type' => 'select',
256
+ 'name' => 'icon',
257
+ 'text' => __( '"Add to Wishlist" Icon', 'ti-woocommerce-wishlist' ),
258
+ 'desc' => __( 'You can choose from our predefined icons or upload your custom icon. Custom icon size is limited to 16x16 px.', 'ti-woocommerce-wishlist' ),
259
+ 'std' => '',
260
+ 'options' => array(
261
+ '' => __( 'None', 'ti-woocommerce-wishlist' ),
262
+ 'heart' => __( 'Heart', 'ti-woocommerce-wishlist' ),
263
+ 'heart-plus' => __( 'Heart+', 'ti-woocommerce-wishlist' ),
264
+ 'custom' => __( 'Custom', 'ti-woocommerce-wishlist' ),
265
+ ),
266
+ 'extra' => array(
267
+ 'class' => 'tiwl-button-icon',
268
+ 'tiwl-show' => '.tiwl-button-icon-custom',
269
+ 'tiwl-hide' => '.tiwl-button-icon-style',
270
+ 'tiwl-value' => 'custom',
271
+ ),
272
+ ),
273
+ array(
274
+ 'type' => 'uploadfile',
275
+ 'name' => 'icon_upload',
276
+ 'std' => '',
277
+ 'text' => ' ',
278
+ 'class' => 'tiwl-button-icon-custom',
279
+ 'extra' => array(
280
+ 'button' => array(
281
+ 'value' => __( 'Upload', 'ti-woocommerce-wishlist' ),
282
+ ),
283
+ 'type' => array( 'image' ),
284
+ ),
285
+ ),
286
+ array(
287
+ 'type' => 'select',
288
+ 'name' => 'icon_style',
289
+ 'std' => 'black',
290
+ 'text' => __( '"Add to Wishlist" Icon Color', 'ti-woocommerce-wishlist' ),
291
+ 'options' => array(
292
+ 'black' => __( 'Black', 'ti-woocommerce-wishlist' ),
293
+ 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
294
+ ),
295
+ 'class' => 'tiwl-button-icon-style',
296
+ ),
297
+ array(
298
+ 'type' => 'checkboxonoff',
299
+ 'name' => 'show_text',
300
+ 'text' => __( 'Show button text', 'ti-woocommerce-wishlist-premium' ),
301
+ 'std' => true,
302
+ 'extra' => array(
303
+ 'tiwl-show' => '.tiwl-button-text',
304
+ ),
305
+ ),
306
+ array(
307
+ 'type' => 'group',
308
+ 'id' => 'show_text_single',
309
+ 'class' => 'tiwl-button-text',
310
+ 'style' => 'border-top: 0px; padding-top: 0px;',
311
+ ),
312
+ array(
313
+ 'type' => 'text',
314
+ 'name' => 'text',
315
+ 'text' => __( '"Add to Wishlist" button Text', 'ti-woocommerce-wishlist' ),
316
+ 'std' => 'Add to Wishlist',
317
+ ),
318
+ array(
319
+ 'type' => 'text',
320
+ 'name' => 'text_remove',
321
+ 'text' => __( '"Remove from Wishlist" Button Text', 'ti-woocommerce-wishlist' ),
322
+ 'std' => 'Remove from Wishlist',
323
+ 'class' => 'tiwl-button-simple-flow',
324
+ ),
325
+ ),
326
+ ),
327
+ array(
328
+ 'id' => 'add_to_wishlist_catalog',
329
+ 'title' => __( 'Product listing Button Settings', 'ti-woocommerce-wishlist' ),
330
+ 'desc' => __( 'These are separate settings for the "Add to Wishlist" button on a product listing (Shop page, categories, etc.). You can also adjust button and text colors, size, etc. in a <code>TI Wishlist > Style Options.</code>', 'ti-woocommerce-wishlist' ),
331
+ 'show_names' => true,
332
+ 'fields' => array(
333
+ array(
334
+ 'type' => 'checkboxonoff',
335
+ 'name' => 'show_in_loop',
336
+ 'text' => __( 'Show in Product Listing', 'ti-woocommerce-wishlist' ),
337
+ 'std' => true,
338
+ 'extra' => array(
339
+ 'tiwl-show' => '.tiwl-buttoncat-button',
340
+ ),
341
+ ),
342
+ array(
343
+ 'type' => 'group',
344
+ 'id' => 'add_to_wishlist_catalog',
345
+ 'class' => 'tiwl-buttoncat-button',
346
+ 'style' => 'border-top: 0px; padding-top: 0px;',
347
+ ),
348
+ array(
349
+ 'type' => 'select',
350
+ 'name' => 'position',
351
+ 'text' => __( 'Button position', 'ti-woocommerce-wishlist' ),
352
+ 'std' => 'after',
353
+ 'options' => array(
354
+ 'after' => __( 'After "Add to Cart" button', 'ti-woocommerce-wishlist' ),
355
+ 'before' => __( 'Before "Add to Cart" button', 'ti-woocommerce-wishlist' ),
356
+ 'above_thumb' => __( 'Above Thumbnail', 'ti-woocommerce-wishlist' ),
357
+ 'shortcode' => __( 'Custom position with code', 'ti-woocommerce-wishlist' ),
358
+ ),
359
+ 'desc' => __( 'Note: if "Custom position with code" option is applied, the "Add to Wishlist" button should be added into template using <code>do_shortcode()</code> function like this:<br /><code>do_shortcode("[ti_wishlists_addtowishlist loop=yes]")</code>', 'ti-woocommerce-wishlist' ),
360
+ ),
361
+ array(
362
+ 'type' => 'select',
363
+ 'name' => 'type',
364
+ 'text' => __( 'Button type', 'ti-woocommerce-wishlist' ),
365
+ 'std' => 'button',
366
+ 'options' => array(
367
+ 'link' => __( 'Link', 'ti-woocommerce-wishlist' ),
368
+ 'button' => __( 'Button', 'ti-woocommerce-wishlist' ),
369
+ ),
370
+ ),
371
+ array(
372
+ 'type' => 'select',
373
+ 'name' => 'icon',
374
+ 'text' => __( '"Add to Wishlist" Icon', 'ti-woocommerce-wishlist' ),
375
+ 'std' => '',
376
+ 'options' => array(
377
+ '' => __( 'None', 'ti-woocommerce-wishlist' ),
378
+ 'heart' => __( 'Heart', 'ti-woocommerce-wishlist' ),
379
+ 'heart-plus' => __( 'Heart+', 'ti-woocommerce-wishlist' ),
380
+ 'custom' => __( 'Custom', 'ti-woocommerce-wishlist' ),
381
+ ),
382
+ 'extra' => array(
383
+ 'tiwl-show' => '.tiwl-buttoncat-icon-custom',
384
+ 'tiwl-hide' => '.tiwl-buttoncat-icon-style',
385
+ 'tiwl-value' => 'custom',
386
+ ),
387
+ ),
388
+ array(
389
+ 'type' => 'uploadfile',
390
+ 'name' => 'icon_upload',
391
+ 'std' => '',
392
+ 'text' => ' ',
393
+ 'class' => 'tiwl-buttoncat-icon-custom',
394
+ 'extra' => array(
395
+ 'button' => array(
396
+ 'value' => __( 'Upload', 'ti-woocommerce-wishlist' ),
397
+ ),
398
+ 'type' => array( 'image' ),
399
+ ),
400
+ ),
401
+ array(
402
+ 'type' => 'select',
403
+ 'name' => 'icon_style',
404
+ 'std' => 'black',
405
+ 'text' => __( '"Add to Wishlist" Icon Color', 'ti-woocommerce-wishlist' ),
406
+ 'options' => array(
407
+ 'black' => __( 'Black', 'ti-woocommerce-wishlist' ),
408
+ 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
409
+ ),
410
+ 'class' => 'tiwl-buttoncat-icon-style',
411
+ ),
412
+ array(
413
+ 'type' => 'checkboxonoff',
414
+ 'name' => 'show_text',
415
+ 'text' => __( 'Show button text', 'ti-woocommerce-wishlist-premium' ),
416
+ 'std' => true,
417
+ 'extra' => array(
418
+ 'tiwl-show' => '.tiwl-button-text-catalog',
419
+ ),
420
+ ),
421
+ array(
422
+ 'type' => 'group',
423
+ 'id' => 'show_text_single',
424
+ 'class' => 'tiwl-button-text-catalog',
425
+ 'style' => 'border-top: 0px; padding-top: 0px;',
426
+ ),
427
+ array(
428
+ 'type' => 'text',
429
+ 'name' => 'text',
430
+ 'text' => __( '"Add to Wishlist" Text', 'ti-woocommerce-wishlist' ),
431
+ 'std' => 'Add to Wishlist',
432
+ ),
433
+ array(
434
+ 'type' => 'text',
435
+ 'name' => 'text_remove',
436
+ 'text' => __( '"Remove from Wishlist" Button Text', 'ti-woocommerce-wishlist' ),
437
+ 'std' => 'Remove from Wishlist',
438
+ 'class' => 'tiwl-button-simple-flow',
439
+ ),
440
+ ),
441
+ ),
442
+ array(
443
+ 'id' => 'product_table',
444
+ 'title' => __( 'Wishlist Product Settings', 'ti-woocommerce-wishlist' ),
445
+ 'desc' => __( 'Following options allows you to choose what information/functionality to show/enable in wishlist table on wishlist page.', 'ti-woocommerce-wishlist' ),
446
+ 'show_names' => true,
447
+ 'fields' => array(
448
+ array(
449
+ 'type' => 'checkboxonoff',
450
+ 'name' => 'add_to_cart',
451
+ 'text' => __( 'Show "Add to Cart" button', 'ti-woocommerce-wishlist' ),
452
+ 'std' => true,
453
+ 'extra' => array( 'tiwl-show' => '.tiwl-table-action-addcart' ),
454
+ ),
455
+ array(
456
+ 'type' => 'text',
457
+ 'name' => 'text_add_to_cart',
458
+ 'text' => __( '"Add to Cart" Text', 'ti-woocommerce-wishlist' ),
459
+ 'std' => 'Add to Cart',
460
+ 'class' => 'tiwl-table-action-addcart',
461
+ ),
462
+ array(
463
+ 'type' => 'checkboxonoff',
464
+ 'name' => 'colm_price',
465
+ 'text' => __( 'Show Unit price', 'ti-woocommerce-wishlist' ),
466
+ 'std' => true,
467
+ ),
468
+ array(
469
+ 'type' => 'checkboxonoff',
470
+ 'name' => 'colm_stock',
471
+ 'text' => __( 'Show Stock status', 'ti-woocommerce-wishlist' ),
472
+ 'std' => true,
473
+ ),
474
+ array(
475
+ 'type' => 'checkboxonoff',
476
+ 'name' => 'colm_date',
477
+ 'text' => __( 'Show Date of addition', 'ti-woocommerce-wishlist' ),
478
+ 'std' => true,
479
+ ),
480
+ ),
481
+ ),
482
+ array(
483
+ 'id' => 'table',
484
+ 'title' => __( 'Wishlist Table Settings', 'ti-woocommerce-wishlist' ),
485
+ 'desc' => __( 'Following options will help user to manage and add products to cart from wishlist table in bulk.', 'ti-woocommerce-wishlist' ),
486
+ 'show_names' => true,
487
+ 'fields' => array(
488
+ array(
489
+ 'type' => 'checkboxonoff',
490
+ 'name' => 'colm_checkbox',
491
+ 'text' => __( 'Show Checkboxes', 'ti-woocommerce-wishlist' ),
492
+ 'std' => true,
493
+ 'extra' => array( 'tiwl-show' => '.tiwl-table-cb-button' ),
494
+ ),
495
+ array(
496
+ 'type' => 'group',
497
+ 'id' => 'cb_button',
498
+ 'class' => 'tiwl-table-cb-button',
499
+ ),
500
+ array(
501
+ 'type' => 'checkboxonoff',
502
+ 'name' => 'colm_actions',
503
+ 'text' => __( 'Show Actions button', 'ti-woocommerce-wishlist' ),
504
+ 'desc' => __( 'Bulk actions drop down at the bottom of wishlist table', 'ti-woocommerce-wishlist' ),
505
+ 'std' => true,
506
+ ),
507
+ array(
508
+ 'type' => 'checkboxonoff',
509
+ 'name' => 'add_select_to_cart',
510
+ 'text' => __( 'Show "Add Selected to Cart" button', 'ti-woocommerce-wishlist' ),
511
+ 'std' => true,
512
+ 'extra' => array( 'tiwl-show' => '.tiwl-table-addcart-sel' ),
513
+ ),
514
+ array(
515
+ 'type' => 'text',
516
+ 'name' => 'text_add_select_to_cart',
517
+ 'text' => __( '"Add Selected to Cart" Button Text', 'ti-woocommerce-wishlist' ),
518
+ 'std' => 'Add Selected to Cart',
519
+ 'class' => 'tiwl-table-addcart-sel',
520
+ ),
521
+ array(
522
+ 'type' => 'group',
523
+ 'id' => '_button',
524
+ ),
525
+ array(
526
+ 'type' => 'checkboxonoff',
527
+ 'name' => 'add_all_to_cart',
528
+ 'text' => __( 'Show "Add All to Cart" button', 'ti-woocommerce-wishlist' ),
529
+ 'std' => true,
530
+ 'extra' => array( 'tiwl-show' => '.tiwl-table-addcart-all' ),
531
+ ),
532
+ array(
533
+ 'type' => 'text',
534
+ 'name' => 'text_add_all_to_cart',
535
+ 'text' => __( '"Add All to Cart" Button Text', 'ti-woocommerce-wishlist' ),
536
+ 'std' => 'Add All to Cart',
537
+ 'class' => 'tiwl-table-addcart-all',
538
+ ),
539
+ ),
540
+ ),
541
+ array(
542
+ 'id' => 'social',
543
+ 'show_names' => true,
544
+ 'fields' => array(
545
+ array(
546
+ 'type' => 'group',
547
+ 'id' => 'social',
548
+ 'desc' => __( 'Following options enable/disable Social share icons below wishlist table on wishlist page. Wishlist owner can easily share their wishlists using this button on social networks. Wishlist privacy should be set to public or shared status, private wishlists can\'t be shared.', 'ti-woocommerce-wishlist' ),
549
+ 'class' => 'tinvwl-info-top',
550
+ ),
551
+ array(
552
+ 'type' => 'html',
553
+ 'name' => 'social',
554
+ 'text' => __( 'Social Networks Sharing Options', 'ti-woocommerce-wishlist' ),
555
+ 'class' => 'tinvwl-header-row tinvwl-line-border',
556
+ ),
557
+ array(
558
+ 'type' => 'checkboxonoff',
559
+ 'name' => 'facebook',
560
+ 'text' => __( 'Show "Facebook" Button', 'ti-woocommerce-wishlist' ),
561
+ 'std' => true,
562
+ ),
563
+ array(
564
+ 'type' => 'checkboxonoff',
565
+ 'name' => 'twitter',
566
+ 'text' => __( 'Show "Twitter" Button', 'ti-woocommerce-wishlist' ),
567
+ 'std' => true,
568
+ ),
569
+ array(
570
+ 'type' => 'checkboxonoff',
571
+ 'name' => 'pinterest',
572
+ 'text' => __( 'Show "Pinterest" Button', 'ti-woocommerce-wishlist' ),
573
+ 'std' => true,
574
+ ),
575
+ array(
576
+ 'type' => 'checkboxonoff',
577
+ 'name' => 'google',
578
+ 'text' => __( 'Show "Google+" Button', 'ti-woocommerce-wishlist' ),
579
+ 'std' => true,
580
+ ),
581
+ array(
582
+ 'type' => 'checkboxonoff',
583
+ 'name' => 'email',
584
+ 'text' => __( 'Show "Share by Email" Button', 'ti-woocommerce-wishlist' ),
585
+ 'std' => true,
586
+ ),
587
+ array(
588
+ 'type' => 'text',
589
+ 'name' => 'share_on',
590
+ 'text' => __( '"Share on" Text', 'ti-woocommerce-wishlist' ),
591
+ 'std' => 'Share on',
592
+ ),
593
+ array(
594
+ 'type' => 'select',
595
+ 'name' => 'icon_style',
596
+ 'text' => __( 'Social Icons Color', 'ti-woocommerce-wishlist' ),
597
+ 'options' => array(
598
+ 'dark' => __( 'Dark', 'ti-woocommerce-wishlist' ),
599
+ 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
600
+ ),
601
+ 'validate' => FILTER_DEFAULT,
602
+ ),
603
+ ),
604
+ ),
605
+ array(
606
+ 'id' => 'topline',
607
+ 'title' => __( 'Wishlist Products Counter', 'ti-woocommerce-wishlist' ),
608
+ 'desc' => sprintf( __( 'Add this shortcode <code>[ti_wishlist_products_counter]</code> anywhere into a page content to show Wishlist Counter.<br/><br/>It can be also added as a widget <code>Wishlist Products Counter</code> under the <a href="%s">Appearance -> Widgets</a> section.', 'ti-woocommerce-wishlist' ), esc_url( admin_url( 'widgets.php' ) ) ),
609
+ 'show_names' => true,
610
+ 'fields' => array(
611
+ array(
612
+ 'type' => 'select',
613
+ 'name' => 'icon',
614
+ 'text' => __( '"Wishlist" Icon', 'ti-woocommerce-wishlist' ),
615
+ 'std' => '',
616
+ 'options' => array(
617
+ '' => __( 'None', 'ti-woocommerce-wishlist' ),
618
+ 'heart' => __( 'Heart', 'ti-woocommerce-wishlist' ),
619
+ 'heart-plus' => __( 'Heart+', 'ti-woocommerce-wishlist' ),
620
+ 'custom' => __( 'Custom', 'ti-woocommerce-wishlist' ),
621
+ ),
622
+ 'desc' => __( 'You can choose from our predefined icons or upload your custom icon. Custom icon size is limited to 16x16 px.', 'ti-woocommerce-wishlist' ),
623
+ 'extra' => array(
624
+ 'tiwl-show' => '.tiwl-dropdown-icon-custom',
625
+ 'tiwl-hide' => '.tiwl-dropdown-icon-style',
626
+ 'tiwl-value' => 'custom',
627
+ ),
628
+ ),
629
+ array(
630
+ 'type' => 'uploadfile',
631
+ 'name' => 'icon_upload',
632
+ 'std' => '',
633
+ 'text' => ' ',
634
+ 'class' => 'tiwl-dropdown-icon-custom',
635
+ 'extra' => array(
636
+ 'button' => array(
637
+ 'value' => __( 'Upload', 'ti-woocommerce-wishlist' ),
638
+ ),
639
+ 'type' => array( 'image' ),
640
+ ),
641
+ ),
642
+ array(
643
+ 'type' => 'select',
644
+ 'name' => 'icon_style',
645
+ 'std' => 'black',
646
+ 'text' => __( '"Wishlist" Icon Color', 'ti-woocommerce-wishlist' ),
647
+ 'options' => array(
648
+ 'black' => __( 'Black', 'ti-woocommerce-wishlist' ),
649
+ 'white' => __( 'White', 'ti-woocommerce-wishlist' ),
650
+ ),
651
+ 'class' => 'tiwl-dropdown-icon-style',
652
+ ),
653
+ array(
654
+ 'type' => 'checkboxonoff',
655
+ 'name' => 'show_text',
656
+ 'text' => __( 'Show counter text', 'ti-woocommerce-wishlist' ),
657
+ 'std' => true,
658
+ 'extra' => array(
659
+ 'tiwl-show' => '.tiwl-dropdown-text',
660
+ ),
661
+ ),
662
+ array(
663
+ 'type' => 'text',
664
+ 'name' => 'text',
665
+ 'text' => __( 'Counter Text', 'ti-woocommerce-wishlist' ),
666
+ 'std' => __( 'Wishlist - ', 'ti-woocommerce-wishlist' ),
667
+ 'class' => 'tiwl-dropdown-text',
668
+ ),
669
+ ),
670
+ ),
671
+ array(
672
+ 'id' => 'save_buttons',
673
+ 'class' => 'only-button',
674
+ 'noform' => true,
675
+ 'fields' => array(
676
+ array(
677
+ 'type' => 'button_submit',
678
+ 'name' => 'setting_save',
679
+ 'std' => '<span><i class="fa fa-check"></i></span>' . __( 'Save Settings', 'ti-woocommerce-wishlist' ),
680
+ 'extra' => array( 'class' => 'tinvwl-btn split status-btn-ok' ),
681
+ ),
682
+ array(
683
+ 'type' => 'button_submit',
684
+ 'name' => 'setting_reset',
685
+ 'std' => '<span><i class="fa fa-times"></i></span>' . __( 'Reset', 'ti-woocommerce-wishlist' ),
686
+ 'extra' => array( 'class' => 'tinvwl-btn split status-btn-ok tinvwl-confirm-reset' ),
687
+ ),
688
+ array(
689
+ 'type' => 'button_submit_quick',
690
+ 'name' => 'setting_save_quick',
691
+ 'std' => '<span><i class="fa fa-floppy-o"></i></span>' . __( 'Save', 'ti-woocommerce-wishlist' ),
692
+ ),
693
+ ),
694
+ ),
695
+ );
696
+ }
697
+
698
+ /**
699
+ * Load value from database
700
+ *
701
+ * @param array $sections Sections array.
702
+ *
703
+ * @return array
704
+ */
705
+ function constructor_load( $sections ) {
706
+ $data = parent::constructor_load( $sections );
707
+ $data['general']['page_wishlist'] = $data['page']['wishlist'];
708
+ $data['general']['processing_autoremove'] = $data['processing']['autoremove'];
709
+ $data['general']['processing_autoremove_anyone'] = $data['processing']['autoremove_anyone'];
710
+
711
+ return $data;
712
+ }
713
+
714
+ /**
715
+ * Save value to database and flush rewrite.
716
+ *
717
+ * @param array $data Post section data.
718
+ */
719
+ function constructor_save( $data ) {
720
+ parent::constructor_save( $data );
721
+ if ( empty( $data ) || ! is_array( $data ) ) {
722
+ return false;
723
+ }
724
+ tinv_update_option( 'page', 'wishlist', $data['general']['page_wishlist'] );
725
+ tinv_update_option( 'processing', 'autoremove', $data['general']['processing_autoremove'] );
726
+ tinv_update_option( 'processing', 'autoremove_anyone', $data['general']['processing_autoremove_anyone'] );
727
+ tinv_update_option( 'processing', 'autoremove_status', 'tinvwl-addcart' );
728
+ if ( filter_input( INPUT_POST, 'save_buttons-setting_reset' ) ) {
729
+ foreach ( $data as $key => $value ) {
730
+ if ( ! in_array( $key, array( 'page' ) ) ) {
731
+ $data[ $key ] = array();
732
+ }
733
+ }
734
+ parent::constructor_save( $data );
735
+ }
736
+ TInvWL_Public_TInvWL::update_rewrite_rules();
737
+ }
738
+
739
+ /**
740
+ * Show Premium Features sections
741
+ */
742
+ function premium_features() {
743
+ TInvWL_View::view( 'premium-features' );
744
+ }
745
+ }
asset/js/public.js CHANGED
@@ -1,545 +1,553 @@
1
- (function ($) {
2
- $.fn.tinvwl_to_wishlist = function (so) {
3
- var sd = {
4
- api_url: window.location.href,
5
- text_create: window.tinvwl_add_to_wishlist['text_create'],
6
- text_already_in: window.tinvwl_add_to_wishlist['text_already_in'],
7
- class: {
8
- dialogbox: '.tinvwl_add_to_select_wishlist',
9
- select: '.tinvwl_wishlist',
10
- newtitle: '.tinvwl_new_input',
11
- dialogbutton: '.tinvwl_button_add'
12
- },
13
- redirectTimer: null,
14
- onPrepareList: function () {},
15
- onGetDialogBox: function () {},
16
- onPrepareDialogBox: function () {
17
- if (!$('body > .tinv-wishlist').length) {
18
- $('body').append($('<div>').addClass('tinv-wishlist'));
19
- }
20
- $(this).appendTo('body > .tinv-wishlist');
21
- },
22
- onCreateWishList: function (wishlist) {
23
- $(this).append($('<option>').html(wishlist.title).attr('value', wishlist.ID).toggleClass('tinv_in_wishlist', wishlist.in));
24
- },
25
- onSelectWishList: function () {},
26
- onDialogShow: function () {
27
- $(this).addClass('tinv-modal-open');
28
- },
29
- onDialogHide: function () {
30
- $(this).removeClass('tinv-modal-open');
31
- },
32
- onInited: function () {},
33
- onClick: function () {
34
- if ($(this).is('.disabled-add-wishlist')) {
35
- return false;
36
- }
37
- if (this.tinvwl_dialog) {
38
- this.tinvwl_dialog.show_list.call(this);
39
- } else {
40
- s.onActionProduct.call(this);
41
- }
42
- },
43
- onPrepareDataAction: function () {},
44
- filterProductAlreadyIn: function (WList) {
45
- var WList = WList || [],
46
- data = {};
47
- $('form.cart[method=post], .woocommerce-variation-add-to-cart').find('input, select').each(function () {
48
- var name_elm = $(this).attr('name'),
49
- type_elm = $(this).attr('type'),
50
- value_elm = $(this).val();
51
- if ('checkbox' === type_elm || 'radio' === type_elm) {
52
- if ($(this).is(':checked')) {
53
- data['form' + name_elm] = value_elm;
54
- }
55
- } else {
56
- data['form' + name_elm] = value_elm;
57
- }
58
- });
59
- data = data['formvariation_id'];
60
- return WList.filter(function (wishlist) {
61
- if ('object' === typeof wishlist.in && 'string' === typeof data) {
62
- var number = parseInt(data);
63
- return 0 <= wishlist.in.indexOf(number);
64
- }
65
- return wishlist.in;
66
- });
67
- },
68
- onMultiProductAlreadyIn: function (WList) {
69
- var WList = WList || [];
70
- WList = s.onPrepareList.call(WList) || WList;
71
- WList = s.filterProductAlreadyIn.call(this, WList) || WList;
72
- $(this).parent().parent().find('.already-in').remove();
73
- var text = '';
74
- switch (WList.length) {
75
- case 0:
76
- break;
77
- default:
78
- var text = $('<ul>');
79
- $.each(WList, function (k, wishlist) {
80
- text.append($('<li>').html($('<a>').html(wishlist.title).attr({
81
- href: wishlist.url
82
- })).attr('value', wishlist.ID));
83
- });
84
- break;
85
- }
86
- if (text.length) {
87
- $(this).closest('.tinv-modal-inner').find('img').after($('<div>').addClass('already-in').html(s.text_already_in + ' ').append(text));
88
- }
89
- },
90
- onAction: {
91
- redirect: function (url) {
92
- if (s.redirectTimer) {
93
- clearTimeout(s.redirectTimer);
94
- }
95
- s.redirectTimer = window.setTimeout(function () {
96
- window.location.href = url;
97
- }, 4000);
98
- },
99
- force_redirect: function (url) {
100
- window.location.href = url;
101
- },
102
- wishlists: function (wishlist) {
103
- $(this).attr('data-tinv-wl-list', wishlist);
104
- },
105
- msg: function (html) {
106
- if (!html) {
107
- return false;
108
- }
109
- var $msg = $(html).eq(0);
110
- if (!$('body > .tinv-wishlist').length) {
111
- $('body').append($('<div>').addClass('tinv-wishlist'));
112
- }
113
- $('body > .tinv-wishlist').append($msg);
114
- $msg.on('click', '.tinv-close-modal, .tinvwl_button_close, .tinv-overlay', function (e) {
115
- e.preventDefault();
116
- $msg.remove();
117
- if (s.redirectTimer) {
118
- clearTimeout(s.redirectTimer);
119
- }
120
- });
121
- },
122
- status: function (status) {
123
- if (status) {
124
- $(this).addClass('tinvwl-product-in-list');
125
- }
126
- },
127
- removed: function (status) {
128
- if (status) {
129
- $(this).removeClass('tinvwl-product-in-list').removeClass('tinvwl-product-make-remove').attr('data-tinv-wl-action', 'addto');
130
- }
131
- },
132
- make_remove: function (status) {
133
- $(this).toggleClass('tinvwl-product-make-remove', status).attr('data-tinv-wl-action', status ? 'remove' : 'addto');
134
- },
135
- fragments: function (data) {
136
- if (typeof wc_cart_fragments_params === 'undefined') {
137
- $.each(data, function (key, value) {
138
- $(key).replaceWith(value);
139
- });
140
- return false;
141
- }
142
- var $supports_html5_storage;
143
- try {
144
- $supports_html5_storage = ('sessionStorage' in window && window.sessionStorage !== null);
145
- window.sessionStorage.setItem('wc', 'test');
146
- window.sessionStorage.removeItem('wc');
147
- window.localStorage.setItem('wc', 'test');
148
- window.localStorage.removeItem('wc');
149
- } catch (err) {
150
- $supports_html5_storage = false;
151
- }
152
- if ($supports_html5_storage) {
153
- try {
154
- var wc_fragments = $.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),
155
- cart_hash_key = wc_cart_fragments_params.ajax_url.toString() + '-wc_cart_hash',
156
- cart_hash = sessionStorage.getItem(cart_hash_key),
157
- cookie_hash = Cookies.get('woocommerce_cart_hash'),
158
- cart_created = sessionStorage.getItem('wc_cart_created');
159
- if (cart_hash === null || cart_hash === undefined || cart_hash === '') {
160
- cart_hash = '';
161
- }
162
- if (cookie_hash === null || cookie_hash === undefined || cookie_hash === '') {
163
- cookie_hash = '';
164
- }
165
- if (cart_hash && (cart_created === null || cart_created === undefined || cart_created === '')) {
166
- throw 'No cart_created';
167
- }
168
- $.each(data, function (key, value) {
169
- wc_fragments[key] = value;
170
- });
171
- localStorage.setItem(cart_hash_key, localStorage.getItem(cart_hash_key) + (new Date()).getTime());
172
- sessionStorage.setItem(cart_hash_key, sessionStorage.getItem(cart_hash_key) + (new Date()).getTime());
173
- sessionStorage.setItem(wc_cart_fragments_params.fragment_name, JSON.stringify(wc_fragments));
174
- if (wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash === cookie_hash) {
175
- $.each(wc_fragments, function (key, value) {
176
- $(key).replaceWith(value);
177
- });
178
- $(document.body).trigger('wc_fragments_loaded');
179
- } else {
180
- throw 'No fragment';
181
- }
182
- } catch (err) {
183
- $(document.body).trigger('wc_fragment_refresh');
184
- }
185
- }
186
- }
187
- }
188
- };
189
- sd.onActionProduct = function (id, name) {
190
- var data = {
191
- form: {},
192
- tinv_wishlist_id: id || '',
193
- tinv_wishlist_name: name || '',
194
- product_type: $(this).attr('data-tinv-wl-producttype'),
195
- product_id: $(this).attr('data-tinv-wl-product') || 0,
196
- product_variation: $(this).attr('data-tinv-wl-productvariation') || 0,
197
- product_action: $(this).attr('data-tinv-wl-action') || 'addto'
198
- },
199
- a = this;
200
- $(a).closest('form.cart[method=post], .woocommerce-variation-add-to-cart').find('input, select, textarea').each(function () {
201
- var name_elm = $(this).attr('name'),
202
- type_elm = $(this).attr('type'),
203
- value_elm = $(this).val(),
204
- count = 10,
205
- ti_merge_value = function (o1, o2) {
206
- if ('object' === typeof o2) {
207
- if ('undefined' === typeof o1) {
208
- o1 = {};
209
- }
210
- for (var i in o2) {
211
- if ('' === i) {
212
- var j = -1;
213
- for (j in o1) {
214
- j = j;
215
- }
216
- j = parseInt(j) + 1;
217
- o1[j] = ti_merge_value(o1[i], o2[i]);
218
- } else {
219
- o1[i] = ti_merge_value(o1[i], o2[i]);
220
- }
221
- }
222
- return o1;
223
- } else {
224
- return o2;
225
- }
226
- };
227
- while (/^(.+)\[([^\[\]]*?)\]$/.test(name_elm) && 0 < count) {
228
- var n_name = name_elm.match(/^(.+)\[([^\[\]]*?)\]$/);
229
- if (3 === n_name.length) {
230
- var _value_elm = {};
231
- _value_elm[n_name[2]] = value_elm;
232
- value_elm = _value_elm;
233
- }
234
- name_elm = n_name[1];
235
- count--;
236
- }
237
- if ('checkbox' === type_elm || 'radio' === type_elm) {
238
- if ($(this).is(':checked')) {
239
- if (!value_elm.length && 'object' !== typeof value_elm) {
240
- value_elm = true;
241
- }
242
- data.form[name_elm] = ti_merge_value(data.form[name_elm], value_elm);
243
- }
244
- } else {
245
- data.form[name_elm] = ti_merge_value(data.form[name_elm], value_elm);
246
- }
247
- });
248
- data = s.onPrepareDataAction.call(a, data) || data;
249
- $.post(s.api_url, data, function (body) {
250
- s.onDialogHide.call(a.tinvwl_dialog);
251
- if ('object' === typeof body) {
252
- for (var k in body) {
253
- if ('function' === typeof s.onAction[k]) {
254
- s.onAction[k].call(a, body[k]);
255
- }
256
- }
257
- } else {
258
- if ('function' === typeof s.onAction['msg']) {
259
- s.onAction['msg'].call(a, body);
260
- }
261
- }
262
- });
263
- };
264
- var s = $.extend(true, {}, sd, so);
265
- return $(this).each(function () {
266
- if (!$(this).attr('data-tinv-wl-list')) {
267
- return false;
268
- }
269
- if (s.dialogbox) {
270
- if (s.dialogbox.length) {
271
- this.tinvwl_dialog = s.dialogbox;
272
- }
273
- }
274
- if (!this.tinvwl_dialog) {
275
- this.tinvwl_dialog = s.onGetDialogBox.call(this);
276
- }
277
- if (!this.tinvwl_dialog) {
278
- var _tinvwl_dialog = $(this).nextAll(s.class.dialogbox).eq(0);
279
- if (_tinvwl_dialog.length) {
280
- this.tinvwl_dialog = _tinvwl_dialog;
281
- }
282
- }
283
- if (this.tinvwl_dialog) {
284
- s.onPrepareDialogBox.call(this.tinvwl_dialog);
285
- if ('function' !== typeof this.tinvwl_dialog.update_list) {
286
- this.tinvwl_dialog.update_list = function (WL) {
287
- var $select = $(this).find(s.class.select).eq(0);
288
- $(this).find(s.class.newtitle).hide().val('');
289
- $select.html('');
290
- $.each(WL, function (k, v) {
291
- s.onCreateWishList.call($select, v);
292
- });
293
- if (s.text_create) {
294
- s.onCreateWishList.call($select, {
295
- ID: '',
296
- title: s.text_create,
297
- in: false
298
- });
299
- }
300
- s.onMultiProductAlreadyIn.call($select, WL);
301
- s.onSelectWishList.call($select, WL);
302
- $(this).find(s.class.newtitle).toggle('' === $select.val());
303
- }
304
- }
305
- if ('function' !== typeof this.tinvwl_dialog.show_list) {
306
- this.tinvwl_dialog.show_list = function () {
307
- var WList = $.parseJSON($(this).attr('data-tinv-wl-list')) || [];
308
- if (WList.length) {
309
- WList = s.onPrepareList.call(WList) || WList;
310
- this.tinvwl_dialog.update_list(WList);
311
- s.onDialogShow.call(this.tinvwl_dialog);
312
- } else {
313
- s.onActionProduct.call(this);
314
- }
315
- }
316
- }
317
- var a = this;
318
- $(this.tinvwl_dialog).find(s.class.dialogbutton).off('click').on('click', function () {
319
- var b = $(a.tinvwl_dialog).find(s.class.select),
320
- c = $(a.tinvwl_dialog).find(s.class.newtitle),
321
- d;
322
- if (b.val() || c.val()) {
323
- s.onActionProduct.call(a, b.val(), c.val());
324
- } else {
325
- d = c.is(':visible') ? c : b;
326
- d.addClass('empty-name-wishlist');
327
- window.setTimeout(function () {
328
- d.removeClass('empty-name-wishlist');
329
- }, 1000);
330
- }
331
- });
332
- }
333
- $(this).off('click').on('click', s.onClick);
334
- s.onInited.call(this, s);
335
- });
336
- };
337
- $(document).ready(function () {
338
- $('body').on('click', '.tinvwl_add_to_wishlist_button', function (e) {
339
- if ($(this).is('.disabled-add-wishlist')) {
340
- e.preventDefault();
341
- window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);
342
- return;
343
- }
344
- if ($(this).is('.inited-add-wishlist')) {
345
- return;
346
- }
347
- $(this).tinvwl_to_wishlist({
348
- onInited: function (s) {
349
- $(this).addClass('inited-add-wishlist');
350
- s.onClick.call(this);
351
- }
352
- });
353
- });
354
- $('.tinvwl_move_product_button').tinvwl_to_wishlist({
355
- class: {
356
- dialogbox: '.tinvwl_wishlist_move',
357
- select: '.tinvwl_wishlist',
358
- newtitle: '.tinvwl_new_input',
359
- dialogbutton: '.tinvwl_button_move'
360
- },
361
- onPrepareDataAction: function (data) {
362
- data.tinv_from_wishlist_id = $(this).attr('data-tinv-wl');
363
- data.tinv_to_wishlist_id = data.tinv_wishlist_id;
364
- if (!data.tinv_wishlist_name) {
365
- data.tinv_wishlist_name = '-';
366
- }
367
- delete data.tinv_wishlist_id;
368
- return data;
369
- },
370
- onPrepareList: function () {
371
- return this.filter(function (a) {
372
- return !a.hide;
373
- });
374
- },
375
- onAction: {
376
- redirect: function (url) {
377
- return window.location.href = url;
378
- }
379
- }
380
- });
381
- $('.global-cb').on('click', function () {
382
- $(this).closest('table').eq(0).find('.product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]').prop('checked', $(this).is(':checked'))
383
- });
384
- });
385
- })(jQuery);
386
- (function ($) {
387
- $.fn.tinvwl_break_submit = function (so) {
388
- var sd = {
389
- selector: 'input, select, textarea',
390
- ifempty: true,
391
- invert: false,
392
- validate: function () {
393
- return $(this).val();
394
- },
395
- rule: function () {
396
- var form_elements = $(this).parents('form').eq(0).find(s.selector),
397
- trigger = s.invert;
398
- if (0 === form_elements.length) {
399
- return s.ifempty;
400
- }
401
- form_elements.each(function () {
402
- if ((trigger && !s.invert) || (!trigger && s.invert)) {
403
- return;
404
- }
405
- trigger = Boolean(s.validate.call($(this)));
406
- });
407
- return trigger;
408
- }
409
- };
410
- var s = $.extend(true, {}, sd, so);
411
- return $(this).each(function () {
412
- $(this).on('click', function (event) {
413
- if (!s.rule.call($(this))) {
414
- event.preventDefault();
415
- }
416
- });
417
- });
418
- };
419
- $(document).ready(function () {
420
- $('.tinvwl-break-input').tinvwl_break_submit({
421
- selector: '.tinvwl-break-input-filed'
422
- });
423
- $('.tinvwl-break-checkbox').tinvwl_break_submit({
424
- selector: 'table td input[type=checkbox]',
425
- validate: function () {
426
- return $(this).is(':checked');
427
- }
428
- });
429
- });
430
- })(jQuery);
431
- (function ($) {
432
- $('.variations_form').each(function () {
433
- var c = $(this),
434
- e = c.find('.tinvwl_add_to_wishlist_button');
435
- if (e.length) {
436
- c.on('hide_variation', function (a) {
437
- a.preventDefault();
438
- e.addClass('disabled-add-wishlist');
439
- }).on('show_variation', function (a, b, d) {
440
- var f = JSON.parse(e.attr('data-tinv-wl-list')),
441
- j = false,
442
- g = '1' == window.tinvwl_add_to_wishlist['simple_flow'];
443
- for (var i in f) {
444
- if (f[i].hasOwnProperty('in') && Array.isArray(f[i]['in']) && -1 < (f[i]['in'] || []).indexOf(b.variation_id)) {
445
- j = true;
446
- }
447
- }
448
- e.toggleClass('tinvwl-product-in-list', j).toggleClass('tinvwl-product-make-remove', (j && g)).attr('data-tinv-wl-action', ((j && g) ? 'remove' : 'addto'));
449
- a.preventDefault();
450
- e.removeClass('disabled-add-wishlist');
451
- });
452
- }
453
- });
454
- })(jQuery);
455
- (function ($) {
456
- $(document).ready(function () {
457
- $.fn.tinvwl_modal = function (so) {
458
- var sd = {
459
- showClass: 'tinv-modal-open',
460
- modal: '.tinv-modal',
461
- onPrepare: function () {
462
- if (!$('body > .tinv-wishlist').length) {
463
- $('body').append($('<div>').addClass('tinv-wishlist'));
464
- }
465
- $(this).appendTo('body > .tinv-wishlist');
466
- }
467
- },
468
- s = $.extend(true, {}, sd, so);
469
- return $(this).each(function () {
470
- var a = $(this),
471
- b = a.next(s.modal);
472
- s.onPrepare.call(b);
473
- a.on('click', function () {
474
- b.addClass(s.showClass);
475
- });
476
- });
477
- };
478
- $('.tinv-modal-btn').tinvwl_modal({});
479
- $('#tinvwl_manage_actions, #tinvwl_product_actions').addClass('form-control').parent().wrapInner('<div class="input-group tinvwl-no-full">').find('button').wrap('<span class="input-group-btn">');
480
- $('.tinv-lists-nav').each(function () {
481
- if (!$.trim($(this).html()).length) {
482
- $(this).remove();
483
- }
484
- });
485
- $('body').on('click', '.social-buttons .social[title!=email]', function (e) {
486
- var newWind = window.open($(this).attr('href'), $(this).attr('title'), "width=420,height=320,resizable=yes,scrollbars=yes,status=yes");
487
- if (newWind) {
488
- newWind.focus();
489
- e.preventDefault();
490
- }
491
- });
492
- $('.tinvwl-select-all').on('click', function (e) {
493
- e.preventDefault();
494
- $(this).parent().parent().find('ul li input[type="checkbox"]').attr('checked', true);
495
- });
496
- $('.tinvwl-select-none').on('click', function (e) {
497
- e.preventDefault();
498
- $(this).parent().parent().find('ul li input[type="checkbox"]').attr('checked', false);
499
- });
500
- $('body').on('click', '.tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close', function (e) {
501
- e.preventDefault();
502
- $(this).parents('.tinv-modal:first').removeClass('tinv-modal-open');
503
- });
504
- $('body').on('click', '.tinv-wishlist .tinvwl-btn-onclick', function (e) {
505
- var url = $(this).data('url');
506
- if (url) {
507
- e.preventDefault();
508
- window.location = $(this).data('url');
509
- }
510
- });
511
- var navigationButton = $('.tinv-wishlist .navigation-button');
512
- if (navigationButton.length) {
513
- navigationButton.each(function () {
514
- var navigationButtons = $(this).find('> li');
515
- if (navigationButtons.length < 5) {
516
- navigationButtons.parent().addClass('tinvwl-btns-count-' + navigationButtons.length);
517
- }
518
- });
519
- }
520
- $('.tinv-login .showlogin').unbind("click").on('click', function (e) {
521
- e.preventDefault();
522
- $(this).closest('.tinv-login').find('.login').toggle();
523
- });
524
- $('.tinv-wishlist table.tinvwl-table-manage-list tfoot td').each(function () {
525
- $(this).toggle(!!$(this).children().not('.look_in').length || !!$(this).children('.look_in').children().length);
526
- });
527
- });
528
- $(document.body).on('wc_fragments_refreshed wc_fragments_loaded', function () {
529
- $('.wishlist_products_counter').toggleClass('wishlist-counter-with-products', '0' != $('.wishlist_products_counter_number').html());
530
- });
531
- $(window).load(function () {
532
- if ($('.tinv-wishlist.woocommerce').length && $('.woocommerce-message').length) {
533
- $(document.body).on('wc_fragments_refreshed.wishlist', function () {
534
- if (typeof wc_cart_fragments_params === 'undefined') {
535
- return false;
536
- }
537
- cart_hash_key = wc_cart_fragments_params.ajax_url.toString() + '-wc_cart_hash';
538
- localStorage.setItem(cart_hash_key, localStorage.getItem(cart_hash_key) + (new Date()).getTime());
539
- sessionStorage.setItem(cart_hash_key, sessionStorage.getItem(cart_hash_key) + (new Date()).getTime());
540
- $(document.body).off('wc_fragments_refreshed.wishlist');
541
- });
542
- $(document.body).trigger('updated_wc_div');
543
- }
544
- });
545
- })(jQuery);
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+ $.fn.tinvwl_to_wishlist = function (so) {
3
+ var sd = {
4
+ api_url: window.location.href,
5
+ text_create: window.tinvwl_add_to_wishlist['text_create'],
6
+ text_already_in: window.tinvwl_add_to_wishlist['text_already_in'],
7
+ class: {
8
+ dialogbox: '.tinvwl_add_to_select_wishlist',
9
+ select: '.tinvwl_wishlist',
10
+ newtitle: '.tinvwl_new_input',
11
+ dialogbutton: '.tinvwl_button_add'
12
+ },
13
+ redirectTimer: null,
14
+ onPrepareList: function () {
15
+ },
16
+ onGetDialogBox: function () {
17
+ },
18
+ onPrepareDialogBox: function () {
19
+ if (!$('body > .tinv-wishlist').length) {
20
+ $('body').append($('<div>').addClass('tinv-wishlist'));
21
+ }
22
+ $(this).appendTo('body > .tinv-wishlist');
23
+ },
24
+ onCreateWishList: function (wishlist) {
25
+ $(this).append($('<option>').html(wishlist.title).attr('value', wishlist.ID).toggleClass('tinv_in_wishlist', wishlist.in));
26
+ },
27
+ onSelectWishList: function () {
28
+ },
29
+ onDialogShow: function () {
30
+ $(this).addClass('tinv-modal-open');
31
+ },
32
+ onDialogHide: function () {
33
+ $(this).removeClass('tinv-modal-open');
34
+ },
35
+ onInited: function () {
36
+ },
37
+ onClick: function () {
38
+ if ($(this).is('.disabled-add-wishlist')) {
39
+ return false;
40
+ }
41
+ if (this.tinvwl_dialog) {
42
+ this.tinvwl_dialog.show_list.call(this);
43
+ } else {
44
+ s.onActionProduct.call(this);
45
+ }
46
+ },
47
+ onPrepareDataAction: function () {
48
+ },
49
+ filterProductAlreadyIn: function (WList) {
50
+ var WList = WList || [],
51
+ data = {};
52
+ $('form.cart[method=post], .woocommerce-variation-add-to-cart').find('input, select').each(function () {
53
+ var name_elm = $(this).attr('name'),
54
+ type_elm = $(this).attr('type'),
55
+ value_elm = $(this).val();
56
+ if ('checkbox' === type_elm || 'radio' === type_elm) {
57
+ if ($(this).is(':checked')) {
58
+ data['form' + name_elm] = value_elm;
59
+ }
60
+ } else {
61
+ data['form' + name_elm] = value_elm;
62
+ }
63
+ });
64
+ data = data['formvariation_id'];
65
+ return WList.filter(function (wishlist) {
66
+ if ('object' === typeof wishlist.in && 'string' === typeof data) {
67
+ var number = parseInt(data);
68
+ return 0 <= wishlist.in.indexOf(number);
69
+ }
70
+ return wishlist.in;
71
+ });
72
+ },
73
+ onMultiProductAlreadyIn: function (WList) {
74
+ var WList = WList || [];
75
+ WList = s.onPrepareList.call(WList) || WList;
76
+ WList = s.filterProductAlreadyIn.call(this, WList) || WList;
77
+ $(this).parent().parent().find('.already-in').remove();
78
+ var text = '';
79
+ switch (WList.length) {
80
+ case 0:
81
+ break;
82
+ default:
83
+ var text = $('<ul>');
84
+ $.each(WList, function (k, wishlist) {
85
+ text.append($('<li>').html($('<a>').html(wishlist.title).attr({
86
+ href: wishlist.url
87
+ })).attr('value', wishlist.ID));
88
+ });
89
+ break;
90
+ }
91
+ if (text.length) {
92
+ $(this).closest('.tinv-modal-inner').find('img').after($('<div>').addClass('already-in').html(s.text_already_in + ' ').append(text));
93
+ }
94
+ },
95
+ onAction: {
96
+ redirect: function (url) {
97
+ if (s.redirectTimer) {
98
+ clearTimeout(s.redirectTimer);
99
+ }
100
+ s.redirectTimer = window.setTimeout(function () {
101
+ window.location.href = url;
102
+ }, 4000);
103
+ },
104
+ force_redirect: function (url) {
105
+ window.location.href = url;
106
+ },
107
+ wishlists: function (wishlist) {
108
+ $(this).attr('data-tinv-wl-list', wishlist);
109
+ },
110
+ msg: function (html) {
111
+ if (!html) {
112
+ return false;
113
+ }
114
+ var $msg = $(html).eq(0);
115
+ if (!$('body > .tinv-wishlist').length) {
116
+ $('body').append($('<div>').addClass('tinv-wishlist'));
117
+ }
118
+ $('body > .tinv-wishlist').append($msg);
119
+ $msg.on('click', '.tinv-close-modal, .tinvwl_button_close, .tinv-overlay', function (e) {
120
+ e.preventDefault();
121
+ $msg.remove();
122
+ if (s.redirectTimer) {
123
+ clearTimeout(s.redirectTimer);
124
+ }
125
+ });
126
+ },
127
+ status: function (status) {
128
+ if (status) {
129
+ $(this).addClass('tinvwl-product-in-list');
130
+ }
131
+ },
132
+ removed: function (status) {
133
+ if (status) {
134
+ $(this).removeClass('tinvwl-product-in-list').removeClass('tinvwl-product-make-remove').attr('data-tinv-wl-action', 'addto');
135
+ }
136
+ },
137
+ make_remove: function (status) {
138
+ $(this).toggleClass('tinvwl-product-make-remove', status).attr('data-tinv-wl-action', status ? 'remove' : 'addto');
139
+ },
140
+ fragments: function (data) {
141
+ if (typeof wc_cart_fragments_params === 'undefined') {
142
+ $.each(data, function (key, value) {
143
+ $(key).replaceWith(value);
144
+ });
145
+ return false;
146
+ }
147
+ var $supports_html5_storage;
148
+ try {
149
+ $supports_html5_storage = ('sessionStorage' in window && window.sessionStorage !== null);
150
+ window.sessionStorage.setItem('wc', 'test');
151
+ window.sessionStorage.removeItem('wc');
152
+ window.localStorage.setItem('wc', 'test');
153
+ window.localStorage.removeItem('wc');
154
+ } catch (err) {
155
+ $supports_html5_storage = false;
156
+ }
157
+ if ($supports_html5_storage) {
158
+ try {
159
+ var wc_fragments = $.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),
160
+ cart_hash_key = wc_cart_fragments_params.ajax_url.toString() + '-wc_cart_hash',
161
+ cart_hash = sessionStorage.getItem(cart_hash_key),
162
+ cookie_hash = Cookies.get('woocommerce_cart_hash'),
163
+ cart_created = sessionStorage.getItem('wc_cart_created');
164
+ if (cart_hash === null || cart_hash === undefined || cart_hash === '') {
165
+ cart_hash = '';
166
+ }
167
+ if (cookie_hash === null || cookie_hash === undefined || cookie_hash === '') {
168
+ cookie_hash = '';
169
+ }
170
+ if (cart_hash && (cart_created === null || cart_created === undefined || cart_created === '')) {
171
+ throw 'No cart_created';
172
+ }
173
+ $.each(data, function (key, value) {
174
+ wc_fragments[key] = value;
175
+ });
176
+ localStorage.setItem(cart_hash_key, localStorage.getItem(cart_hash_key) + (new Date()).getTime());
177
+ sessionStorage.setItem(cart_hash_key, sessionStorage.getItem(cart_hash_key) + (new Date()).getTime());
178
+ sessionStorage.setItem(wc_cart_fragments_params.fragment_name, JSON.stringify(wc_fragments));
179
+ if (wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash === cookie_hash) {
180
+ $.each(wc_fragments, function (key, value) {
181
+ $(key).replaceWith(value);
182
+ });
183
+ $(document.body).trigger('wc_fragments_loaded');
184
+ } else {
185
+ throw 'No fragment';
186
+ }
187
+ } catch (err) {
188
+ $(document.body).trigger('wc_fragment_refresh');
189
+ }
190
+ }
191
+ }
192
+ }
193
+ };
194
+ sd.onActionProduct = function (id, name) {
195
+ var data = {
196
+ form: {},
197
+ tinv_wishlist_id: id || '',
198
+ tinv_wishlist_name: name || '',
199
+ product_type: $(this).attr('data-tinv-wl-producttype'),
200
+ product_id: $(this).attr('data-tinv-wl-product') || 0,
201
+ product_variation: $(this).attr('data-tinv-wl-productvariation') || 0,
202
+ product_action: $(this).attr('data-tinv-wl-action') || 'addto'
203
+ },
204
+ a = this;
205
+ $(a).closest('form.cart[method=post], .woocommerce-variation-add-to-cart, .tinvwl-loop-button-wrapper').find('input, select, textarea').each(function () {
206
+ var name_elm = $(this).attr('name'),
207
+ type_elm = $(this).attr('type'),
208
+ value_elm = $(this).val(),
209
+ count = 10,
210
+ ti_merge_value = function (o1, o2) {
211
+ if ('object' === typeof o2) {
212
+ if ('undefined' === typeof o1) {
213
+ o1 = {};
214
+ }
215
+ for (var i in o2) {
216
+ if ('' === i) {
217
+ var j = -1;
218
+ for (j in o1) {
219
+ j = j;
220
+ }
221
+ j = parseInt(j) + 1;
222
+ o1[j] = ti_merge_value(o1[i], o2[i]);
223
+ } else {
224
+ o1[i] = ti_merge_value(o1[i], o2[i]);
225
+ }
226
+ }
227
+ return o1;
228
+ } else {
229
+ return o2;
230
+ }
231
+ };
232
+ if ('button' === type_elm) {
233
+ return;
234
+ }
235
+ while (/^(.+)\[([^\[\]]*?)\]$/.test(name_elm) && 0 < count) {
236
+ var n_name = name_elm.match(/^(.+)\[([^\[\]]*?)\]$/);
237
+ if (3 === n_name.length) {
238
+ var _value_elm = {};
239
+ _value_elm[n_name[2]] = value_elm;
240
+ value_elm = _value_elm;
241
+ }
242
+ name_elm = n_name[1];
243
+ count--;
244
+ }
245
+ if ('checkbox' === type_elm || 'radio' === type_elm) {
246
+ if ($(this).is(':checked')) {
247
+ if (!value_elm.length && 'object' !== typeof value_elm) {
248
+ value_elm = true;
249
+ }
250
+ data.form[name_elm] = ti_merge_value(data.form[name_elm], value_elm);
251
+ }
252
+ } else {
253
+ data.form[name_elm] = ti_merge_value(data.form[name_elm], value_elm);
254
+ }
255
+ });
256
+ data = s.onPrepareDataAction.call(a, data) || data;
257
+ $.post(s.api_url, data, function (body) {
258
+ s.onDialogHide.call(a.tinvwl_dialog);
259
+ if ('object' === typeof body) {
260
+ for (var k in body) {
261
+ if ('function' === typeof s.onAction[k]) {
262
+ s.onAction[k].call(a, body[k]);
263
+ }
264
+ }
265
+ } else {
266
+ if ('function' === typeof s.onAction['msg']) {
267
+ s.onAction['msg'].call(a, body);
268
+ }
269
+ }
270
+ });
271
+ };
272
+ var s = $.extend(true, {}, sd, so);
273
+ return $(this).each(function () {
274
+ if (!$(this).attr('data-tinv-wl-list')) {
275
+ return false;
276
+ }
277
+ if (s.dialogbox) {
278
+ if (s.dialogbox.length) {
279
+ this.tinvwl_dialog = s.dialogbox;
280
+ }
281
+ }
282
+ if (!this.tinvwl_dialog) {
283
+ this.tinvwl_dialog = s.onGetDialogBox.call(this);
284
+ }
285
+ if (!this.tinvwl_dialog) {
286
+ var _tinvwl_dialog = $(this).nextAll(s.class.dialogbox).eq(0);
287
+ if (_tinvwl_dialog.length) {
288
+ this.tinvwl_dialog = _tinvwl_dialog;
289
+ }
290
+ }
291
+ if (this.tinvwl_dialog) {
292
+ s.onPrepareDialogBox.call(this.tinvwl_dialog);
293
+ if ('function' !== typeof this.tinvwl_dialog.update_list) {
294
+ this.tinvwl_dialog.update_list = function (WL) {
295
+ var $select = $(this).find(s.class.select).eq(0);
296
+ $(this).find(s.class.newtitle).hide().val('');
297
+ $select.html('');
298
+ $.each(WL, function (k, v) {
299
+ s.onCreateWishList.call($select, v);
300
+ });
301
+ if (s.text_create) {
302
+ s.onCreateWishList.call($select, {
303
+ ID: '',
304
+ title: s.text_create,
305
+ in: false
306
+ });
307
+ }
308
+ s.onMultiProductAlreadyIn.call($select, WL);
309
+ s.onSelectWishList.call($select, WL);
310
+ $(this).find(s.class.newtitle).toggle('' === $select.val());
311
+ }
312
+ }
313
+ if ('function' !== typeof this.tinvwl_dialog.show_list) {
314
+ this.tinvwl_dialog.show_list = function () {
315
+ var WList = $.parseJSON($(this).attr('data-tinv-wl-list')) || [];
316
+ if (WList.length) {
317
+ WList = s.onPrepareList.call(WList) || WList;
318
+ this.tinvwl_dialog.update_list(WList);
319
+ s.onDialogShow.call(this.tinvwl_dialog);
320
+ } else {
321
+ s.onActionProduct.call(this);
322
+ }
323
+ }
324
+ }
325
+ var a = this;
326
+ $(this.tinvwl_dialog).find(s.class.dialogbutton).off('click').on('click', function () {
327
+ var b = $(a.tinvwl_dialog).find(s.class.select),
328
+ c = $(a.tinvwl_dialog).find(s.class.newtitle),
329
+ d;
330
+ if (b.val() || c.val()) {
331
+ s.onActionProduct.call(a, b.val(), c.val());
332
+ } else {
333
+ d = c.is(':visible') ? c : b;
334
+ d.addClass('empty-name-wishlist');
335
+ window.setTimeout(function () {
336
+ d.removeClass('empty-name-wishlist');
337
+ }, 1000);
338
+ }
339
+ });
340
+ }
341
+ $(this).off('click').on('click', s.onClick);
342
+ s.onInited.call(this, s);
343
+ });
344
+ };
345
+ $(document).ready(function () {
346
+ $('body').on('click', '.tinvwl_add_to_wishlist_button', function (e) {
347
+ if ($(this).is('.disabled-add-wishlist')) {
348
+ e.preventDefault();
349
+ window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);
350
+ return;
351
+ }
352
+ if ($(this).is('.inited-add-wishlist')) {
353
+ return;
354
+ }
355
+ $(this).tinvwl_to_wishlist({
356
+ onInited: function (s) {
357
+ $(this).addClass('inited-add-wishlist');
358
+ s.onClick.call(this);
359
+ }
360
+ });
361
+ });
362
+ $('.tinvwl_move_product_button').tinvwl_to_wishlist({
363
+ class: {
364
+ dialogbox: '.tinvwl_wishlist_move',
365
+ select: '.tinvwl_wishlist',
366
+ newtitle: '.tinvwl_new_input',
367
+ dialogbutton: '.tinvwl_button_move'
368
+ },
369
+ onPrepareDataAction: function (data) {
370
+ data.tinv_from_wishlist_id = $(this).attr('data-tinv-wl');
371
+ data.tinv_to_wishlist_id = data.tinv_wishlist_id;
372
+ if (!data.tinv_wishlist_name) {
373
+ data.tinv_wishlist_name = '-';
374
+ }
375
+ delete data.tinv_wishlist_id;
376
+ return data;
377
+ },
378
+ onPrepareList: function () {
379
+ return this.filter(function (a) {
380
+ return !a.hide;
381
+ });
382
+ },
383
+ onAction: {
384
+ redirect: function (url) {
385
+ return window.location.href = url;
386
+ }
387
+ }
388
+ });
389
+ $('.global-cb').on('click', function () {
390
+ $(this).closest('table').eq(0).find('.product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]').prop('checked', $(this).is(':checked'))
391
+ });
392
+ });
393
+ })(jQuery);
394
+ (function ($) {
395
+ $.fn.tinvwl_break_submit = function (so) {
396
+ var sd = {
397
+ selector: 'input, select, textarea',
398
+ ifempty: true,
399
+ invert: false,
400
+ validate: function () {
401
+ return $(this).val();
402
+ },
403
+ rule: function () {
404
+ var form_elements = $(this).parents('form').eq(0).find(s.selector),
405
+ trigger = s.invert;
406
+ if (0 === form_elements.length) {
407
+ return s.ifempty;
408
+ }
409
+ form_elements.each(function () {
410
+ if ((trigger && !s.invert) || (!trigger && s.invert)) {
411
+ return;
412
+ }
413
+ trigger = Boolean(s.validate.call($(this)));
414
+ });
415
+ return trigger;
416
+ }
417
+ };
418
+ var s = $.extend(true, {}, sd, so);
419
+ return $(this).each(function () {
420
+ $(this).on('click', function (event) {
421
+ if (!s.rule.call($(this))) {
422
+ event.preventDefault();
423
+ }
424
+ });
425
+ });
426
+ };
427
+ $(document).ready(function () {
428
+ $('.tinvwl-break-input').tinvwl_break_submit({
429
+ selector: '.tinvwl-break-input-filed'
430
+ });
431
+ $('.tinvwl-break-checkbox').tinvwl_break_submit({
432
+ selector: 'table td input[type=checkbox]',
433
+ validate: function () {
434
+ return $(this).is(':checked');
435
+ }
436
+ });
437
+ });
438
+ })(jQuery);
439
+ (function ($) {
440
+ $('.variations_form').each(function () {
441
+ var c = $(this),
442
+ e = c.find('.tinvwl_add_to_wishlist_button');
443
+ if (e.length) {
444
+ c.on('hide_variation', function (a) {
445
+ a.preventDefault();
446
+ e.addClass('disabled-add-wishlist');
447
+ }).on('show_variation', function (a, b, d) {
448
+ var f = JSON.parse(e.attr('data-tinv-wl-list')),
449
+ j = false,
450
+ g = '1' == window.tinvwl_add_to_wishlist['simple_flow'];
451
+ for (var i in f) {
452
+ if (f[i].hasOwnProperty('in') && Array.isArray(f[i]['in']) && -1 < (f[i]['in'] || []).indexOf(b.variation_id)) {
453
+ j = true;
454
+ }
455
+ }
456
+ e.toggleClass('tinvwl-product-in-list', j).toggleClass('tinvwl-product-make-remove', (j && g)).attr('data-tinv-wl-action', ((j && g) ? 'remove' : 'addto'));
457
+ a.preventDefault();
458
+ e.removeClass('disabled-add-wishlist');
459
+ });
460
+ }
461
+ });
462
+ })(jQuery);
463
+ (function ($) {
464
+ $(document).ready(function () {
465
+ $.fn.tinvwl_modal = function (so) {
466
+ var sd = {
467
+ showClass: 'tinv-modal-open',
468
+ modal: '.tinv-modal',
469
+ onPrepare: function () {
470
+ if (!$('body > .tinv-wishlist').length) {
471
+ $('body').append($('<div>').addClass('tinv-wishlist'));
472
+ }
473
+ $(this).appendTo('body > .tinv-wishlist');
474
+ }
475
+ },
476
+ s = $.extend(true, {}, sd, so);
477
+ return $(this).each(function () {
478
+ var a = $(this),
479
+ b = a.next(s.modal);
480
+ s.onPrepare.call(b);
481
+ a.on('click', function () {
482
+ b.addClass(s.showClass);
483
+ });
484
+ });
485
+ };
486
+ $('.tinv-modal-btn').tinvwl_modal({});
487
+ $('#tinvwl_manage_actions, #tinvwl_product_actions').addClass('form-control').parent().wrapInner('<div class="input-group tinvwl-no-full">').find('button').wrap('<span class="input-group-btn">');
488
+ $('.tinv-lists-nav').each(function () {
489
+ if (!$.trim($(this).html()).length) {
490
+ $(this).remove();
491
+ }
492
+ });
493
+ $('body').on('click', '.social-buttons .social[title!=email]', function (e) {
494
+ var newWind = window.open($(this).attr('href'), $(this).attr('title'), "width=420,height=320,resizable=yes,scrollbars=yes,status=yes");
495
+ if (newWind) {
496
+ newWind.focus();
497
+ e.preventDefault();
498
+ }
499
+ });
500
+ $('.tinvwl-select-all').on('click', function (e) {
501
+ e.preventDefault();
502
+ $(this).parent().parent().find('ul li input[type="checkbox"]').attr('checked', true);
503
+ });
504
+ $('.tinvwl-select-none').on('click', function (e) {
505
+ e.preventDefault();
506
+ $(this).parent().parent().find('ul li input[type="checkbox"]').attr('checked', false);
507
+ });
508
+ $('body').on('click', '.tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close', function (e) {
509
+ e.preventDefault();
510
+ $(this).parents('.tinv-modal:first').removeClass('tinv-modal-open');
511
+ });
512
+ $('body').on('click', '.tinv-wishlist .tinvwl-btn-onclick', function (e) {
513
+ var url = $(this).data('url');
514
+ if (url) {
515
+ e.preventDefault();
516
+ window.location = $(this).data('url');
517
+ }
518
+ });
519
+ var navigationButton = $('.tinv-wishlist .navigation-button');
520
+ if (navigationButton.length) {
521
+ navigationButton.each(function () {
522
+ var navigationButtons = $(this).find('> li');
523
+ if (navigationButtons.length < 5) {
524
+ navigationButtons.parent().addClass('tinvwl-btns-count-' + navigationButtons.length);
525
+ }
526
+ });
527
+ }
528
+ $('.tinv-login .showlogin').unbind("click").on('click', function (e) {
529
+ e.preventDefault();
530
+ $(this).closest('.tinv-login').find('.login').toggle();
531
+ });
532
+ $('.tinv-wishlist table.tinvwl-table-manage-list tfoot td').each(function () {
533
+ $(this).toggle(!!$(this).children().not('.look_in').length || !!$(this).children('.look_in').children().length);
534
+ });
535
+ });
536
+ $(document.body).on('wc_fragments_refreshed wc_fragments_loaded', function () {
537
+ $('.wishlist_products_counter').toggleClass('wishlist-counter-with-products', '0' != $('.wishlist_products_counter_number').html());
538
+ });
539
+ $(window).on('load', function () {
540
+ if ($('.tinv-wishlist.woocommerce').length && $('.woocommerce-message').length) {
541
+ $(document.body).on('wc_fragments_refreshed.wishlist', function () {
542
+ if (typeof wc_cart_fragments_params === 'undefined') {
543
+ return false;
544
+ }
545
+ cart_hash_key = wc_cart_fragments_params.ajax_url.toString() + '-wc_cart_hash';
546
+ localStorage.setItem(cart_hash_key, localStorage.getItem(cart_hash_key) + (new Date()).getTime());
547
+ sessionStorage.setItem(cart_hash_key, sessionStorage.getItem(cart_hash_key) + (new Date()).getTime());
548
+ $(document.body).off('wc_fragments_refreshed.wishlist');
549
+ });
550
+ $(document.body).trigger('updated_wc_div');
551
+ }
552
+ });
553
+ })(jQuery);
asset/js/public.min.js CHANGED
@@ -1 +1 @@
1
- (function($){$.fn.tinvwl_to_wishlist=function(so){var sd={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(){if(!$('body > .tinv-wishlist').length){$('body').append($('<div>').addClass('tinv-wishlist'));} $(this).appendTo('body > .tinv-wishlist');},onCreateWishList:function(wishlist){$(this).append($('<option>').html(wishlist.title).attr('value',wishlist.ID).toggleClass('tinv_in_wishlist',wishlist.in));},onSelectWishList:function(){},onDialogShow:function(){$(this).addClass('tinv-modal-open');},onDialogHide:function(){$(this).removeClass('tinv-modal-open');},onInited:function(){},onClick:function(){if($(this).is('.disabled-add-wishlist')){return false;} if(this.tinvwl_dialog){this.tinvwl_dialog.show_list.call(this);}else{s.onActionProduct.call(this);}},onPrepareDataAction:function(){},filterProductAlreadyIn:function(WList){var WList=WList||[],data={};$('form.cart[method=post], .woocommerce-variation-add-to-cart').find('input, select').each(function(){var name_elm=$(this).attr('name'),type_elm=$(this).attr('type'),value_elm=$(this).val();if('checkbox'===type_elm||'radio'===type_elm){if($(this).is(':checked')){data['form'+name_elm]=value_elm;}}else{data['form'+name_elm]=value_elm;}});data=data['formvariation_id'];return WList.filter(function(wishlist){if('object'===typeof wishlist.in&&'string'===typeof data){var number=parseInt(data);return 0<=wishlist.in.indexOf(number);} return wishlist.in;});},onMultiProductAlreadyIn:function(WList){var WList=WList||[];WList=s.onPrepareList.call(WList)||WList;WList=s.filterProductAlreadyIn.call(this,WList)||WList;$(this).parent().parent().find('.already-in').remove();var text='';switch(WList.length){case 0:break;default:var text=$('<ul>');$.each(WList,function(k,wishlist){text.append($('<li>').html($('<a>').html(wishlist.title).attr({href:wishlist.url})).attr('value',wishlist.ID));});break;} if(text.length){$(this).closest('.tinv-modal-inner').find('img').after($('<div>').addClass('already-in').html(s.text_already_in+' ').append(text));}},onAction:{redirect:function(url){if(s.redirectTimer){clearTimeout(s.redirectTimer);} s.redirectTimer=window.setTimeout(function(){window.location.href=url;},4000);},force_redirect:function(url){window.location.href=url;},wishlists:function(wishlist){$(this).attr('data-tinv-wl-list',wishlist);},msg:function(html){if(!html){return false;} var $msg=$(html).eq(0);if(!$('body > .tinv-wishlist').length){$('body').append($('<div>').addClass('tinv-wishlist'));} $('body > .tinv-wishlist').append($msg);$msg.on('click','.tinv-close-modal, .tinvwl_button_close, .tinv-overlay',function(e){e.preventDefault();$msg.remove();if(s.redirectTimer){clearTimeout(s.redirectTimer);}});},status:function(status){if(status){$(this).addClass('tinvwl-product-in-list');}},removed:function(status){if(status){$(this).removeClass('tinvwl-product-in-list').removeClass('tinvwl-product-make-remove').attr('data-tinv-wl-action','addto');}},make_remove:function(status){$(this).toggleClass('tinvwl-product-make-remove',status).attr('data-tinv-wl-action',status?'remove':'addto');},fragments:function(data){if(typeof wc_cart_fragments_params==='undefined'){$.each(data,function(key,value){$(key).replaceWith(value);});return false;} var $supports_html5_storage;try{$supports_html5_storage=('sessionStorage'in window&&window.sessionStorage!==null);window.sessionStorage.setItem('wc','test');window.sessionStorage.removeItem('wc');window.localStorage.setItem('wc','test');window.localStorage.removeItem('wc');}catch(err){$supports_html5_storage=false;} if($supports_html5_storage){try{var wc_fragments=$.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),cart_hash_key=wc_cart_fragments_params.ajax_url.toString()+'-wc_cart_hash',cart_hash=sessionStorage.getItem(cart_hash_key),cookie_hash=Cookies.get('woocommerce_cart_hash'),cart_created=sessionStorage.getItem('wc_cart_created');if(cart_hash===null||cart_hash===undefined||cart_hash===''){cart_hash='';} if(cookie_hash===null||cookie_hash===undefined||cookie_hash===''){cookie_hash='';} if(cart_hash&&(cart_created===null||cart_created===undefined||cart_created==='')){throw'No cart_created';} $.each(data,function(key,value){wc_fragments[key]=value;});localStorage.setItem(cart_hash_key,localStorage.getItem(cart_hash_key)+(new Date()).getTime());sessionStorage.setItem(cart_hash_key,sessionStorage.getItem(cart_hash_key)+(new Date()).getTime());sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(wc_fragments));if(wc_fragments&&wc_fragments['div.widget_shopping_cart_content']&&cart_hash===cookie_hash){$.each(wc_fragments,function(key,value){$(key).replaceWith(value);});$(document.body).trigger('wc_fragments_loaded');}else{throw'No fragment';}}catch(err){$(document.body).trigger('wc_fragment_refresh');}}}}};sd.onActionProduct=function(id,name){var data={form:{},tinv_wishlist_id:id||'',tinv_wishlist_name:name||'',product_type:$(this).attr('data-tinv-wl-producttype'),product_id:$(this).attr('data-tinv-wl-product')||0,product_variation:$(this).attr('data-tinv-wl-productvariation')||0,product_action:$(this).attr('data-tinv-wl-action')||'addto'},a=this;$(a).closest('form.cart[method=post], .woocommerce-variation-add-to-cart').find('input, select, textarea').each(function(){var name_elm=$(this).attr('name'),type_elm=$(this).attr('type'),value_elm=$(this).val(),count=10,ti_merge_value=function(o1,o2){if('object'===typeof o2){if('undefined'===typeof o1){o1={};} for(var i in o2){if(''===i){var j=-1;for(j in o1){j=j;} j=parseInt(j)+1;o1[j]=ti_merge_value(o1[i],o2[i]);}else{o1[i]=ti_merge_value(o1[i],o2[i]);}} return o1;}else{return o2;}};while(/^(.+)\[([^\[\]]*?)\]$/.test(name_elm)&&0<count){var n_name=name_elm.match(/^(.+)\[([^\[\]]*?)\]$/);if(3===n_name.length){var _value_elm={};_value_elm[n_name[2]]=value_elm;value_elm=_value_elm;} name_elm=n_name[1];count--;} if('checkbox'===type_elm||'radio'===type_elm){if($(this).is(':checked')){if(!value_elm.length&&'object'!==typeof value_elm){value_elm=true;} data.form[name_elm]=ti_merge_value(data.form[name_elm],value_elm);}}else{data.form[name_elm]=ti_merge_value(data.form[name_elm],value_elm);}});data=s.onPrepareDataAction.call(a,data)||data;$.post(s.api_url,data,function(body){s.onDialogHide.call(a.tinvwl_dialog);if('object'===typeof body){for(var k in body){if('function'===typeof s.onAction[k]){s.onAction[k].call(a,body[k]);}}}else{if('function'===typeof s.onAction['msg']){s.onAction['msg'].call(a,body);}}});};var s=$.extend(true,{},sd,so);return $(this).each(function(){if(!$(this).attr('data-tinv-wl-list')){return false;} if(s.dialogbox){if(s.dialogbox.length){this.tinvwl_dialog=s.dialogbox;}} if(!this.tinvwl_dialog){this.tinvwl_dialog=s.onGetDialogBox.call(this);} if(!this.tinvwl_dialog){var _tinvwl_dialog=$(this).nextAll(s.class.dialogbox).eq(0);if(_tinvwl_dialog.length){this.tinvwl_dialog=_tinvwl_dialog;}} if(this.tinvwl_dialog){s.onPrepareDialogBox.call(this.tinvwl_dialog);if('function'!==typeof this.tinvwl_dialog.update_list){this.tinvwl_dialog.update_list=function(WL){var $select=$(this).find(s.class.select).eq(0);$(this).find(s.class.newtitle).hide().val('');$select.html('');$.each(WL,function(k,v){s.onCreateWishList.call($select,v);});if(s.text_create){s.onCreateWishList.call($select,{ID:'',title:s.text_create,in:false});} s.onMultiProductAlreadyIn.call($select,WL);s.onSelectWishList.call($select,WL);$(this).find(s.class.newtitle).toggle(''===$select.val());}} if('function'!==typeof this.tinvwl_dialog.show_list){this.tinvwl_dialog.show_list=function(){var WList=$.parseJSON($(this).attr('data-tinv-wl-list'))||[];if(WList.length){WList=s.onPrepareList.call(WList)||WList;this.tinvwl_dialog.update_list(WList);s.onDialogShow.call(this.tinvwl_dialog);}else{s.onActionProduct.call(this);}}} var a=this;$(this.tinvwl_dialog).find(s.class.dialogbutton).off('click').on('click',function(){var b=$(a.tinvwl_dialog).find(s.class.select),c=$(a.tinvwl_dialog).find(s.class.newtitle),d;if(b.val()||c.val()){s.onActionProduct.call(a,b.val(),c.val());}else{d=c.is(':visible')?c:b;d.addClass('empty-name-wishlist');window.setTimeout(function(){d.removeClass('empty-name-wishlist');},1000);}});} $(this).off('click').on('click',s.onClick);s.onInited.call(this,s);});};$(document).ready(function(){$('body').on('click','.tinvwl_add_to_wishlist_button',function(e){if($(this).is('.disabled-add-wishlist')){e.preventDefault();window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);return;} if($(this).is('.inited-add-wishlist')){return;} $(this).tinvwl_to_wishlist({onInited:function(s){$(this).addClass('inited-add-wishlist');s.onClick.call(this);}});});$('.tinvwl_move_product_button').tinvwl_to_wishlist({class:{dialogbox:'.tinvwl_wishlist_move',select:'.tinvwl_wishlist',newtitle:'.tinvwl_new_input',dialogbutton:'.tinvwl_button_move'},onPrepareDataAction:function(data){data.tinv_from_wishlist_id=$(this).attr('data-tinv-wl');data.tinv_to_wishlist_id=data.tinv_wishlist_id;if(!data.tinv_wishlist_name){data.tinv_wishlist_name='-';} delete data.tinv_wishlist_id;return data;},onPrepareList:function(){return this.filter(function(a){return!a.hide;});},onAction:{redirect:function(url){return window.location.href=url;}}});$('.global-cb').on('click',function(){$(this).closest('table').eq(0).find('.product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]').prop('checked',$(this).is(':checked'))});});})(jQuery);(function($){$.fn.tinvwl_break_submit=function(so){var sd={selector:'input, select, textarea',ifempty:true,invert:false,validate:function(){return $(this).val();},rule:function(){var form_elements=$(this).parents('form').eq(0).find(s.selector),trigger=s.invert;if(0===form_elements.length){return s.ifempty;} form_elements.each(function(){if((trigger&&!s.invert)||(!trigger&&s.invert)){return;} trigger=Boolean(s.validate.call($(this)));});return trigger;}};var s=$.extend(true,{},sd,so);return $(this).each(function(){$(this).on('click',function(event){if(!s.rule.call($(this))){event.preventDefault();}});});};$(document).ready(function(){$('.tinvwl-break-input').tinvwl_break_submit({selector:'.tinvwl-break-input-filed'});$('.tinvwl-break-checkbox').tinvwl_break_submit({selector:'table td input[type=checkbox]',validate:function(){return $(this).is(':checked');}});});})(jQuery);(function($){$('.variations_form').each(function(){var c=$(this),e=c.find('.tinvwl_add_to_wishlist_button');if(e.length){c.on('hide_variation',function(a){a.preventDefault();e.addClass('disabled-add-wishlist');}).on('show_variation',function(a,b,d){var f=JSON.parse(e.attr('data-tinv-wl-list')),j=false,g='1'==window.tinvwl_add_to_wishlist['simple_flow'];for(var i in f){if(f[i].hasOwnProperty('in')&&Array.isArray(f[i]['in'])&&-1<(f[i]['in']||[]).indexOf(b.variation_id)){j=true;}} e.toggleClass('tinvwl-product-in-list',j).toggleClass('tinvwl-product-make-remove',(j&&g)).attr('data-tinv-wl-action',((j&&g)?'remove':'addto'));a.preventDefault();e.removeClass('disabled-add-wishlist');});}});})(jQuery);(function($){$(document).ready(function(){$.fn.tinvwl_modal=function(so){var sd={showClass:'tinv-modal-open',modal:'.tinv-modal',onPrepare:function(){if(!$('body > .tinv-wishlist').length){$('body').append($('<div>').addClass('tinv-wishlist'));} $(this).appendTo('body > .tinv-wishlist');}},s=$.extend(true,{},sd,so);return $(this).each(function(){var a=$(this),b=a.next(s.modal);s.onPrepare.call(b);a.on('click',function(){b.addClass(s.showClass);});});};$('.tinv-modal-btn').tinvwl_modal({});$('#tinvwl_manage_actions, #tinvwl_product_actions').addClass('form-control').parent().wrapInner('<div class="input-group tinvwl-no-full">').find('button').wrap('<span class="input-group-btn">');$('.tinv-lists-nav').each(function(){if(!$.trim($(this).html()).length){$(this).remove();}});$('body').on('click','.social-buttons .social[title!=email]',function(e){var newWind=window.open($(this).attr('href'),$(this).attr('title'),"width=420,height=320,resizable=yes,scrollbars=yes,status=yes");if(newWind){newWind.focus();e.preventDefault();}});$('.tinvwl-select-all').on('click',function(e){e.preventDefault();$(this).parent().parent().find('ul li input[type="checkbox"]').attr('checked',true);});$('.tinvwl-select-none').on('click',function(e){e.preventDefault();$(this).parent().parent().find('ul li input[type="checkbox"]').attr('checked',false);});$('body').on('click','.tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close',function(e){e.preventDefault();$(this).parents('.tinv-modal:first').removeClass('tinv-modal-open');});$('body').on('click','.tinv-wishlist .tinvwl-btn-onclick',function(e){var url=$(this).data('url');if(url){e.preventDefault();window.location=$(this).data('url');}});var navigationButton=$('.tinv-wishlist .navigation-button');if(navigationButton.length){navigationButton.each(function(){var navigationButtons=$(this).find('> li');if(navigationButtons.length<5){navigationButtons.parent().addClass('tinvwl-btns-count-'+navigationButtons.length);}});} $('.tinv-login .showlogin').unbind("click").on('click',function(e){e.preventDefault();$(this).closest('.tinv-login').find('.login').toggle();});$('.tinv-wishlist table.tinvwl-table-manage-list tfoot td').each(function(){$(this).toggle(!!$(this).children().not('.look_in').length||!!$(this).children('.look_in').children().length);});});$(document.body).on('wc_fragments_refreshed wc_fragments_loaded',function(){$('.wishlist_products_counter').toggleClass('wishlist-counter-with-products','0'!=$('.wishlist_products_counter_number').html());});$(window).load(function(){if($('.tinv-wishlist.woocommerce').length&&$('.woocommerce-message').length){$(document.body).on('wc_fragments_refreshed.wishlist',function(){if(typeof wc_cart_fragments_params==='undefined'){return false;} cart_hash_key=wc_cart_fragments_params.ajax_url.toString()+'-wc_cart_hash';localStorage.setItem(cart_hash_key,localStorage.getItem(cart_hash_key)+(new Date()).getTime());sessionStorage.setItem(cart_hash_key,sessionStorage.getItem(cart_hash_key)+(new Date()).getTime());$(document.body).off('wc_fragments_refreshed.wishlist');});$(document.body).trigger('updated_wc_div');}});})(jQuery);
1
+ !function(t){t.fn.tinvwl_to_wishlist=function(i){var n={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(){t("body > .tinv-wishlist").length||t("body").append(t("<div>").addClass("tinv-wishlist")),t(this).appendTo("body > .tinv-wishlist")},onCreateWishList:function(i){t(this).append(t("<option>").html(i.title).attr("value",i.ID).toggleClass("tinv_in_wishlist",i.in))},onSelectWishList:function(){},onDialogShow:function(){t(this).addClass("tinv-modal-open")},onDialogHide:function(){t(this).removeClass("tinv-modal-open")},onInited:function(){},onClick:function(){if(t(this).is(".disabled-add-wishlist"))return!1;this.tinvwl_dialog?this.tinvwl_dialog.show_list.call(this):e.onActionProduct.call(this)},onPrepareDataAction:function(){},filterProductAlreadyIn:function(i){i=i||[];var n={};return t("form.cart[method=post], .woocommerce-variation-add-to-cart").find("input, select").each(function(){var i=t(this).attr("name"),e=t(this).attr("type"),o=t(this).val();"checkbox"===e||"radio"===e?t(this).is(":checked")&&(n["form"+i]=o):n["form"+i]=o}),n=n.formvariation_id,i.filter(function(t){if("object"==typeof t.in&&"string"==typeof n){var i=parseInt(n);return 0<=t.in.indexOf(i)}return t.in})},onMultiProductAlreadyIn:function(i){i=i||[];i=e.onPrepareList.call(i)||i,i=e.filterProductAlreadyIn.call(this,i)||i,t(this).parent().parent().find(".already-in").remove();var n="";switch(i.length){case 0:break;default:n=t("<ul>");t.each(i,function(i,e){n.append(t("<li>").html(t("<a>").html(e.title).attr({href:e.url})).attr("value",e.ID))})}n.length&&t(this).closest(".tinv-modal-inner").find("img").after(t("<div>").addClass("already-in").html(e.text_already_in+" ").append(n))},onAction:{redirect:function(t){e.redirectTimer&&clearTimeout(e.redirectTimer),e.redirectTimer=window.setTimeout(function(){window.location.href=t},4e3)},force_redirect:function(t){window.location.href=t},wishlists:function(i){t(this).attr("data-tinv-wl-list",i)},msg:function(i){if(!i)return!1;var n=t(i).eq(0);t("body > .tinv-wishlist").length||t("body").append(t("<div>").addClass("tinv-wishlist")),t("body > .tinv-wishlist").append(n),n.on("click",".tinv-close-modal, .tinvwl_button_close, .tinv-overlay",function(t){t.preventDefault(),n.remove(),e.redirectTimer&&clearTimeout(e.redirectTimer)})},status:function(i){i&&t(this).addClass("tinvwl-product-in-list")},removed:function(i){i&&t(this).removeClass("tinvwl-product-in-list").removeClass("tinvwl-product-make-remove").attr("data-tinv-wl-action","addto")},make_remove:function(i){t(this).toggleClass("tinvwl-product-make-remove",i).attr("data-tinv-wl-action",i?"remove":"addto")},fragments:function(i){if("undefined"==typeof wc_cart_fragments_params)return t.each(i,function(i,n){t(i).replaceWith(n)}),!1;var n;try{n="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){n=!1}if(n)try{var e=t.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),o=wc_cart_fragments_params.ajax_url.toString()+"-wc_cart_hash",a=sessionStorage.getItem(o),l=Cookies.get("woocommerce_cart_hash"),s=sessionStorage.getItem("wc_cart_created");if(null!=a&&""!==a||(a=""),null!=l&&""!==l||(l=""),a&&(null==s||""===s))throw"No cart_created";if(t.each(i,function(t,i){e[t]=i}),localStorage.setItem(o,localStorage.getItem(o)+(new Date).getTime()),sessionStorage.setItem(o,sessionStorage.getItem(o)+(new Date).getTime()),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(e)),!e||!e["div.widget_shopping_cart_content"]||a!==l)throw"No fragment";t.each(e,function(i,n){t(i).replaceWith(n)}),t(document.body).trigger("wc_fragments_loaded")}catch(i){t(document.body).trigger("wc_fragment_refresh")}}},onActionProduct:function(i,n){var o={form:{},tinv_wishlist_id:i||"",tinv_wishlist_name:n||"",product_type:t(this).attr("data-tinv-wl-producttype"),product_id:t(this).attr("data-tinv-wl-product")||0,product_variation:t(this).attr("data-tinv-wl-productvariation")||0,product_action:t(this).attr("data-tinv-wl-action")||"addto"},a=this;t(a).closest("form.cart[method=post], .woocommerce-variation-add-to-cart, .tinvwl-loop-button-wrapper").find("input, select, textarea").each(function(){var i=t(this).attr("name"),n=t(this).attr("type"),e=t(this).val(),a=10,l=function(t,i){if("object"==typeof i){for(var n in void 0===t&&(t={}),i)if(""===n){var e=-1;for(e in t)e=e;t[e=parseInt(e)+1]=l(t[n],i[n])}else t[n]=l(t[n],i[n]);return t}return i};if("button"!==n){for(;/^(.+)\[([^\[\]]*?)\]$/.test(i)&&0<a;){var s=i.match(/^(.+)\[([^\[\]]*?)\]$/);if(3===s.length){var r={};r[s[2]]=e,e=r}i=s[1],a--}"checkbox"===n||"radio"===n?t(this).is(":checked")&&(e.length||"object"==typeof e||(e=!0),o.form[i]=l(o.form[i],e)):o.form[i]=l(o.form[i],e)}}),o=e.onPrepareDataAction.call(a,o)||o,t.post(e.api_url,o,function(t){if(e.onDialogHide.call(a.tinvwl_dialog),"object"==typeof t)for(var i in t)"function"==typeof e.onAction[i]&&e.onAction[i].call(a,t[i]);else"function"==typeof e.onAction.msg&&e.onAction.msg.call(a,t)})}},e=t.extend(!0,{},n,i);return t(this).each(function(){if(!t(this).attr("data-tinv-wl-list"))return!1;if(e.dialogbox&&e.dialogbox.length&&(this.tinvwl_dialog=e.dialogbox),this.tinvwl_dialog||(this.tinvwl_dialog=e.onGetDialogBox.call(this)),!this.tinvwl_dialog){var i=t(this).nextAll(e.class.dialogbox).eq(0);i.length&&(this.tinvwl_dialog=i)}if(this.tinvwl_dialog){e.onPrepareDialogBox.call(this.tinvwl_dialog),"function"!=typeof this.tinvwl_dialog.update_list&&(this.tinvwl_dialog.update_list=function(i){var n=t(this).find(e.class.select).eq(0);t(this).find(e.class.newtitle).hide().val(""),n.html(""),t.each(i,function(t,i){e.onCreateWishList.call(n,i)}),e.text_create&&e.onCreateWishList.call(n,{ID:"",title:e.text_create,in:!1}),e.onMultiProductAlreadyIn.call(n,i),e.onSelectWishList.call(n,i),t(this).find(e.class.newtitle).toggle(""===n.val())}),"function"!=typeof this.tinvwl_dialog.show_list&&(this.tinvwl_dialog.show_list=function(){var i=t.parseJSON(t(this).attr("data-tinv-wl-list"))||[];i.length?(i=e.onPrepareList.call(i)||i,this.tinvwl_dialog.update_list(i),e.onDialogShow.call(this.tinvwl_dialog)):e.onActionProduct.call(this)});var n=this;t(this.tinvwl_dialog).find(e.class.dialogbutton).off("click").on("click",function(){var i,o=t(n.tinvwl_dialog).find(e.class.select),a=t(n.tinvwl_dialog).find(e.class.newtitle);o.val()||a.val()?e.onActionProduct.call(n,o.val(),a.val()):((i=a.is(":visible")?a:o).addClass("empty-name-wishlist"),window.setTimeout(function(){i.removeClass("empty-name-wishlist")},1e3))})}t(this).off("click").on("click",e.onClick),e.onInited.call(this,e)})},t(document).ready(function(){t("body").on("click",".tinvwl_add_to_wishlist_button",function(i){if(t(this).is(".disabled-add-wishlist"))return i.preventDefault(),void window.alert(tinvwl_add_to_wishlist.i18n_make_a_selection_text);t(this).is(".inited-add-wishlist")||t(this).tinvwl_to_wishlist({onInited:function(i){t(this).addClass("inited-add-wishlist"),i.onClick.call(this)}})}),t(".tinvwl_move_product_button").tinvwl_to_wishlist({class:{dialogbox:".tinvwl_wishlist_move",select:".tinvwl_wishlist",newtitle:".tinvwl_new_input",dialogbutton:".tinvwl_button_move"},onPrepareDataAction:function(i){return i.tinv_from_wishlist_id=t(this).attr("data-tinv-wl"),i.tinv_to_wishlist_id=i.tinv_wishlist_id,i.tinv_wishlist_name||(i.tinv_wishlist_name="-"),delete i.tinv_wishlist_id,i},onPrepareList:function(){return this.filter(function(t){return!t.hide})},onAction:{redirect:function(t){return window.location.href=t}}}),t(".global-cb").on("click",function(){t(this).closest("table").eq(0).find(".product-cb input[type=checkbox], .wishlist-cb input[type=checkbox]").prop("checked",t(this).is(":checked"))})})}(jQuery),function(t){t.fn.tinvwl_break_submit=function(i){var n={selector:"input, select, textarea",ifempty:!0,invert:!1,validate:function(){return t(this).val()},rule:function(){var i=t(this).parents("form").eq(0).find(e.selector),n=e.invert;return 0===i.length?e.ifempty:(i.each(function(){n&&!e.invert||!n&&e.invert||(n=Boolean(e.validate.call(t(this))))}),n)}},e=t.extend(!0,{},n,i);return t(this).each(function(){t(this).on("click",function(i){e.rule.call(t(this))||i.preventDefault()})})},t(document).ready(function(){t(".tinvwl-break-input").tinvwl_break_submit({selector:".tinvwl-break-input-filed"}),t(".tinvwl-break-checkbox").tinvwl_break_submit({selector:"table td input[type=checkbox]",validate:function(){return t(this).is(":checked")}})})}(jQuery),function(t){t(".variations_form").each(function(){var i=t(this),n=i.find(".tinvwl_add_to_wishlist_button");n.length&&i.on("hide_variation",function(t){t.preventDefault(),n.addClass("disabled-add-wishlist")}).on("show_variation",function(t,i,e){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(t){t(document).ready(function(){t.fn.tinvwl_modal=function(i){var n={showClass:"tinv-modal-open",modal:".tinv-modal",onPrepare:function(){t("body > .tinv-wishlist").length||t("body").append(t("<div>").addClass("tinv-wishlist")),t(this).appendTo("body > .tinv-wishlist")}},e=t.extend(!0,{},n,i);return t(this).each(function(){var i=t(this),n=i.next(e.modal);e.onPrepare.call(n),i.on("click",function(){n.addClass(e.showClass)})})},t(".tinv-modal-btn").tinvwl_modal({}),t("#tinvwl_manage_actions, #tinvwl_product_actions").addClass("form-control").parent().wrapInner('<div class="input-group tinvwl-no-full">').find("button").wrap('<span class="input-group-btn">'),t(".tinv-lists-nav").each(function(){t.trim(t(this).html()).length||t(this).remove()}),t("body").on("click",".social-buttons .social[title!=email]",function(i){var n=window.open(t(this).attr("href"),t(this).attr("title"),"width=420,height=320,resizable=yes,scrollbars=yes,status=yes");n&&(n.focus(),i.preventDefault())}),t(".tinvwl-select-all").on("click",function(i){i.preventDefault(),t(this).parent().parent().find('ul li input[type="checkbox"]').attr("checked",!0)}),t(".tinvwl-select-none").on("click",function(i){i.preventDefault(),t(this).parent().parent().find('ul li input[type="checkbox"]').attr("checked",!1)}),t("body").on("click",".tinv-wishlist .tinv-overlay, .tinv-wishlist .tinv-close-modal, .tinv-wishlist .tinvwl_button_close",function(i){i.preventDefault(),t(this).parents(".tinv-modal:first").removeClass("tinv-modal-open")}),t("body").on("click",".tinv-wishlist .tinvwl-btn-onclick",function(i){t(this).data("url")&&(i.preventDefault(),window.location=t(this).data("url"))});var i=t(".tinv-wishlist .navigation-button");i.length&&i.each(function(){var i=t(this).find("> li");i.length<5&&i.parent().addClass("tinvwl-btns-count-"+i.length)}),t(".tinv-login .showlogin").unbind("click").on("click",function(i){i.preventDefault(),t(this).closest(".tinv-login").find(".login").toggle()}),t(".tinv-wishlist table.tinvwl-table-manage-list tfoot td").each(function(){t(this).toggle(!!t(this).children().not(".look_in").length||!!t(this).children(".look_in").children().length)})}),t(document.body).on("wc_fragments_refreshed wc_fragments_loaded",function(){t(".wishlist_products_counter").toggleClass("wishlist-counter-with-products","0"!=t(".wishlist_products_counter_number").html())}),t(window).on("load",function(){t(".tinv-wishlist.woocommerce").length&&t(".woocommerce-message").length&&(t(document.body).on("wc_fragments_refreshed.wishlist",function(){if("undefined"==typeof wc_cart_fragments_params)return!1;cart_hash_key=wc_cart_fragments_params.ajax_url.toString()+"-wc_cart_hash",localStorage.setItem(cart_hash_key,localStorage.getItem(cart_hash_key)+(new Date).getTime()),sessionStorage.setItem(cart_hash_key,sessionStorage.getItem(cart_hash_key)+(new Date).getTime()),t(document.body).off("wc_fragments_refreshed.wishlist")}),t(document.body).trigger("updated_wc_div"))})}(jQuery);
includes/product.helper.php CHANGED
@@ -1,586 +1,657 @@
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 $_n;
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
- * @global wpdb $wpdb
48
- * @param array $wishlist Object wishlist.
49
- * @param string $plugin_name Plugin name.
50
- */
51
- function __construct( $wishlist = array(), $plugin_name = TINVWL_PREFIX ) {
52
- global $wpdb;
53
-
54
- $this->wishlist = (array) $wishlist;
55
- $this->_n = $plugin_name;
56
- $this->table = sprintf( '%s%s_%s', $wpdb->prefix, $this->_n, 'items' );
57
- $this->user = $this->wishlist_author();
58
- if ( empty( $this->user ) ) {
59
- $user = wp_get_current_user();
60
- if ( $user->exists() ) {
61
- $this->user = $user->ID;
62
- }
63
- }
64
- }
65
-
66
- /**
67
- * Get wishlist id
68
- *
69
- * @return int
70
- */
71
- function wishlist_id() {
72
- if ( is_array( $this->wishlist ) && array_key_exists( 'ID', $this->wishlist ) ) {
73
- return $this->wishlist['ID'];
74
- }
75
- return 0;
76
- }
77
-
78
- /**
79
- * Get author wishlist
80
- *
81
- * @return int
82
- */
83
- function wishlist_author() {
84
- if ( is_array( $this->wishlist ) && array_key_exists( 'author', $this->wishlist ) ) {
85
- return $this->wishlist['author'];
86
- }
87
- return 0;
88
- }
89
-
90
- /**
91
- * Add\Update product
92
- *
93
- * @param array $data Object product.
94
- * @param array $meta Object meta form data.
95
- * @return boolean
96
- */
97
- function add_product( $data = array(), $meta = array() ) {
98
- $_data = filter_var_array( $data, array(
99
- 'product_id' => FILTER_VALIDATE_INT,
100
- 'variation_id' => FILTER_VALIDATE_INT,
101
- 'wishlist_id' => FILTER_VALIDATE_INT,
102
- 'quantity' => FILTER_VALIDATE_INT,
103
- ) );
104
- if ( empty( $_data['quantity'] ) ) {
105
- $_data['quantity'] = 1;
106
- }
107
- if ( empty( $_data['wishlist_id'] ) ) {
108
- $_data['wishlist_id'] = $this->wishlist_id();
109
- }
110
- $product_data = $this->check_product( $_data['product_id'], $_data['variation_id'], $_data['wishlist_id'], $meta );
111
- if ( false === $product_data ) {
112
- return false;
113
- }
114
- if ( $product_data ) {
115
- $data['quantity'] = $product_data['quantity'] + $_data['quantity'];
116
- return $this->update( $data, $meta );
117
- } else {
118
- return $this->add( $data, $meta );
119
- }
120
- }
121
-
122
- /**
123
- * Add product
124
- *
125
- * @global wpdb $wpdb
126
- * @param array $data Object product.
127
- * @param array $meta Object meta form data.
128
- * @return boolean
129
- */
130
- function add( $data = array(), $meta = array() ) {
131
- $default = array(
132
- 'author' => $this->user,
133
- 'date' => date( 'Y-m-d H:i:s' ),
134
- 'in_stock' => false,
135
- 'price' => 0,
136
- 'product_id' => 0,
137
- 'quantity' => 1,
138
- 'variation_id' => 0,
139
- 'wishlist_id' => $this->wishlist_id(),
140
- );
141
- $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_add_field', array(
142
- 'author' => FILTER_VALIDATE_INT,
143
- 'product_id' => FILTER_VALIDATE_INT,
144
- 'quantity' => FILTER_VALIDATE_INT,
145
- 'variation_id' => FILTER_VALIDATE_INT,
146
- 'wishlist_id' => FILTER_VALIDATE_INT,
147
- ) ) );
148
- $data = array_filter( $data );
149
-
150
- $data = tinv_array_merge( $default, $data );
151
-
152
- if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
153
- return false;
154
- }
155
-
156
- $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
157
-
158
- if ( $data['quantity'] <= 0 || ! $product_data ) {
159
- return false;
160
- }
161
-
162
- if ( $product_data->is_sold_individually() ) {
163
- $data['quantity'] = 1;
164
- }
165
-
166
- $data = apply_filters( 'tinvwl_wishlist_product_add', $data );
167
- $data['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() ) );
168
- $data['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
169
- $data['in_stock'] = $product_data->is_in_stock();
170
- $data['price'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price() );
171
- $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
172
-
173
- global $wpdb;
174
- if ( $wpdb->insert( $this->table, $data ) ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
175
- $id = $wpdb->insert_id;
176
- return $id;
177
- }
178
- return false;
179
- }
180
-
181
- /**
182
- * Get products by wishlist
183
- *
184
- * @param array $data Request.
185
- * @return array
186
- */
187
- function get_wishlist( $data = array() ) {
188
- if ( ! array_key_exists( 'wishlist_id', $data ) ) {
189
- $data['wishlist_id'] = $this->wishlist_id();
190
- }
191
- if ( empty( $data['wishlist_id'] ) ) {
192
- return array();
193
- }
194
-
195
- return $this->get( $data );
196
- }
197
-
198
- /**
199
- * Check existing product
200
- *
201
- * @param integer $product_id Product id.
202
- * @param integer $variation_id Product variaton id.
203
- * @param integer $wishlist_id If exist wishlist object, you can put 0.
204
- * @param array $meta Object meta form data.
205
- * @return mixed
206
- */
207
- function check_product( $product_id, $variation_id = 0, $wishlist_id = 0, $meta = array() ) {
208
- $product_id = absint( $product_id );
209
- $variation_id = absint( $variation_id );
210
- $wishlist_id = absint( $wishlist_id );
211
-
212
- if ( empty( $wishlist_id ) ) {
213
- $wishlist_id = $this->wishlist_id();
214
- }
215
- if ( empty( $wishlist_id ) || empty( $product_id ) ) {
216
- return false;
217
- }
218
-
219
- $product_data = $this->product_data( $product_id, $variation_id );
220
-
221
- if ( ! $product_data ) {
222
- return false;
223
- }
224
-
225
- $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() ) );
226
- $variation_id = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
227
-
228
- $products = $this->get( array(
229
- 'product_id' => $product_id,
230
- 'variation_id' => $variation_id,
231
- 'wishlist_id' => $wishlist_id,
232
- 'formdata' => $this->prepare_save_meta( $meta, $product_id, $variation_id ),
233
- 'count' => 1,
234
- 'external' => false,
235
- ) );
236
-
237
- return array_shift( $products );
238
- }
239
-
240
- /**
241
- * Get products
242
- *
243
- * @global wpdb $wpdb
244
- * @param array $data Request.
245
- * @return array
246
- */
247
- function get( $data = array() ) {
248
- global $wpdb;
249
-
250
- $default = array(
251
- 'count' => 10,
252
- 'field' => null,
253
- 'offset' => 0,
254
- 'order' => 'ASC',
255
- 'order_by' => 'in_stock',
256
- 'external' => true,
257
- 'sql' => '',
258
- );
259
-
260
- foreach ( $default as $_k => $_v ) {
261
- if ( array_key_exists( $_k, $data ) ) {
262
- $default[ $_k ] = $data[ $_k ];
263
- unset( $data[ $_k ] );
264
- }
265
- }
266
-
267
- $default['offset'] = absint( $default['offset'] );
268
- $default['count'] = absint( $default['count'] );
269
- if ( is_array( $default['field'] ) ) {
270
- $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
271
- } elseif ( is_string( $default['field'] ) ) {
272
- $default['field'] = array( 'ID', $default['field'] );
273
- $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
274
- } else {
275
- $default['field'] = '*';
276
- }
277
- $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
278
-
279
- $where = '1';
280
- if ( ! empty( $data ) && is_array( $data ) ) {
281
- if ( array_key_exists( 'meta', $data ) ) {
282
- $product_id = $variation_id = 0;
283
- if ( array_key_exists( 'product_id', $data ) ) {
284
- $product_id = $data['product_id'];
285
- }
286
- if ( array_key_exists( 'variation_id', $data ) ) {
287
- $variation_id = $data['variation_id'];
288
- }
289
- $data['formdata'] = trim( $wpdb->prepare( '%s', $this->prepare_save_meta( $data['meta'], $product_id, $variation_id ) ), "'" );
290
- unset( $data['meta'] );
291
- }
292
- foreach ( $data as $f => $v ) {
293
- $s = is_array( $v ) ? ' IN ' : '=';
294
- if ( is_array( $v ) ) {
295
- foreach ( $v as $_f => $_v ) {
296
- $v[ $_f ] = $wpdb->prepare( '%s', $_v );
297
- }
298
- $v = implode( ',', $v );
299
- $v = "($v)";
300
- } else {
301
- $v = $wpdb->prepare( '%s', $v );
302
- }
303
- $data[ $f ] = sprintf( '`%s`%s%s', $f, $s, $v );
304
- }
305
- $where = implode( ' AND ', $data );
306
- $sql .= ' WHERE ' . $where;
307
- }
308
-
309
- $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
310
- if ( ! empty( $default['sql'] ) ) {
311
- $replacer = $replace = array();
312
- $replace[0] = '{table}';
313
- $replacer[0] = $this->table;
314
- $replace[1] = '{where}';
315
- $replacer[1] = $where;
316
-
317
- foreach ( $default as $key => $value ) {
318
- $i = count( $replace );
319
-
320
- $replace[ $i ] = '{' . $key . '}';
321
- $replacer[ $i ] = $value;
322
- }
323
-
324
- $sql = str_replace( $replace, $replacer, $default['sql'] );
325
- }
326
- $products = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
327
-
328
- if ( empty( $products ) ) {
329
- return array();
330
- }
331
-
332
- foreach ( $products as $k => $product ) {
333
- if ( empty( $default['sql'] ) ) {
334
- $product = filter_var_array( $product, array(
335
- 'ID' => FILTER_VALIDATE_INT,
336
- 'wishlist_id' => FILTER_VALIDATE_INT,
337
- 'product_id' => FILTER_VALIDATE_INT,
338
- 'variation_id' => FILTER_VALIDATE_INT,
339
- 'author' => FILTER_VALIDATE_INT,
340
- 'date' => FILTER_DEFAULT,
341
- 'formdata' => FILTER_DEFAULT,
342
- 'quantity' => FILTER_VALIDATE_INT,
343
- 'price' => FILTER_SANITIZE_NUMBER_FLOAT,
344
- 'in_stock' => FILTER_VALIDATE_BOOLEAN,
345
- ) );
346
- if ( ! tinv_get_option( 'general', 'quantity_func' ) ) {
347
- $product['quantity'] = 1;
348
- }
349
- }
350
- if ( $default['external'] ) {
351
- $product_data = $this->product_data( $product['variation_id'], $product['product_id'] );
352
- if ( $product_data ) {
353
- $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() ) );
354
- $product['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
355
- } else {
356
- unset( $products[ $k ] );
357
- continue;
358
- }
359
- $product['data'] = $product_data;
360
- }
361
- $product['meta'] = array();
362
- if ( array_key_exists( 'formdata', $product ) ) {
363
- $meta = $product['formdata'];
364
- unset( $product['formdata'] );
365
-
366
- $product['meta'] = $this->prepare_retrun_meta( $meta, $product['product_id'], $product['variation_id'], $product['quantity'] );
367
- }
368
- $products[ $k ] = apply_filters( 'tinvwl_wishlist_product_get', $product );
369
- }
370
- return $products;
371
- }
372
-
373
- /**
374
- * Get product info
375
- *
376
- * @param integer $product_id Product id.
377
- * @param integer $variation_id Product variation id.
378
- * @return mixed
379
- */
380
- function product_data( $product_id, $variation_id = 0 ) {
381
- $product_id = absint( $product_id );
382
- $variation_id = absint( $variation_id );
383
-
384
- if ( 'product_variation' == get_post_type( $product_id ) ) { // WPCS: loose comparison ok.
385
- $variation_id = $product_id;
386
- $product_id = wp_get_post_parent_id( $variation_id );
387
- }
388
-
389
- $product_data = wc_get_product( $variation_id ? $variation_id : $product_id );
390
-
391
- if ( ! $product_data || 'trash' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->post->post_status : get_post( $product_data->get_id() )->post_status ) ) {
392
- return null;
393
- }
394
-
395
- $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 ) ) );
396
- return $product_data;
397
- }
398
-
399
- /**
400
- * Update product
401
- *
402
- * @global wpdb $wpdb
403
- * @param array $data Object product.
404
- * @param array $meta Object meta form data.
405
- * @return boolean
406
- */
407
- function update( $data = array(), $meta = array() ) {
408
- if ( empty( $meta ) && array_key_exists( 'meta', $data ) && ! empty( $data['meta'] ) ) {
409
- $meta = $data['meta'];
410
- }
411
-
412
- $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_update_field', array(
413
- 'product_id' => FILTER_VALIDATE_INT,
414
- 'quantity' => FILTER_VALIDATE_INT,
415
- 'variation_id' => FILTER_VALIDATE_INT,
416
- 'wishlist_id' => FILTER_VALIDATE_INT,
417
- 'author' => FILTER_VALIDATE_INT,
418
- ) ) );
419
- $data = array_filter( $data );
420
-
421
- if ( ! array_key_exists( 'wishlist_id', $data ) ) {
422
- $data['wishlist_id'] = $this->wishlist_id();
423
- }
424
- if ( ! array_key_exists( 'variation_id', $data ) ) {
425
- $data['variation_id'] = 0;
426
- }
427
-
428
- if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
429
- return false;
430
- }
431
- $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
432
- if ( ! $product_data ) {
433
- return false;
434
- }
435
-
436
- if ( $product_data->is_sold_individually() ) {
437
- $data['quantity'] = 1;
438
- }
439
-
440
- $data = apply_filters( 'tinvwl_wishlist_product_update', $data );
441
- $data['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() ) );
442
- $data['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
443
- $data['in_stock'] = $product_data->is_in_stock();
444
- $data['price'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price();
445
-
446
- global $wpdb;
447
- return false !== $wpdb->update( $this->table, $data, array(
448
- 'product_id' => $data['product_id'],
449
- 'variation_id' => $data['variation_id'],
450
- 'wishlist_id' => $data['wishlist_id'],
451
- 'formdata' => $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] ),
452
- ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
453
- }
454
-
455
- /**
456
- * Remove product from wishlist
457
- *
458
- * @global wpdb $wpdb
459
- * @param integer $wishlist_id If exist wishlist object, you can put 0.
460
- * @param integer $product_id Product id.
461
- * @param integer $variation_id Product variation id.
462
- * @param array $meta Object meta form data.
463
- * @return boolean
464
- */
465
- function remove_product_from_wl( $wishlist_id = 0, $product_id = 0, $variation_id = 0, $meta = array() ) {
466
- global $wpdb;
467
- if ( empty( $wishlist_id ) ) {
468
- $wishlist_id = $this->wishlist_id();
469
- }
470
- if ( empty( $wishlist_id ) ) {
471
- return false;
472
- }
473
- if ( empty( $product_id ) ) {
474
- return false !== $wpdb->delete( $this->table, array( 'wishlist_id' => $wishlist_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
475
- }
476
- $product_data = $this->product_data( $product_id, $variation_id );
477
- if ( ! $product_data ) {
478
- return false;
479
- }
480
- $data = array(
481
- 'wishlist_id' => $wishlist_id,
482
- '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() ) ),
483
- 'variation_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ),
484
- );
485
- $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
486
- $result = false !== $wpdb->delete( $this->table, $data ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
487
- if ( $result ) {
488
- 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 ) ) );
489
- }
490
- return $result;
491
- }
492
-
493
- /**
494
- * Remove product
495
- *
496
- * @global wpdb $wpdb
497
- * @param integer $product_id Product id.
498
- * @return boolean
499
- */
500
- function remove_product( $product_id = 0 ) {
501
- if ( empty( $product_id ) ) {
502
- return false;
503
- }
504
-
505
- global $wpdb;
506
- $result = false !== $wpdb->delete( $this->table, array( 'product_id' => $product_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
507
- if ( $result ) {
508
- do_action( 'tinvwl_wishlist_product_removed_by_product', $product_id );
509
- }
510
- return $result;
511
- }
512
-
513
- /**
514
- * Remove product by ID
515
- *
516
- * @global wpdb $wpdb
517
- * @param integer $id Product id.
518
- * @return boolean
519
- */
520
- function remove( $id = 0 ) {
521
- if ( empty( $id ) ) {
522
- return false;
523
- }
524
-
525
- global $wpdb;
526
- $result = false !== $wpdb->delete( $this->table, array( 'ID' => $id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
527
- if ( $result ) {
528
- do_action( 'tinvwl_wishlist_product_removed_by_id', $id );
529
- }
530
- return $result;
531
- }
532
-
533
- /**
534
- * Prepare to save meta in database
535
- *
536
- * @param array $meta Meta array.
537
- * @param ineger $product_id Woocommerce product ID.
538
- * @param ineger $variation_id Woocommerce product variation ID.
539
- * @return string
540
- */
541
- function prepare_save_meta( $meta = array(), $product_id = 0, $variation_id = 0 ) {
542
- if ( ! is_array( $meta ) ) {
543
- $meta = array();
544
- }
545
- $meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
546
- foreach ( array( 'add-to-cart', 'product_id', 'variation_id', 'quantity', 'undefined', 'product_sku' ) as $field ) {
547
- if ( array_key_exists( $field, $meta ) ) {
548
- unset( $meta[ $field ] );
549
- }
550
- }
551
- $meta = array_filter( $meta );
552
- if ( empty( $meta ) ) {
553
- return '';
554
- }
555
- ksort( $meta );
556
- return json_encode( $meta );
557
- }
558
-
559
- /**
560
- * Convert meta string to array
561
- *
562
- * @param string $meta Meta array.
563
- * @param integer $product_id Product ID.
564
- * @param integer $variation_id Variation product ID.
565
- * @param integer $quantity Quantity product.
566
- * @return array
567
- */
568
- function prepare_retrun_meta( $meta = '', $product_id = 0, $variation_id = 0, $quantity = 1 ) {
569
- if ( empty( $meta ) ) {
570
- return array();
571
- }
572
- $meta = @json_decode( $meta, true );
573
- if ( empty( $meta ) || ! is_array( $meta ) ) {
574
- return array();
575
- }
576
- if ( ! empty( $product_id ) ) {
577
- $meta['add-to-cart'] = $product_id;
578
- $meta['product_id'] = $product_id;
579
- $meta['quantity'] = $quantity;
580
- if ( ! empty( $variation_id ) ) {
581
- $meta['variation_id'] = $variation_id;
582
- }
583
- }
584
- return apply_filters( 'tinvwl_wishlist_product_unprepare_meta', $meta );
585
- }
586
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 $_n;
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
+ * @global wpdb $wpdb
48
+ *
49
+ * @param array $wishlist Object wishlist.
50
+ * @param string $plugin_name Plugin name.
51
+ */
52
+ function __construct( $wishlist = array(), $plugin_name = TINVWL_PREFIX ) {
53
+ global $wpdb;
54
+
55
+ $this->wishlist = (array) $wishlist;
56
+ $this->_n = $plugin_name;
57
+ $this->table = sprintf( '%s%s_%s', $wpdb->prefix, $this->_n, 'items' );
58
+ $this->user = $this->wishlist_author();
59
+ if ( empty( $this->user ) ) {
60
+ $user = wp_get_current_user();
61
+ if ( $user->exists() ) {
62
+ $this->user = $user->ID;
63
+ }
64
+ }
65
+
66
+ add_filter( 'tinvwl_addtowishlist_add_form', array( $this, 'clean_meta' ), 10, 1 );
67
+ }
68
+
69
+ /**
70
+ * Get wishlist id
71
+ *
72
+ * @return int
73
+ */
74
+ function wishlist_id() {
75
+ if ( is_array( $this->wishlist ) && array_key_exists( 'ID', $this->wishlist ) ) {
76
+ return $this->wishlist['ID'];
77
+ }
78
+
79
+ return 0;
80
+ }
81
+
82
+ /**
83
+ * Get author wishlist
84
+ *
85
+ * @return int
86
+ */
87
+ function wishlist_author() {
88
+ if ( is_array( $this->wishlist ) && array_key_exists( 'author', $this->wishlist ) ) {
89
+ return $this->wishlist['author'];
90
+ }
91
+
92
+ return 0;
93
+ }
94
+
95
+ /**
96
+ * Add\Update product
97
+ *
98
+ * @param array $data Object product.
99
+ * @param array $meta Object meta form data.
100
+ *
101
+ * @return boolean
102
+ */
103
+ function add_product( $data = array(), $meta = array() ) {
104
+ $_data = filter_var_array( $data, array(
105
+ 'product_id' => FILTER_VALIDATE_INT,
106
+ 'variation_id' => FILTER_VALIDATE_INT,
107
+ 'wishlist_id' => FILTER_VALIDATE_INT,
108
+ 'quantity' => FILTER_VALIDATE_INT,
109
+ ) );
110
+ if ( empty( $_data['quantity'] ) ) {
111
+ $_data['quantity'] = 1;
112
+ }
113
+ if ( empty( $_data['wishlist_id'] ) ) {
114
+ $_data['wishlist_id'] = $this->wishlist_id();
115
+ }
116
+ $product_data = $this->check_product( $_data['product_id'], $_data['variation_id'], $_data['wishlist_id'], $meta );
117
+ if ( false === $product_data ) {
118
+ return false;
119
+ }
120
+ if ( $product_data ) {
121
+ $data['quantity'] = $product_data['quantity'] + $_data['quantity'];
122
+
123
+ return $this->update( $data, $meta );
124
+ } else {
125
+ return $this->add( $data, $meta );
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Add product
131
+ *
132
+ * @global wpdb $wpdb
133
+ *
134
+ * @param array $data Object product.
135
+ * @param array $meta Object meta form data.
136
+ *
137
+ * @return boolean
138
+ */
139
+ function add( $data = array(), $meta = array() ) {
140
+ $default = array(
141
+ 'author' => $this->user,
142
+ 'date' => date( 'Y-m-d H:i:s' ),
143
+ 'in_stock' => false,
144
+ 'price' => 0,
145
+ 'product_id' => 0,
146
+ 'quantity' => 1,
147
+ 'variation_id' => 0,
148
+ 'wishlist_id' => $this->wishlist_id(),
149
+ );
150
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_add_field', array(
151
+ 'author' => FILTER_VALIDATE_INT,
152
+ 'product_id' => FILTER_VALIDATE_INT,
153
+ 'quantity' => FILTER_VALIDATE_INT,
154
+ 'variation_id' => FILTER_VALIDATE_INT,
155
+ 'wishlist_id' => FILTER_VALIDATE_INT,
156
+ ) ) );
157
+ $data = array_filter( $data );
158
+
159
+ $data = tinv_array_merge( $default, $data );
160
+
161
+ if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
162
+ return false;
163
+ }
164
+
165
+ $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
166
+
167
+ if ( $data['quantity'] <= 0 || ! $product_data ) {
168
+ return false;
169
+ }
170
+
171
+ if ( $product_data->is_sold_individually() ) {
172
+ $data['quantity'] = 1;
173
+ }
174
+
175
+ $data = apply_filters( 'tinvwl_wishlist_product_add', $data );
176
+ $data['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() ) );
177
+ $data['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
178
+ $data['in_stock'] = $product_data->is_in_stock();
179
+ $data['price'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price() );
180
+ $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
181
+
182
+ global $wpdb;
183
+ if ( $wpdb->insert( $this->table, $data ) ) { // @codingStandardsIgnoreLine WordPress.VIP.DirectDatabaseQuery.DirectQuery
184
+ $id = $wpdb->insert_id;
185
+
186
+ return $id;
187
+ }
188
+
189
+ return false;
190
+ }
191
+
192
+ /**
193
+ * Get products by wishlist
194
+ *
195
+ * @param array $data Request.
196
+ *
197
+ * @return array
198
+ */
199
+ function get_wishlist( $data = array() ) {
200
+ if ( ! array_key_exists( 'wishlist_id', $data ) ) {
201
+ $data['wishlist_id'] = $this->wishlist_id();
202
+ }
203
+ if ( empty( $data['wishlist_id'] ) ) {
204
+ return array();
205
+ }
206
+
207
+ return $this->get( $data );
208
+ }
209
+
210
+ /**
211
+ * Check existing product
212
+ *
213
+ * @param integer $product_id Product id.
214
+ * @param integer $variation_id Product variaton id.
215
+ * @param integer $wishlist_id If exist wishlist object, you can put 0.
216
+ * @param array $meta Object meta form data.
217
+ *
218
+ * @return mixed
219
+ */
220
+ function check_product( $product_id, $variation_id = 0, $wishlist_id = 0, $meta = array() ) {
221
+ $product_id = absint( $product_id );
222
+ $variation_id = absint( $variation_id );
223
+ $wishlist_id = absint( $wishlist_id );
224
+
225
+ if ( empty( $wishlist_id ) ) {
226
+ $wishlist_id = $this->wishlist_id();
227
+ }
228
+ if ( empty( $wishlist_id ) || empty( $product_id ) ) {
229
+ return false;
230
+ }
231
+
232
+ $product_data = $this->product_data( $product_id, $variation_id );
233
+
234
+ if ( ! $product_data ) {
235
+ return false;
236
+ }
237
+
238
+ $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() ) );
239
+ $variation_id = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
240
+
241
+ $products = $this->get( array(
242
+ 'product_id' => $product_id,
243
+ 'variation_id' => $variation_id,
244
+ 'wishlist_id' => $wishlist_id,
245
+ 'formdata' => $this->prepare_save_meta( $meta, $product_id, $variation_id ),
246
+ 'count' => 1,
247
+ 'external' => false,
248
+ ) );
249
+
250
+ return array_shift( $products );
251
+ }
252
+
253
+ /**
254
+ * Get products
255
+ *
256
+ * @global wpdb $wpdb
257
+ *
258
+ * @param array $data Request.
259
+ *
260
+ * @return array
261
+ */
262
+ function get( $data = array() ) {
263
+ global $wpdb;
264
+
265
+ $default = array(
266
+ 'count' => 10,
267
+ 'field' => null,
268
+ 'offset' => 0,
269
+ 'order' => 'ASC',
270
+ 'order_by' => 'in_stock',
271
+ 'external' => true,
272
+ 'sql' => '',
273
+ );
274
+
275
+ foreach ( $default as $_k => $_v ) {
276
+ if ( array_key_exists( $_k, $data ) ) {
277
+ $default[ $_k ] = $data[ $_k ];
278
+ unset( $data[ $_k ] );
279
+ }
280
+ }
281
+
282
+ $default['offset'] = absint( $default['offset'] );
283
+ $default['count'] = absint( $default['count'] );
284
+ if ( is_array( $default['field'] ) ) {
285
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
286
+ } elseif ( is_string( $default['field'] ) ) {
287
+ $default['field'] = array( 'ID', $default['field'] );
288
+ $default['field'] = '`' . implode( '`,`', $default['field'] ) . '`';
289
+ } else {
290
+ $default['field'] = '*';
291
+ }
292
+ $sql = "SELECT {$default[ 'field' ]} FROM `{$this->table}`";
293
+
294
+ $where = '1';
295
+ if ( ! empty( $data ) && is_array( $data ) ) {
296
+ if ( array_key_exists( 'meta', $data ) ) {
297
+ $product_id = $variation_id = 0;
298
+ if ( array_key_exists( 'product_id', $data ) ) {
299
+ $product_id = $data['product_id'];
300
+ }
301
+ if ( array_key_exists( 'variation_id', $data ) ) {
302
+ $variation_id = $data['variation_id'];
303
+ }
304
+ $data['formdata'] = trim( $this->prepare_save_meta( $data['meta'], $product_id, $variation_id ), "'" );
305
+ unset( $data['meta'] );
306
+ }
307
+ foreach ( $data as $f => $v ) {
308
+ $s = is_array( $v ) ? ' IN ' : '=';
309
+ if ( is_array( $v ) ) {
310
+ foreach ( $v as $_f => $_v ) {
311
+ $v[ $_f ] = $wpdb->prepare( '%s', $_v );
312
+ }
313
+ $v = implode( ',', $v );
314
+ $v = "($v)";
315
+ } else {
316
+ $v = $wpdb->prepare( '%s', $v );
317
+ }
318
+ $data[ $f ] = sprintf( '`%s`%s%s', $f, $s, $v );
319
+ }
320
+ $where = implode( ' AND ', $data );
321
+ $sql .= ' WHERE ' . $where;
322
+ }
323
+
324
+ $sql .= sprintf( ' ORDER BY `%s` %s LIMIT %d,%d;', $default['order_by'], $default['order'], $default['offset'], $default['count'] );
325
+ if ( ! empty( $default['sql'] ) ) {
326
+ $replacer = $replace = array();
327
+ $replace[0] = '{table}';
328
+ $replacer[0] = $this->table;
329
+ $replace[1] = '{where}';
330
+ $replacer[1] = $where;
331
+
332
+ foreach ( $default as $key => $value ) {
333
+ $i = count( $replace );
334
+
335
+ $replace[ $i ] = '{' . $key . '}';
336
+ $replacer[ $i ] = $value;
337
+ }
338
+
339
+ $sql = str_replace( $replace, $replacer, $default['sql'] );
340
+ }
341
+ $products = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
342
+
343
+ if ( empty( $products ) ) {
344
+ return array();
345
+ }
346
+
347
+ foreach ( $products as $k => $product ) {
348
+ if ( empty( $default['sql'] ) ) {
349
+ $product = filter_var_array( $product, array(
350
+ 'ID' => FILTER_VALIDATE_INT,
351
+ 'wishlist_id' => FILTER_VALIDATE_INT,
352
+ 'product_id' => FILTER_VALIDATE_INT,
353
+ 'variation_id' => FILTER_VALIDATE_INT,
354
+ 'author' => FILTER_VALIDATE_INT,
355
+ 'date' => FILTER_DEFAULT,
356
+ 'formdata' => FILTER_DEFAULT,
357
+ 'quantity' => FILTER_VALIDATE_INT,
358
+ 'price' => FILTER_SANITIZE_NUMBER_FLOAT,
359
+ 'in_stock' => FILTER_VALIDATE_BOOLEAN,
360
+ ) );
361
+ if ( ! tinv_get_option( 'general', 'quantity_func' ) ) {
362
+ $product['quantity'] = 1;
363
+ }
364
+ }
365
+ if ( $default['external'] ) {
366
+ $product_data = $this->product_data( $product['variation_id'], $product['product_id'] );
367
+ if ( $product_data ) {
368
+ $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() ) );
369
+ $product['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
370
+ } else {
371
+ unset( $products[ $k ] );
372
+ continue;
373
+ }
374
+ $product['data'] = $product_data;
375
+ }
376
+ $product['meta'] = array();
377
+ if ( array_key_exists( 'formdata', $product ) ) {
378
+ $meta = $product['formdata'];
379
+ unset( $product['formdata'] );
380
+
381
+ $product['meta'] = $this->prepare_retrun_meta( $meta, $product['product_id'], $product['variation_id'], $product['quantity'] );
382
+ }
383
+ $products[ $k ] = apply_filters( 'tinvwl_wishlist_product_get', $product );
384
+ }
385
+
386
+ return $products;
387
+ }
388
+
389
+ /**
390
+ * Get product info
391
+ *
392
+ * @param integer $product_id Product id.
393
+ * @param integer $variation_id Product variation id.
394
+ *
395
+ * @return mixed
396
+ */
397
+ function product_data( $product_id, $variation_id = 0 ) {
398
+ $product_id = absint( $product_id );
399
+ $variation_id = absint( $variation_id );
400
+
401
+ if ( 'product_variation' == get_post_type( $product_id ) ) { // WPCS: loose comparison ok.
402
+ $variation_id = $product_id;
403
+ $product_id = wp_get_post_parent_id( $variation_id );
404
+ }
405
+
406
+ $product_data = wc_get_product( $variation_id ? $variation_id : $product_id );
407
+
408
+ if ( ! $product_data || 'trash' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->post->post_status : get_post( $product_data->get_id() )->post_status ) ) {
409
+ return null;
410
+ }
411
+
412
+ $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 ) ) );
413
+
414
+ return $product_data;
415
+ }
416
+
417
+ /**
418
+ * Update product
419
+ *
420
+ * @global wpdb $wpdb
421
+ *
422
+ * @param array $data Object product.
423
+ * @param array $meta Object meta form data.
424
+ *
425
+ * @return boolean
426
+ */
427
+ function update( $data = array(), $meta = array() ) {
428
+ if ( empty( $meta ) && array_key_exists( 'meta', $data ) && ! empty( $data['meta'] ) ) {
429
+ $meta = $data['meta'];
430
+ }
431
+
432
+ $data = filter_var_array( $data, apply_filters( 'tinvwl_wishlist_product_update_field', array(
433
+ 'product_id' => FILTER_VALIDATE_INT,
434
+ 'quantity' => FILTER_VALIDATE_INT,
435
+ 'variation_id' => FILTER_VALIDATE_INT,
436
+ 'wishlist_id' => FILTER_VALIDATE_INT,
437
+ 'author' => FILTER_VALIDATE_INT,
438
+ ) ) );
439
+ $data = array_filter( $data );
440
+
441
+ if ( ! array_key_exists( 'wishlist_id', $data ) ) {
442
+ $data['wishlist_id'] = $this->wishlist_id();
443
+ }
444
+ if ( ! array_key_exists( 'variation_id', $data ) ) {
445
+ $data['variation_id'] = 0;
446
+ }
447
+
448
+ if ( empty( $data['wishlist_id'] ) || empty( $data['product_id'] ) ) {
449
+ return false;
450
+ }
451
+ $product_data = $this->product_data( $data['product_id'], $data['variation_id'] );
452
+ if ( ! $product_data ) {
453
+ return false;
454
+ }
455
+
456
+ if ( $product_data->is_sold_individually() ) {
457
+ $data['quantity'] = 1;
458
+ }
459
+
460
+ $data = apply_filters( 'tinvwl_wishlist_product_update', $data );
461
+ $data['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() ) );
462
+ $data['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
463
+ $data['in_stock'] = $product_data->is_in_stock();
464
+ $data['price'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->price : $product_data->get_price();
465
+
466
+ global $wpdb;
467
+
468
+ return false !== $wpdb->update( $this->table, $data, array(
469
+ 'product_id' => $data['product_id'],
470
+ 'variation_id' => $data['variation_id'],
471
+ 'wishlist_id' => $data['wishlist_id'],
472
+ 'formdata' => $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] ),
473
+ ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
474
+ }
475
+
476
+ /**
477
+ * Remove product from wishlist
478
+ *
479
+ * @global wpdb $wpdb
480
+ *
481
+ * @param integer $wishlist_id If exist wishlist object, you can put 0.
482
+ * @param integer $product_id Product id.
483
+ * @param integer $variation_id Product variation id.
484
+ * @param array $meta Object meta form data.
485
+ *
486
+ * @return boolean
487
+ */
488
+ function remove_product_from_wl( $wishlist_id = 0, $product_id = 0, $variation_id = 0, $meta = array() ) {
489
+ global $wpdb;
490
+ if ( empty( $wishlist_id ) ) {
491
+ $wishlist_id = $this->wishlist_id();
492
+ }
493
+ if ( empty( $wishlist_id ) ) {
494
+ return false;
495
+ }
496
+ if ( empty( $product_id ) ) {
497
+ return false !== $wpdb->delete( $this->table, array( 'wishlist_id' => $wishlist_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
498
+ }
499
+ $product_data = $this->product_data( $product_id, $variation_id );
500
+ if ( ! $product_data ) {
501
+ return false;
502
+ }
503
+ $data = array(
504
+ 'wishlist_id' => $wishlist_id,
505
+ '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() ) ),
506
+ 'variation_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) ),
507
+ );
508
+ $data['formdata'] = $this->prepare_save_meta( $meta, $data['product_id'], $data['variation_id'] );
509
+ $result = false !== $wpdb->delete( $this->table, $data ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
510
+ if ( $result ) {
511
+ 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 ) ) );
512
+ }
513
+
514
+ return $result;
515
+ }
516
+
517
+ /**
518
+ * Remove product
519
+ *
520
+ * @global wpdb $wpdb
521
+ *
522
+ * @param integer $product_id Product id.
523
+ *
524
+ * @return boolean
525
+ */
526
+ function remove_product( $product_id = 0 ) {
527
+ if ( empty( $product_id ) ) {
528
+ return false;
529
+ }
530
+
531
+ global $wpdb;
532
+ $result = false !== $wpdb->delete( $this->table, array( 'product_id' => $product_id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
533
+ if ( $result ) {
534
+ do_action( 'tinvwl_wishlist_product_removed_by_product', $product_id );
535
+ }
536
+
537
+ return $result;
538
+ }
539
+
540
+ /**
541
+ * Remove product by ID
542
+ *
543
+ * @global wpdb $wpdb
544
+ *
545
+ * @param integer $id Product id.
546
+ *
547
+ * @return boolean
548
+ */
549
+ function remove( $id = 0 ) {
550
+ if ( empty( $id ) ) {
551
+ return false;
552
+ }
553
+
554
+ global $wpdb;
555
+ $result = false !== $wpdb->delete( $this->table, array( 'ID' => $id ) ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
556
+ if ( $result ) {
557
+ do_action( 'tinvwl_wishlist_product_removed_by_id', $id );
558
+ }
559
+
560
+ return $result;
561
+ }
562
+
563
+ /**
564
+ * Clean meta from default values.
565
+ *
566
+ * @param array $meta Meta array.
567
+ *
568
+ * @return array
569
+ */
570
+ function clean_meta( $meta ) {
571
+
572
+ foreach (
573
+ array(
574
+ 'add-to-cart',
575
+ 'product_id',
576
+ 'variation_id',
577
+ 'quantity',
578
+ 'undefined',
579
+ 'product_sku'
580
+ ) as $field
581
+ ) {
582
+ if ( array_key_exists( $field, $meta ) ) {
583
+ unset( $meta[ $field ] );
584
+ }
585
+ }
586
+ $meta = array_filter( $meta );
587
+
588
+ return $meta;
589
+ }
590
+
591
+ /**
592
+ * Prepare to save meta in database
593
+ *
594
+ * @param array $meta Meta array.
595
+ * @param ineger $product_id Woocommerce product ID.
596
+ * @param ineger $variation_id Woocommerce product variation ID.
597
+ *
598
+ * @return string
599
+ */
600
+ function prepare_save_meta( $meta = array(), $product_id = 0, $variation_id = 0 ) {
601
+ if ( ! is_array( $meta ) ) {
602
+ $meta = array();
603
+ }
604
+ $meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
605
+ foreach (
606
+ array(
607
+ 'add-to-cart',
608
+ 'product_id',
609
+ 'variation_id',
610
+ 'quantity',
611
+ 'undefined',
612
+ 'product_sku'
613
+ ) as $field
614
+ ) {
615
+ if ( array_key_exists( $field, $meta ) ) {
616
+ unset( $meta[ $field ] );
617
+ }
618
+ }
619
+ $meta = array_filter( $meta );
620
+ if ( empty( $meta ) ) {
621
+ return '';
622
+ }
623
+ ksort( $meta );
624
+
625
+ return json_encode( $meta );
626
+ }
627
+
628
+ /**
629
+ * Convert meta string to array
630
+ *
631
+ * @param string $meta Meta array.
632
+ * @param integer $product_id Product ID.
633
+ * @param integer $variation_id Variation product ID.
634
+ * @param integer $quantity Quantity product.
635
+ *
636
+ * @return array
637
+ */
638
+ function prepare_retrun_meta( $meta = '', $product_id = 0, $variation_id = 0, $quantity = 1 ) {
639
+ if ( empty( $meta ) ) {
640
+ return array();
641
+ }
642
+ $meta = @json_decode( $meta, true );
643
+ if ( empty( $meta ) || ! is_array( $meta ) ) {
644
+ return array();
645
+ }
646
+ if ( ! empty( $product_id ) ) {
647
+ $meta['add-to-cart'] = $product_id;
648
+ $meta['product_id'] = $product_id;
649
+ $meta['quantity'] = $quantity;
650
+ if ( ! empty( $variation_id ) ) {
651
+ $meta['variation_id'] = $variation_id;
652
+ }
653
+ }
654
+
655
+ return apply_filters( 'tinvwl_wishlist_product_unprepare_meta', $meta );
656
+ }
657
+ }
includes/update.helper.php CHANGED
@@ -1,143 +1,168 @@
1
- <?php
2
- /**
3
- * Update plugin class
4
- *
5
- * @since 1.0.0
6
- * @package TInvWishlist
7
- */
8
-
9
- // If this file is called directly, abort.
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- die;
12
- }
13
-
14
- /**
15
- * Update plugin class
16
- */
17
- class TInvWL_Update {
18
-
19
- /**
20
- * Version
21
- *
22
- * @var string
23
- */
24
- public $_v;
25
-
26
- /**
27
- * Previous Version
28
- *
29
- * @var string
30
- */
31
- public $_prev;
32
-
33
- /**
34
- * Regular expression for sorting version function
35
- *
36
- * @var string
37
- */
38
- const REGEXP = '/^up_/i';
39
-
40
- /**
41
- * Get update methods and apply
42
- *
43
- * @param string $version Version.
44
- * @param string $previous_version Previous Version.
45
- * @return boolean
46
- */
47
- function __construct( $version, $previous_version = 0 ) {
48
- $lists = get_class_methods( $this );
49
-
50
- $this->_v = $version;
51
- $this->_prev = $previous_version;
52
- $lists = array_filter( $lists, array( $this, 'filter' ) );
53
- if ( empty( $lists ) ) {
54
- return false;
55
- }
56
- uasort( $lists, array( $this, 'sort' ) );
57
- foreach ( $lists as $method ) {
58
- call_user_func( array( $this, $method ), $previous_version );
59
- }
60
- return true;
61
- }
62
-
63
- /**
64
- * Filter methods
65
- *
66
- * @param string $method Method name from this class.
67
- * @return boolean
68
- */
69
- public function filter( $method ) {
70
- if ( ! preg_match( self::REGEXP, $method ) ) {
71
- return false;
72
- }
73
- if ( version_compare( $this->_prev, $this->prepare( $method ), 'ge' ) ) {
74
- return false;
75
- }
76
- return version_compare( $this->_v, $this->prepare( $method ), 'ge' );
77
- }
78
-
79
- /**
80
- * Sort methods
81
- *
82
- * @param string $method1 Method name first from this class.
83
- * @param string $method2 Method name second from this class.
84
- * @return type
85
- */
86
- public function sort( $method1, $method2 ) {
87
- return version_compare( $this->prepare( $method1 ), $this->prepare( $method2 ) );
88
- }
89
-
90
- /**
91
- * Conver method name to version
92
- *
93
- * @param string $method Method name from this class.
94
- * @return string
95
- */
96
- public function prepare( $method ) {
97
- $method = preg_replace( self::REGEXP, '', $method );
98
- $method = str_replace( '_', '.', $method );
99
- return $method;
100
- }
101
-
102
- /**
103
- * Example of the method updating
104
- *
105
- * @param string $previous_version Previous Version.
106
- */
107
- function up_0_0_0( $previous_version = 0 ) {
108
-
109
- }
110
-
111
- /**
112
- * Set runed wizard
113
- *
114
- * @param string $previous_version Previous version value.
115
- */
116
- function up_1_1_10_1( $previous_version = 0 ) {
117
- update_option( 'tinvwl_wizard', true );
118
- }
119
-
120
- /**
121
- * Fix name field
122
- */
123
- function up_p_1_5_4() {
124
- if ( $value = tinv_get_option( 'product_table', 'add_to_card' ) ) {
125
- tinv_update_option( 'product_table', 'add_to_cart', $value );
126
- }
127
- if ( $value = tinv_get_option( 'product_table', 'text_add_to_card' ) ) {
128
- tinv_update_option( 'product_table', 'text_add_to_cart', $value );
129
- }
130
- if ( $value = tinv_get_option( 'table', 'add_select_to_card' ) ) {
131
- tinv_update_option( 'table', 'add_select_to_cart', $value );
132
- }
133
- if ( $value = tinv_get_option( 'table', 'text_add_select_to_card' ) ) {
134
- tinv_update_option( 'table', 'text_add_select_to_cart', $value );
135
- }
136
- if ( $value = tinv_get_option( 'table', 'add_all_to_card' ) ) {
137
- tinv_update_option( 'table', 'add_all_to_cart', $value );
138
- }
139
- if ( $value = tinv_get_option( 'table', 'text_add_all_to_card' ) ) {
140
- tinv_update_option( 'table', 'text_add_all_to_cart', $value );
141
- }
142
- }
143
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Update plugin class
4
+ *
5
+ * @since 1.0.0
6
+ * @package TInvWishlist
7
+ */
8
+
9
+ // If this file is called directly, abort.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ die;
12
+ }
13
+
14
+ /**
15
+ * Update plugin class
16
+ */
17
+ class TInvWL_Update {
18
+
19
+ /**
20
+ * Plugin name
21
+ *
22
+ * @var string
23
+ */
24
+ private $_n;
25
+
26
+ /**
27
+ * Version
28
+ *
29
+ * @var string
30
+ */
31
+ public $_v;
32
+
33
+ /**
34
+ * Previous Version
35
+ *
36
+ * @var string
37
+ */
38
+ public $_prev;
39
+
40
+ /**
41
+ * Regular expression for sorting version function
42
+ *
43
+ * @var string
44
+ */
45
+ const REGEXP = '/^up_/i';
46
+
47
+ /**
48
+ * Get update methods and apply
49
+ *
50
+ * @param string $version Version.
51
+ * @param string $previous_version Previous Version.
52
+ *
53
+ * @return boolean
54
+ */
55
+ function __construct( $version, $previous_version = 0 ) {
56
+ $lists = get_class_methods( $this );
57
+ $this->_n = TINVWL_PREFIX;
58
+ $this->_v = $version;
59
+ $this->_prev = $previous_version;
60
+ $lists = array_filter( $lists, array( $this, 'filter' ) );
61
+ if ( empty( $lists ) ) {
62
+ return false;
63
+ }
64
+ uasort( $lists, array( $this, 'sort' ) );
65
+ foreach ( $lists as $method ) {
66
+ call_user_func( array( $this, $method ), $previous_version );
67
+ }
68
+
69
+ return true;
70
+ }
71
+
72
+ /**
73
+ * Filter methods
74
+ *
75
+ * @param string $method Method name from this class.
76
+ *
77
+ * @return boolean
78
+ */
79
+ public function filter( $method ) {
80
+ if ( ! preg_match( self::REGEXP, $method ) ) {
81
+ return false;
82
+ }
83
+ if ( version_compare( $this->_prev, $this->prepare( $method ), 'ge' ) ) {
84
+ return false;
85
+ }
86
+
87
+ return version_compare( $this->_v, $this->prepare( $method ), 'ge' );
88
+ }
89
+
90
+ /**
91
+ * Sort methods
92
+ *
93
+ * @param string $method1 Method name first from this class.
94
+ * @param string $method2 Method name second from this class.
95
+ *
96
+ * @return type
97
+ */
98
+ public function sort( $method1, $method2 ) {
99
+ return version_compare( $this->prepare( $method1 ), $this->prepare( $method2 ) );
100
+ }
101
+
102
+ /**
103
+ * Conver method name to version
104
+ *
105
+ * @param string $method Method name from this class.
106
+ *
107
+ * @return string
108
+ */
109
+ public function prepare( $method ) {
110
+ $method = preg_replace( self::REGEXP, '', $method );
111
+ $method = str_replace( '_', '.', $method );
112
+
113
+ return $method;
114
+ }
115
+
116
+ /**
117
+ * Example of the method updating
118
+ *
119
+ * @param string $previous_version Previous Version.
120
+ */
121
+ function up_0_0_0( $previous_version = 0 ) {
122
+
123
+ }
124
+
125
+ /**
126
+ * Set runed wizard
127
+ *
128
+ * @param string $previous_version Previous version value.
129
+ */
130
+ function up_1_1_10_1( $previous_version = 0 ) {
131
+ update_option( 'tinvwl_wizard', true );
132
+ }
133
+
134
+ /**
135
+ * Fix name field
136
+ */
137
+ function up_p_1_5_4() {
138
+ if ( $value = tinv_get_option( 'product_table', 'add_to_card' ) ) {
139
+ tinv_update_option( 'product_table', 'add_to_cart', $value );
140
+ }
141
+ if ( $value = tinv_get_option( 'product_table', 'text_add_to_card' ) ) {
142
+ tinv_update_option( 'product_table', 'text_add_to_cart', $value );
143
+ }
144
+ if ( $value = tinv_get_option( 'table', 'add_select_to_card' ) ) {
145
+ tinv_update_option( 'table', 'add_select_to_cart', $value );
146
+ }
147
+ if ( $value = tinv_get_option( 'table', 'text_add_select_to_card' ) ) {
148
+ tinv_update_option( 'table', 'text_add_select_to_cart', $value );
149
+ }
150
+ if ( $value = tinv_get_option( 'table', 'add_all_to_card' ) ) {
151
+ tinv_update_option( 'table', 'add_all_to_cart', $value );
152
+ }
153
+ if ( $value = tinv_get_option( 'table', 'text_add_all_to_card' ) ) {
154
+ tinv_update_option( 'table', 'text_add_all_to_cart', $value );
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Clean up empty wishlists.
160
+ */
161
+ function up_p_1_6_1() {
162
+ global $wpdb;
163
+ $wishlists_table = sprintf( '%s%s_%s', $wpdb->prefix, $this->_n, 'lists' );
164
+ $wishlists_items_table = sprintf( '%s%s_%s', $wpdb->prefix, $this->_n, 'items' );
165
+ $sql = "DELETE FROM wl USING `{$wishlists_table}` AS wl WHERE NOT EXISTS( SELECT * FROM `{$wishlists_items_table}` WHERE {$wishlists_items_table}.wishlist_id = wl.ID ) AND wl.type='default'";
166
+ $cleanup = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: db call ok; no-cache ok; unprepared SQL ok.
167
+ }
168
+ }
public/addtowishlist.class.php CHANGED
@@ -154,7 +154,7 @@ class TInvWL_Public_AddToWishlist {
154
  $wishlist = apply_filters( 'tinvwl_addtowishlist_wishlist', $wishlist );
155
  if ( empty( $wishlist ) ) {
156
  $data['status'] = false;
157
- $data = apply_filters( 'tinvwl_addtowishlist_return_ajax', $data, $post );
158
  ob_clean();
159
  wp_send_json( $data );
160
  }
@@ -163,17 +163,17 @@ class TInvWL_Public_AddToWishlist {
163
  $data['status'] = false;
164
  $data['icon'] = 'icon_big_times';
165
  if ( tinv_get_option( 'general', 'redirect_require_login' ) ) {
166
- $data['msg'] = array();
167
- $data['force_redirect'] = apply_filters( 'tinvwl_addtowishlist_login_page', wc_get_page_permalink( 'myaccount' ), $post );
168
  } else {
169
- $data['msg'][] = __( 'Please, login to add products to Wishlist', 'ti-woocommerce-wishlist' );
170
- $data['dialog_custom_url'] = apply_filters( 'tinvwl_addtowishlist_login_page', wc_get_page_permalink( 'myaccount' ), $post );
171
- $data['dialog_custom_html'] = esc_html( __( 'Login', 'ti-woocommerce-wishlist' ) );
172
  }
173
  $data['msg'] = array_unique( $data['msg'] );
174
  $data['msg'] = implode( '<br>', $data['msg'] );
175
  if ( ! empty( $data['msg'] ) ) {
176
- $data['msg'] = tinv_wishlist_template_html( 'ti-addedtowishlist-dialogbox.php', $data );
177
  }
178
  $data = apply_filters( 'tinvwl_addtowishlist_return_ajax', $data, $post );
179
  ob_clean();
@@ -312,7 +312,7 @@ class TInvWL_Public_AddToWishlist {
312
  $data['msg'] = implode( '<br>', $data['msg'] );
313
  if ( ! empty( $data['msg'] ) ) {
314
  $data['msg'] = apply_filters( $this->_n . '_addtowishlist_message_after', $data['msg'], $data, $post, $form, $product );
315
- $data['msg'] = tinv_wishlist_template_html( 'ti-addedtowishlist-dialogbox.php', $data );
316
  }
317
  if ( ! tinv_get_option( 'general', 'show_notice' ) && array_key_exists( 'msg', $data ) ) {
318
  unset( $data['msg'] );
@@ -501,7 +501,7 @@ class TInvWL_Public_AddToWishlist {
501
  }
502
 
503
  $data = array(
504
- 'class_postion' => sprintf( 'tinvwl-%s-add-to-cart', $this->is_loop ? tinv_get_option( 'add_to_wishlist_catalog', 'position' ) : $position ),
505
  'product' => $this->product,
506
  'variation_id' => ( $this->is_loop && 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->product_type : $this->product->get_type() ) ) ? $this->variation_id : ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->variation_id : ( $this->product->is_type( 'variation' ) ? $this->product->get_id() : 0 ) ),
507
  'TInvWishlist' => $wishlists,
@@ -510,6 +510,7 @@ class TInvWL_Public_AddToWishlist {
510
  'browse_in_wishlist' => apply_filters( 'tinvwl-general-text_browse', tinv_get_option( 'general', 'text_browse' ) ),
511
  'product_in_wishlist' => apply_filters( 'tinvwl-general-text_already_in', tinv_get_option( 'general', 'text_already_in' ) ),
512
  'product_to_wishlist' => apply_filters( 'tinvwl-general-text_added_to', tinv_get_option( 'general', 'text_added_to' ) ),
 
513
  );
514
  tinv_wishlist_template( 'ti-addtowishlist.php', $data );
515
  }
@@ -521,7 +522,7 @@ class TInvWL_Public_AddToWishlist {
521
  */
522
  function button( $echo = true ) {
523
  $content = apply_filters( 'tinvwl_wishlist_button_before', '' );
524
- $text = tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'text' );
525
  $icon = tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'icon' );
526
  $icon_class = '';
527
  $action = 'addto';
@@ -567,7 +568,10 @@ class TInvWL_Public_AddToWishlist {
567
  if ( 'button' == tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'type' ) ) { // WPCS: loose comparison ok.
568
  $icon .= ' button';
569
  }
570
- $content .= sprintf( '<a class="tinvwl_add_to_wishlist_button %s" data-tinv-wl-list="%s" data-tinv-wl-product="%s" data-tinv-wl-productvariation="%s" data-tinv-wl-producttype="%s" data-tinv-wl-action="%s">%s</a>', $icon, htmlspecialchars( wp_json_encode( $this->wishlist ) ), ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->id : ( $this->product->is_type( 'variation' ) ? $this->product->get_parent_id() : $this->product->get_id() ) ), ( ( $this->is_loop && 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->product_type : $this->product->get_type() ) ) ? $this->variation_id : ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->variation_id : ( $this->product->is_type( 'variation' ) ? $this->product->get_id() : 0 ) ) ), ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->product_type : $this->product->get_type() ), $action, $text );
 
 
 
571
  $content .= apply_filters( 'tinvwl_wishlist_button_after', '' );
572
 
573
  if ( ! empty( $text ) ) {
154
  $wishlist = apply_filters( 'tinvwl_addtowishlist_wishlist', $wishlist );
155
  if ( empty( $wishlist ) ) {
156
  $data['status'] = false;
157
+ $data = apply_filters( 'tinvwl_addtowishlist_return_ajax', $data, $post );
158
  ob_clean();
159
  wp_send_json( $data );
160
  }
163
  $data['status'] = false;
164
  $data['icon'] = 'icon_big_times';
165
  if ( tinv_get_option( 'general', 'redirect_require_login' ) ) {
166
+ $data['msg'] = array();
167
+ $data['force_redirect'] = apply_filters( 'tinvwl_addtowishlist_login_page', wc_get_page_permalink( 'myaccount' ), $post );
168
  } else {
169
+ $data['msg'][] = __( 'Please, login to add products to Wishlist', 'ti-woocommerce-wishlist' );
170
+ $data['dialog_custom_url'] = apply_filters( 'tinvwl_addtowishlist_login_page', wc_get_page_permalink( 'myaccount' ), $post );
171
+ $data['dialog_custom_html'] = esc_html( __( 'Login', 'ti-woocommerce-wishlist' ) );
172
  }
173
  $data['msg'] = array_unique( $data['msg'] );
174
  $data['msg'] = implode( '<br>', $data['msg'] );
175
  if ( ! empty( $data['msg'] ) ) {
176
+ $data['msg'] = tinv_wishlist_template_html( 'ti-addedtowishlist-dialogbox.php', apply_filters( 'tinvwl_addtowishlist_dialog_box', $data, $post ) );
177
  }
178
  $data = apply_filters( 'tinvwl_addtowishlist_return_ajax', $data, $post );
179
  ob_clean();
312
  $data['msg'] = implode( '<br>', $data['msg'] );
313
  if ( ! empty( $data['msg'] ) ) {
314
  $data['msg'] = apply_filters( $this->_n . '_addtowishlist_message_after', $data['msg'], $data, $post, $form, $product );
315
+ $data['msg'] = tinv_wishlist_template_html( 'ti-addedtowishlist-dialogbox.php', apply_filters( 'tinvwl_addtowishlist_dialog_box', $data, $post ) );
316
  }
317
  if ( ! tinv_get_option( 'general', 'show_notice' ) && array_key_exists( 'msg', $data ) ) {
318
  unset( $data['msg'] );
501
  }
502
 
503
  $data = array(
504
+ 'class_postion' => sprintf( 'tinvwl-%s-add-to-cart', $this->is_loop ? tinv_get_option( 'add_to_wishlist_catalog', 'position' ) : $position ) . ( $this->is_loop ? ' tinvwl-loop-button-wrapper' : '' ),
505
  'product' => $this->product,
506
  'variation_id' => ( $this->is_loop && 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->product_type : $this->product->get_type() ) ) ? $this->variation_id : ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->variation_id : ( $this->product->is_type( 'variation' ) ? $this->product->get_id() : 0 ) ),
507
  'TInvWishlist' => $wishlists,
510
  'browse_in_wishlist' => apply_filters( 'tinvwl-general-text_browse', tinv_get_option( 'general', 'text_browse' ) ),
511
  'product_in_wishlist' => apply_filters( 'tinvwl-general-text_already_in', tinv_get_option( 'general', 'text_already_in' ) ),
512
  'product_to_wishlist' => apply_filters( 'tinvwl-general-text_added_to', tinv_get_option( 'general', 'text_added_to' ) ),
513
+ 'loop' => $this->is_loop,
514
  );
515
  tinv_wishlist_template( 'ti-addtowishlist.php', $data );
516
  }
522
  */
523
  function button( $echo = true ) {
524
  $content = apply_filters( 'tinvwl_wishlist_button_before', '' );
525
+ $text = ( tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'show_text' ) ) ? apply_filters( 'tinvwl-add_to_wishlist_catalog-text', tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'text' ) ) : '';
526
  $icon = tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'icon' );
527
  $icon_class = '';
528
  $action = 'addto';
568
  if ( 'button' == tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'type' ) ) { // WPCS: loose comparison ok.
569
  $icon .= ' button';
570
  }
571
+
572
+ $icon .= ' tinvwl-position-' . tinv_get_option( 'add_to_wishlist' . ( $this->is_loop ? '_catalog' : '' ), 'position' );
573
+
574
+ $content .= sprintf( '<a class="tinvwl_add_to_wishlist_button %s" data-tinv-wl-list="%s" data-tinv-wl-product="%s" data-tinv-wl-productvariation="%s" data-tinv-wl-producttype="%s" data-tinv-wl-action="%s" rel="nofollow">%s</a>', $icon, htmlspecialchars( wp_json_encode( $this->wishlist ) ), ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->id : ( $this->product->is_type( 'variation' ) ? $this->product->get_parent_id() : $this->product->get_id() ) ), ( ( $this->is_loop && 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->product_type : $this->product->get_type() ) ) ? $this->variation_id : ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->variation_id : ( $this->product->is_type( 'variation' ) ? $this->product->get_id() : 0 ) ) ), ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $this->product->product_type : $this->product->get_type() ), $action, $text );
575
  $content .= apply_filters( 'tinvwl_wishlist_button_after', '' );
576
 
577
  if ( ! empty( $text ) ) {
public/wishlist/buttons.class.php CHANGED
@@ -46,6 +46,13 @@ class TInvWL_Public_Wishlist_Buttons {
46
  * @return array
47
  */
48
  private static function prepare() {
 
 
 
 
 
 
 
49
  $buttons = array();
50
  if ( tinv_get_option( 'table', 'colm_checkbox' ) && tinv_get_option( 'table', 'colm_actions' ) ) {
51
  $buttons[] = array(
@@ -172,7 +179,11 @@ class TInvWL_Public_Wishlist_Buttons {
172
  add_filter( self::$_n . '_after__button_' . $button['name'], $button['after'] );
173
  }
174
 
175
- add_action( $button['event'], create_function( '$a', 'if (' . $button['condition'] . '){' . __CLASS__ . '::button("' . $button['name'] . '","' . $button['title'] . '","' . $button['submit'] . '");}' ), $button['priority'] ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.create_function
 
 
 
 
176
  add_action( 'tinvwl_action_' . $button['name'], $button['method'], 10, 4 );
177
  }
178
 
46
  * @return array
47
  */
48
  private static function prepare() {
49
+
50
+ // WP Multilang string translations.
51
+ if ( function_exists( 'wpm_translate_string' ) ) {
52
+ add_filter( 'tinvwl-table-text_add_select_to_cart', 'wpm_translate_string' );
53
+ add_filter( 'tinvwl-table-text_add_all_to_cart', 'wpm_translate_string' );
54
+ }
55
+
56
  $buttons = array();
57
  if ( tinv_get_option( 'table', 'colm_checkbox' ) && tinv_get_option( 'table', 'colm_actions' ) ) {
58
  $buttons[] = array(
179
  add_filter( self::$_n . '_after__button_' . $button['name'], $button['after'] );
180
  }
181
 
182
+ add_action( $button['event'], function () use ( $button ) {
183
+ if ( $button['condition'] ) {
184
+ self::button( $button['name'], $button['title'], $button['submit'] );
185
+ }
186
+ }, $button['priority'] );
187
  add_action( 'tinvwl_action_' . $button['name'], $button['method'], 10, 4 );
188
  }
189
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://templateinvaders.com/?utm_source=wordpressorg&utm_content=d
4
  Tags: wishlist, woocommerce, woocommerce wishlist, e-commerce, shop, ecommerce wishlist, shop wishlist, wishlist for Woocommerce
5
  Requires at least: 4.5
6
  Tested up to: 4.9
7
- Stable tag: 1.6.0
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -129,6 +129,22 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
129
 
130
  == Changelog ==
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  = 1.6.0 =
133
  *Release Date - 08 February 2018*
134
 
4
  Tags: wishlist, woocommerce, woocommerce wishlist, e-commerce, shop, ecommerce wishlist, shop wishlist, wishlist for Woocommerce
5
  Requires at least: 4.5
6
  Tested up to: 4.9
7
+ Stable tag: 1.6.1
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
129
 
130
  == Changelog ==
131
 
132
+ = 1.6.1 =
133
+ *Release Date - 01 March 2018*
134
+
135
+ * Fixed an issue with deprecated function create_function(); on PHP 7.2+
136
+ * Fixed an issue with duplicated products in Wishlist
137
+ * Fixed an issue with empty wishlists in database and added cleanup on plugin upgrade
138
+ * Fixed an issue when variable products were not removed from wishlist after adding to cart
139
+ * Fixed PHP undefined notices in Wishlist table
140
+ * Fixed warnings for non-existent products in Wishlist
141
+ * Added new option "Show button text" that allows displaying the only add to wishlist icon
142
+ * Added custom classes for buttons
143
+ * Added "nofollow" attribute for button links
144
+ * Improved compatibility with [WP Multilang](https://wordpress.org/plugins/wp-multilang/) plugin
145
+ * Improved compatibility with [WooCommerce Multilingual](https://wordpress.org/plugins/woocommerce-multilingual/) plugin
146
+ * Improved compatibility with [Personalized Product Option Manager](https://wordpress.org/plugins/woocommerce-product-addon/) plugin
147
+
148
  = 1.6.0 =
149
  *Release Date - 08 February 2018*
150
 
templates/ti-addtowishlist.php CHANGED
@@ -1,22 +1,33 @@
1
- <?php
2
- /**
3
- * The Template for displaying add to wishlist product button.
4
- *
5
- * @version 1.0.0
6
- * @package TInvWishlist\Template
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit; // Exit if accessed directly.
11
- }
12
-
13
- ?>
14
- <input type="hidden" name="product_id" value="<?php echo esc_attr( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ); ?>" />
15
- <?php if ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 ) ) { ?>
16
- <input type="hidden" name="variation_id" value="<?php echo esc_attr( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 ) ); ?>" />
17
- <?php } ?>
18
- <div class="tinv-wraper woocommerce tinv-wishlist <?php echo esc_attr( $class_postion )?>">
19
- <?php do_action( 'tinv_wishlist_addtowishlist_button' ); ?>
20
- <?php do_action( 'tinv_wishlist_addtowishlist_dialogbox' ); ?>
21
- <div class="tinvwl-tooltip"><?php esc_html_e( 'Add to Wishlist', 'ti-woocommerce-wishlist' ); ?></div>
22
- </div>
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Template for displaying add to wishlist product button.
4
+ *
5
+ * @version 1.6.1
6
+ * @package TInvWishlist\Template
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ ?>
14
+ <div class="tinv-wraper woocommerce tinv-wishlist <?php echo esc_attr( $class_postion ) ?>">
15
+ <input type="hidden" name="product_id"
16
+ value="<?php echo esc_attr( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ) ); ?>"/>
17
+ <?php if ( $variation_id ) { ?>
18
+ <input type="hidden" name="variation_id" value="<?php echo esc_attr( $variation_id ); ?>"/>
19
+ <?php
20
+
21
+ $_variation = wc_get_product( $variation_id );
22
+ $attributes = $_variation->get_variation_attributes();
23
+
24
+ foreach ( $attributes as $name => $value ) {
25
+ echo '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
26
+ }
27
+
28
+ ?>
29
+ <?php } ?>
30
+ <?php do_action( 'tinv_wishlist_addtowishlist_button' ); ?>
31
+ <?php do_action( 'tinv_wishlist_addtowishlist_dialogbox' ); ?>
32
+ <div class="tinvwl-tooltip"><?php echo esc_html( tinv_get_option( 'add_to_wishlist' . ( $loop ? '_catalog' : '' ), 'text' ) ); ?></div>
33
+ </div>
templates/ti-wishlist-user.php CHANGED
@@ -1,147 +1,155 @@
1
- <?php
2
- /**
3
- * The Template for displaying user wishlist.
4
- *
5
- * @version 1.0.0
6
- * @package TInvWishlist\Template
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit; // Exit if accessed directly.
11
- }
12
-
13
- ?>
14
- <div class="tinv-wishlist woocommerce tinv-wishlist-clear">
15
- <?php do_action( 'tinvwl_before_wishlist', $wishlist ); ?>
16
- <?php if ( function_exists( 'wc_print_notices' ) ) { wc_print_notices(); } ?>
17
- <form action="<?php echo esc_url( tinv_url_wishlist() ); ?>" method="post" autocomplete="off">
18
- <?php do_action( 'tinvwl_before_wishlist_table', $wishlist ); ?>
19
- <table class="tinvwl-table-manage-list">
20
- <thead>
21
- <tr>
22
- <?php if ( $wishlist_table['colm_checkbox'] ) { ?>
23
- <th class="product-cb"><input type="checkbox" class="global-cb"></th>
24
- <?php } ?>
25
- <th class="product-thumbnail">&nbsp;</th>
26
- <th class="product-name"><span class="tinvwl-full"><?php esc_html_e( 'Product Name', 'ti-woocommerce-wishlist' ); ?></span><span class="tinvwl-mobile"><?php esc_html_e( 'Product', 'ti-woocommerce-wishlist' ); ?></span></th>
27
- <?php if ( $wishlist_table_row['colm_price'] ) { ?>
28
- <th class="product-price"><?php esc_html_e( 'Unit Price', 'ti-woocommerce-wishlist' ); ?></th>
29
- <?php } ?>
30
- <?php if ( $wishlist_table_row['colm_date'] ) { ?>
31
- <th class="product-date"><?php esc_html_e( 'Date Added', 'ti-woocommerce-wishlist' ); ?></th>
32
- <?php } ?>
33
- <?php if ( $wishlist_table_row['colm_stock'] ) { ?>
34
- <th class="product-stock"><?php esc_html_e( 'Stock Status', 'ti-woocommerce-wishlist' ); ?></th>
35
- <?php } ?>
36
- <?php if ( $wishlist_table_row['add_to_cart'] ) { ?>
37
- <th class="product-action">&nbsp;</th>
38
- <?php } ?>
39
- </tr>
40
- </thead>
41
- <tbody>
42
- <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
43
-
44
- <?php
45
- foreach ( $products as $wl_product ) {
46
- $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
47
- unset( $wl_product['data'] );
48
- if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
49
- $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
50
- do_action( 'tinvwl_wishlist_row_before', $wl_product, $product );
51
- ?>
52
- <tr class="<?php echo esc_attr( apply_filters( 'tinvwl_wishlist_item_class', 'wishlist_item', $wl_product, $product ) ); ?>">
53
- <?php if ( $wishlist_table['colm_checkbox'] ) { ?>
54
- <td class="product-cb">
55
- <?php
56
- echo apply_filters( 'tinvwl_wishlist_item_cb', sprintf( // WPCS: xss ok.
57
- '<input type="checkbox" name="wishlist_pr[]" value="%d">', esc_attr( $wl_product['ID'] )
58
- ), $wl_product, $product );
59
- ?>
60
- </td>
61
- <?php } ?>
62
- <td class="product-thumbnail">
63
- <?php
64
- $thumbnail = apply_filters( 'tinvwl_wishlist_item_thumbnail', $product->get_image(), $wl_product, $product );
65
-
66
- if ( ! $product->is_visible() ) {
67
- echo $thumbnail; // WPCS: xss ok.
68
- } else {
69
- printf( '<a href="%s">%s</a>', esc_url( $product_url ), $thumbnail ); // WPCS: xss ok.
70
- }
71
- ?>
72
- </td>
73
- <td class="product-name">
74
- <?php
75
- if ( ! $product->is_visible() ) {
76
- echo apply_filters( 'tinvwl_wishlist_item_name', $product->get_title(), $wl_product, $product ) . '&nbsp;'; // WPCS: xss ok.
77
- } else {
78
- echo apply_filters( 'tinvwl_wishlist_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product->get_title() ), $wl_product, $product ); // WPCS: xss ok.
79
- }
80
-
81
- echo apply_filters( 'tinvwl_wishlist_item_meta_data', tinv_wishlist_get_item_data( $product, $wl_product ), $wl_product, $product ); // WPCS: xss ok.
82
- ?>
83
- </td>
84
- <?php if ( $wishlist_table_row['colm_price'] ) { ?>
85
- <td class="product-price">
86
- <?php
87
- echo apply_filters( 'tinvwl_wishlist_item_price', $product->get_price_html(), $wl_product, $product ); // WPCS: xss ok.
88
- ?>
89
- </td>
90
- <?php } ?>
91
- <?php if ( $wishlist_table_row['colm_date'] ) { ?>
92
- <td class="product-date">
93
- <?php
94
- echo apply_filters( 'tinvwl_wishlist_item_date', sprintf( // WPCS: xss ok.
95
- '<time class="entry-date" datetime="%1$s">%2$s</time>', $wl_product['date'], mysql2date( get_option( 'date_format' ), $wl_product['date'] )
96
- ), $wl_product, $product );
97
- ?>
98
- </td>
99
- <?php } ?>
100
- <?php if ( $wishlist_table_row['colm_stock'] ) { ?>
101
- <td class="product-stock">
102
- <?php
103
- $availability = (array) $product->get_availability();
104
- if ( ! array_key_exists( 'availability', $availability ) ) {
105
- $availability['availability'] = '';
106
- }
107
- if ( ! array_key_exists( 'class', $availability ) ) {
108
- $availability['class'] = '';
109
- }
110
- $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
111
-
112
- echo apply_filters( 'tinvwl_wishlist_item_status', $availability_html, $availability['availability'], $wl_product, $product ); // WPCS: xss ok.
113
- ?>
114
- </td>
115
- <?php } ?>
116
- <?php if ( $wishlist_table_row['add_to_cart'] ) { ?>
117
- <td class="product-action">
118
- <?php
119
- if ( apply_filters( 'tinvwl_wishlist_item_action_add_to_cart', $wishlist_table_row['add_to_cart'], $wl_product, $product ) ) {
120
- ?>
121
- <button class="button alt" name="tinvwl-add-to-cart" value="<?php echo esc_attr( $wl_product['ID'] ); ?>"><i class="fa fa-shopping-cart"></i><span class="tinvwl-txt"><?php echo esc_html( apply_filters( 'tinvwl_wishlist_item_add_to_cart', $wishlist_table_row['text_add_to_cart'], $wl_product, $product ) ); ?></span></button>
122
- <?php } ?>
123
- </td>
124
- <?php } ?>
125
- </tr>
126
- <?php
127
- do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
128
- } // End if().
129
- } // End foreach().
130
- ?>
131
- <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
132
- </tbody>
133
- <tfoot>
134
- <tr>
135
- <td colspan="100">
136
- <?php do_action( 'tinvwl_after_wishlist_table', $wishlist ); ?>
137
- <?php wp_nonce_field( 'tinvwl_wishlist_user', 'wishlist_nonce' ); ?>
138
- </td>
139
- </tr>
140
- </tfoot>
141
- </table>
142
- </form>
143
- <?php do_action( 'tinvwl_after_wishlist', $wishlist ); ?>
144
- <div class="tinv-lists-nav tinv-wishlist-clear">
145
- <?php do_action( 'tinvwl_pagenation_wishlist', $wishlist ); ?>
146
- </div>
147
- </div>
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Template for displaying user wishlist.
4
+ *
5
+ * @version 1.6.1
6
+ * @package TInvWishlist\Template
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ ?>
14
+ <div class="tinv-wishlist woocommerce tinv-wishlist-clear">
15
+ <?php do_action( 'tinvwl_before_wishlist', $wishlist ); ?>
16
+ <?php if ( function_exists( 'wc_print_notices' ) ) {
17
+ wc_print_notices();
18
+ } ?>
19
+ <form action="<?php echo esc_url( tinv_url_wishlist() ); ?>" method="post" autocomplete="off">
20
+ <?php do_action( 'tinvwl_before_wishlist_table', $wishlist ); ?>
21
+ <table class="tinvwl-table-manage-list">
22
+ <thead>
23
+ <tr>
24
+ <?php if ( isset( $wishlist_table['colm_checkbox'] ) && $wishlist_table['colm_checkbox'] ) { ?>
25
+ <th class="product-cb"><input type="checkbox" class="global-cb"></th>
26
+ <?php } ?>
27
+ <th class="product-thumbnail">&nbsp;</th>
28
+ <th class="product-name"><span
29
+ class="tinvwl-full"><?php esc_html_e( 'Product Name', 'ti-woocommerce-wishlist' ); ?></span><span
30
+ class="tinvwl-mobile"><?php esc_html_e( 'Product', 'ti-woocommerce-wishlist' ); ?></span></th>
31
+ <?php if ( isset( $wishlist_table_row['colm_price'] ) && $wishlist_table_row['colm_price'] ) { ?>
32
+ <th class="product-price"><?php esc_html_e( 'Unit Price', 'ti-woocommerce-wishlist' ); ?></th>
33
+ <?php } ?>
34
+ <?php if ( isset( $wishlist_table_row['colm_date'] ) && $wishlist_table_row['colm_date'] ) { ?>
35
+ <th class="product-date"><?php esc_html_e( 'Date Added', 'ti-woocommerce-wishlist' ); ?></th>
36
+ <?php } ?>
37
+ <?php if ( isset( $wishlist_table_row['colm_stock'] ) && $wishlist_table_row['colm_stock'] ) { ?>
38
+ <th class="product-stock"><?php esc_html_e( 'Stock Status', 'ti-woocommerce-wishlist' ); ?></th>
39
+ <?php } ?>
40
+ <?php if ( isset( $wishlist_table_row['add_to_cart'] ) && $wishlist_table_row['add_to_cart'] ) { ?>
41
+ <th class="product-action">&nbsp;</th>
42
+ <?php } ?>
43
+ </tr>
44
+ </thead>
45
+ <tbody>
46
+ <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
47
+
48
+ <?php
49
+ foreach ( $products as $wl_product ) {
50
+ $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
51
+ unset( $wl_product['data'] );
52
+ if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
53
+ $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
54
+ do_action( 'tinvwl_wishlist_row_before', $wl_product, $product );
55
+ ?>
56
+ <tr class="<?php echo esc_attr( apply_filters( 'tinvwl_wishlist_item_class', 'wishlist_item', $wl_product, $product ) ); ?>">
57
+ <?php if ( isset( $wishlist_table['colm_checkbox'] ) && $wishlist_table['colm_checkbox'] ) { ?>
58
+ <td class="product-cb">
59
+ <?php
60
+ echo apply_filters( 'tinvwl_wishlist_item_cb', sprintf( // WPCS: xss ok.
61
+ '<input type="checkbox" name="wishlist_pr[]" value="%d">', esc_attr( $wl_product['ID'] )
62
+ ), $wl_product, $product );
63
+ ?>
64
+ </td>
65
+ <?php } ?>
66
+ <td class="product-thumbnail">
67
+ <?php
68
+ $thumbnail = apply_filters( 'tinvwl_wishlist_item_thumbnail', $product->get_image(), $wl_product, $product );
69
+
70
+ if ( ! $product->is_visible() ) {
71
+ echo $thumbnail; // WPCS: xss ok.
72
+ } else {
73
+ printf( '<a href="%s">%s</a>', esc_url( $product_url ), $thumbnail ); // WPCS: xss ok.
74
+ }
75
+ ?>
76
+ </td>
77
+ <td class="product-name">
78
+ <?php
79
+ if ( ! $product->is_visible() ) {
80
+ echo apply_filters( 'tinvwl_wishlist_item_name', $product->get_title(), $wl_product, $product ) . '&nbsp;'; // WPCS: xss ok.
81
+ } else {
82
+ echo apply_filters( 'tinvwl_wishlist_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product->get_title() ), $wl_product, $product ); // WPCS: xss ok.
83
+ }
84
+
85
+ echo apply_filters( 'tinvwl_wishlist_item_meta_data', tinv_wishlist_get_item_data( $product, $wl_product ), $wl_product, $product ); // WPCS: xss ok.
86
+ ?>
87
+ </td>
88
+ <?php if ( isset( $wishlist_table_row['colm_price'] ) && $wishlist_table_row['colm_price'] ) { ?>
89
+ <td class="product-price">
90
+ <?php
91
+ echo apply_filters( 'tinvwl_wishlist_item_price', $product->get_price_html(), $wl_product, $product ); // WPCS: xss ok.
92
+ ?>
93
+ </td>
94
+ <?php } ?>
95
+ <?php if ( isset( $wishlist_table_row['colm_date'] ) && $wishlist_table_row['colm_date'] ) { ?>
96
+ <td class="product-date">
97
+ <?php
98
+ echo apply_filters( 'tinvwl_wishlist_item_date', sprintf( // WPCS: xss ok.
99
+ '<time class="entry-date" datetime="%1$s">%2$s</time>', $wl_product['date'], mysql2date( get_option( 'date_format' ), $wl_product['date'] )
100
+ ), $wl_product, $product );
101
+ ?>
102
+ </td>
103
+ <?php } ?>
104
+ <?php if ( isset( $wishlist_table_row['colm_stock'] ) && $wishlist_table_row['colm_stock'] ) { ?>
105
+ <td class="product-stock">
106
+ <?php
107
+ $availability = (array) $product->get_availability();
108
+ if ( ! array_key_exists( 'availability', $availability ) ) {
109
+ $availability['availability'] = '';
110
+ }
111
+ if ( ! array_key_exists( 'class', $availability ) ) {
112
+ $availability['class'] = '';
113
+ }
114
+ $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
115
+
116
+ echo apply_filters( 'tinvwl_wishlist_item_status', $availability_html, $availability['availability'], $wl_product, $product ); // WPCS: xss ok.
117
+ ?>
118
+ </td>
119
+ <?php } ?>
120
+ <?php if ( isset( $wishlist_table_row['add_to_cart'] ) && $wishlist_table_row['add_to_cart'] ) { ?>
121
+ <td class="product-action">
122
+ <?php
123
+ if ( apply_filters( 'tinvwl_wishlist_item_action_add_to_cart', $wishlist_table_row['add_to_cart'], $wl_product, $product ) ) {
124
+ ?>
125
+ <button class="button alt" name="tinvwl-add-to-cart"
126
+ value="<?php echo esc_attr( $wl_product['ID'] ); ?>"><i
127
+ class="fa fa-shopping-cart"></i><span
128
+ class="tinvwl-txt"><?php echo esc_html( apply_filters( 'tinvwl_wishlist_item_add_to_cart', $wishlist_table_row['text_add_to_cart'], $wl_product, $product ) ); ?></span>
129
+ </button>
130
+ <?php } ?>
131
+ </td>
132
+ <?php } ?>
133
+ </tr>
134
+ <?php
135
+ do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
136
+ } // End if().
137
+ } // End foreach().
138
+ ?>
139
+ <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
140
+ </tbody>
141
+ <tfoot>
142
+ <tr>
143
+ <td colspan="100">
144
+ <?php do_action( 'tinvwl_after_wishlist_table', $wishlist ); ?>
145
+ <?php wp_nonce_field( 'tinvwl_wishlist_user', 'wishlist_nonce' ); ?>
146
+ </td>
147
+ </tr>
148
+ </tfoot>
149
+ </table>
150
+ </form>
151
+ <?php do_action( 'tinvwl_after_wishlist', $wishlist ); ?>
152
+ <div class="tinv-lists-nav tinv-wishlist-clear">
153
+ <?php do_action( 'tinvwl_pagenation_wishlist', $wishlist ); ?>
154
+ </div>
155
+ </div>
templates/ti-wishlist.php CHANGED
@@ -1,151 +1,161 @@
1
- <?php
2
- /**
3
- * The Template for displaying wishlist.
4
- *
5
- * @version 1.0.0
6
- * @package TInvWishlist\Template
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit; // Exit if accessed directly.
11
- }
12
-
13
- ?>
14
- <div class="tinv-wishlist woocommerce tinv-wishlist-clear">
15
- <?php do_action( 'tinvwl_before_wishlist', $wishlist ); ?>
16
- <?php if ( function_exists( 'wc_print_notices' ) ) { wc_print_notices(); } ?>
17
- <form action="<?php echo esc_url( tinv_url_wishlist() ); ?>" method="post" autocomplete="off">
18
- <?php do_action( 'tinvwl_before_wishlist_table', $wishlist ); ?>
19
- <table class="tinvwl-table-manage-list">
20
- <thead>
21
- <tr>
22
- <?php if ( $wishlist_table['colm_checkbox'] ) { ?>
23
- <th class="product-cb"><input type="checkbox" class="global-cb"></th>
24
- <?php } ?>
25
- <th class="product-remove"></th>
26
- <th class="product-thumbnail">&nbsp;</th>
27
- <th class="product-name"><span class="tinvwl-full"><?php esc_html_e( 'Product Name', 'ti-woocommerce-wishlist' ); ?></span><span class="tinvwl-mobile"><?php esc_html_e( 'Product', 'ti-woocommerce-wishlist' ); ?></span></th>
28
- <?php if ( $wishlist_table_row['colm_price'] ) { ?>
29
- <th class="product-price"><?php esc_html_e( 'Unit Price', 'ti-woocommerce-wishlist' ); ?></th>
30
- <?php } ?>
31
- <?php if ( $wishlist_table_row['colm_date'] ) { ?>
32
- <th class="product-date"><?php esc_html_e( 'Date Added', 'ti-woocommerce-wishlist' ); ?></th>
33
- <?php } ?>
34
- <?php if ( $wishlist_table_row['colm_stock'] ) { ?>
35
- <th class="product-stock"><?php esc_html_e( 'Stock Status', 'ti-woocommerce-wishlist' ); ?></th>
36
- <?php } ?>
37
- <?php if ( $wishlist_table_row['add_to_cart'] ) { ?>
38
- <th class="product-action">&nbsp;</th>
39
- <?php } ?>
40
- </tr>
41
- </thead>
42
- <tbody>
43
- <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
44
-
45
- <?php
46
- foreach ( $products as $wl_product ) {
47
- $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
48
- unset( $wl_product['data'] );
49
- if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
50
- $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
51
- do_action( 'tinvwl_wishlist_row_before', $wl_product, $product );
52
- ?>
53
- <tr class="<?php echo esc_attr( apply_filters( 'tinvwl_wishlist_item_class', 'wishlist_item', $wl_product, $product ) ); ?>">
54
- <?php if ( $wishlist_table['colm_checkbox'] ) { ?>
55
- <td class="product-cb">
56
- <?php
57
- echo apply_filters( 'tinvwl_wishlist_item_cb', sprintf( // WPCS: xss ok.
58
- '<input type="checkbox" name="wishlist_pr[]" value="%d">', esc_attr( $wl_product['ID'] )
59
- ), $wl_product, $product );
60
- ?>
61
- </td>
62
- <?php } ?>
63
- <td class="product-remove">
64
- <button type="submit" name="tinvwl-remove" value="<?php echo esc_attr( $wl_product['ID'] ); ?>" >X</button>
65
- </td>
66
- <td class="product-thumbnail">
67
- <?php
68
- $thumbnail = apply_filters( 'tinvwl_wishlist_item_thumbnail', $product->get_image(), $wl_product, $product );
69
-
70
- if ( ! $product->is_visible() ) {
71
- echo $thumbnail; // WPCS: xss ok.
72
- } else {
73
- printf( '<a href="%s">%s</a>', esc_url( $product_url ), $thumbnail ); // WPCS: xss ok.
74
- }
75
- ?>
76
- </td>
77
- <td class="product-name">
78
- <?php
79
- if ( ! $product->is_visible() ) {
80
- echo apply_filters( 'tinvwl_wishlist_item_name', $product->get_title(), $wl_product, $product ) . '&nbsp;'; // WPCS: xss ok.
81
- } else {
82
- echo apply_filters( 'tinvwl_wishlist_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product->get_title() ), $wl_product, $product ); // WPCS: xss ok.
83
- }
84
-
85
- echo apply_filters( 'tinvwl_wishlist_item_meta_data', tinv_wishlist_get_item_data( $product, $wl_product ), $wl_product, $product ); // WPCS: xss ok.
86
- ?>
87
- </td>
88
- <?php if ( $wishlist_table_row['colm_price'] ) { ?>
89
- <td class="product-price">
90
- <?php
91
- echo apply_filters( 'tinvwl_wishlist_item_price', $product->get_price_html(), $wl_product, $product ); // WPCS: xss ok.
92
- ?>
93
- </td>
94
- <?php } ?>
95
- <?php if ( $wishlist_table_row['colm_date'] ) { ?>
96
- <td class="product-date">
97
- <?php
98
- echo apply_filters( 'tinvwl_wishlist_item_date', sprintf( // WPCS: xss ok.
99
- '<time class="entry-date" datetime="%1$s">%2$s</time>', $wl_product['date'], mysql2date( get_option( 'date_format' ), $wl_product['date'] )
100
- ), $wl_product, $product );
101
- ?>
102
- </td>
103
- <?php } ?>
104
- <?php if ( $wishlist_table_row['colm_stock'] ) { ?>
105
- <td class="product-stock">
106
- <?php
107
- $availability = (array) $product->get_availability();
108
- if ( ! array_key_exists( 'availability', $availability ) ) {
109
- $availability['availability'] = '';
110
- }
111
- if ( ! array_key_exists( 'class', $availability ) ) {
112
- $availability['class'] = '';
113
- }
114
- $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
115
-
116
- echo apply_filters( 'tinvwl_wishlist_item_status', $availability_html, $availability['availability'], $wl_product, $product ); // WPCS: xss ok.
117
- ?>
118
- </td>
119
- <?php } ?>
120
- <?php if ( $wishlist_table_row['add_to_cart'] ) { ?>
121
- <td class="product-action">
122
- <?php
123
- if ( apply_filters( 'tinvwl_wishlist_item_action_add_to_cart', $wishlist_table_row['add_to_cart'], $wl_product, $product ) ) {
124
- ?>
125
- <button class="button alt" name="tinvwl-add-to-cart" value="<?php echo esc_attr( $wl_product['ID'] ); ?>"><i class="fa fa-shopping-cart"></i><span class="tinvwl-txt"><?php echo esc_html( apply_filters( 'tinvwl_wishlist_item_add_to_cart', $wishlist_table_row['text_add_to_cart'], $wl_product, $product ) ); ?></span></button>
126
- <?php } ?>
127
- </td>
128
- <?php } ?>
129
- </tr>
130
- <?php
131
- do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
132
- } // End if().
133
- } // End foreach().
134
- ?>
135
- <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
136
- </tbody>
137
- <tfoot>
138
- <tr>
139
- <td colspan="100">
140
- <?php do_action( 'tinvwl_after_wishlist_table', $wishlist ); ?>
141
- <?php wp_nonce_field( 'tinvwl_wishlist_owner', 'wishlist_nonce' ); ?>
142
- </td>
143
- </tr>
144
- </tfoot>
145
- </table>
146
- </form>
147
- <?php do_action( 'tinvwl_after_wishlist', $wishlist ); ?>
148
- <div class="tinv-lists-nav tinv-wishlist-clear">
149
- <?php do_action( 'tinvwl_pagenation_wishlist', $wishlist ); ?>
150
- </div>
151
- </div>
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Template for displaying wishlist.
4
+ *
5
+ * @version 1.6.1
6
+ * @package TInvWishlist\Template
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ ?>
14
+ <div class="tinv-wishlist woocommerce tinv-wishlist-clear">
15
+ <?php do_action( 'tinvwl_before_wishlist', $wishlist ); ?>
16
+ <?php if ( function_exists( 'wc_print_notices' ) ) {
17
+ wc_print_notices();
18
+ } ?>
19
+ <form action="<?php echo esc_url( tinv_url_wishlist() ); ?>" method="post" autocomplete="off">
20
+ <?php do_action( 'tinvwl_before_wishlist_table', $wishlist ); ?>
21
+ <table class="tinvwl-table-manage-list">
22
+ <thead>
23
+ <tr>
24
+ <?php if ( isset( $wishlist_table['colm_checkbox'] ) && $wishlist_table['colm_checkbox'] ) { ?>
25
+ <th class="product-cb"><input type="checkbox" class="global-cb"></th>
26
+ <?php } ?>
27
+ <th class="product-remove"></th>
28
+ <th class="product-thumbnail">&nbsp;</th>
29
+ <th class="product-name"><span
30
+ class="tinvwl-full"><?php esc_html_e( 'Product Name', 'ti-woocommerce-wishlist' ); ?></span><span
31
+ class="tinvwl-mobile"><?php esc_html_e( 'Product', 'ti-woocommerce-wishlist' ); ?></span></th>
32
+ <?php if ( isset( $wishlist_table_row['colm_price'] ) && $wishlist_table_row['colm_price'] ) { ?>
33
+ <th class="product-price"><?php esc_html_e( 'Unit Price', 'ti-woocommerce-wishlist' ); ?></th>
34
+ <?php } ?>
35
+ <?php if ( isset( $wishlist_table_row['colm_date'] ) && $wishlist_table_row['colm_date'] ) { ?>
36
+ <th class="product-date"><?php esc_html_e( 'Date Added', 'ti-woocommerce-wishlist' ); ?></th>
37
+ <?php } ?>
38
+ <?php if ( isset( $wishlist_table_row['colm_stock'] ) && $wishlist_table_row['colm_stock'] ) { ?>
39
+ <th class="product-stock"><?php esc_html_e( 'Stock Status', 'ti-woocommerce-wishlist' ); ?></th>
40
+ <?php } ?>
41
+ <?php if ( isset( $wishlist_table_row['add_to_cart'] ) && $wishlist_table_row['add_to_cart'] ) { ?>
42
+ <th class="product-action">&nbsp;</th>
43
+ <?php } ?>
44
+ </tr>
45
+ </thead>
46
+ <tbody>
47
+ <?php do_action( 'tinvwl_wishlist_contents_before' ); ?>
48
+
49
+ <?php
50
+ foreach ( $products as $wl_product ) {
51
+ $product = apply_filters( 'tinvwl_wishlist_item', $wl_product['data'] );
52
+ unset( $wl_product['data'] );
53
+ if ( $wl_product['quantity'] > 0 && apply_filters( 'tinvwl_wishlist_item_visible', true, $wl_product, $product ) ) {
54
+ $product_url = apply_filters( 'tinvwl_wishlist_item_url', $product->get_permalink(), $wl_product, $product );
55
+ do_action( 'tinvwl_wishlist_row_before', $wl_product, $product );
56
+ ?>
57
+ <tr class="<?php echo esc_attr( apply_filters( 'tinvwl_wishlist_item_class', 'wishlist_item', $wl_product, $product ) ); ?>">
58
+ <?php if ( isset( $wishlist_table['colm_checkbox'] ) && $wishlist_table['colm_checkbox'] ) { ?>
59
+ <td class="product-cb">
60
+ <?php
61
+ echo apply_filters( 'tinvwl_wishlist_item_cb', sprintf( // WPCS: xss ok.
62
+ '<input type="checkbox" name="wishlist_pr[]" value="%d">', esc_attr( $wl_product['ID'] )
63
+ ), $wl_product, $product );
64
+ ?>
65
+ </td>
66
+ <?php } ?>
67
+ <td class="product-remove">
68
+ <button type="submit" name="tinvwl-remove"
69
+ value="<?php echo esc_attr( $wl_product['ID'] ); ?>">X
70
+ </button>
71
+ </td>
72
+ <td class="product-thumbnail">
73
+ <?php
74
+ $thumbnail = apply_filters( 'tinvwl_wishlist_item_thumbnail', $product->get_image(), $wl_product, $product );
75
+
76
+ if ( ! $product->is_visible() ) {
77
+ echo $thumbnail; // WPCS: xss ok.
78
+ } else {
79
+ printf( '<a href="%s">%s</a>', esc_url( $product_url ), $thumbnail ); // WPCS: xss ok.
80
+ }
81
+ ?>
82
+ </td>
83
+ <td class="product-name">
84
+ <?php
85
+ if ( ! $product->is_visible() ) {
86
+ echo apply_filters( 'tinvwl_wishlist_item_name', $product->get_title(), $wl_product, $product ) . '&nbsp;'; // WPCS: xss ok.
87
+ } else {
88
+ echo apply_filters( 'tinvwl_wishlist_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product->get_title() ), $wl_product, $product ); // WPCS: xss ok.
89
+ }
90
+
91
+ echo apply_filters( 'tinvwl_wishlist_item_meta_data', tinv_wishlist_get_item_data( $product, $wl_product ), $wl_product, $product ); // WPCS: xss ok.
92
+ ?>
93
+ </td>
94
+ <?php if ( isset( $wishlist_table_row['colm_price'] ) && $wishlist_table_row['colm_price'] ) { ?>
95
+ <td class="product-price">
96
+ <?php
97
+ echo apply_filters( 'tinvwl_wishlist_item_price', $product->get_price_html(), $wl_product, $product ); // WPCS: xss ok.
98
+ ?>
99
+ </td>
100
+ <?php } ?>
101
+ <?php if ( isset( $wishlist_table_row['colm_date'] ) && $wishlist_table_row['colm_date'] ) { ?>
102
+ <td class="product-date">
103
+ <?php
104
+ echo apply_filters( 'tinvwl_wishlist_item_date', sprintf( // WPCS: xss ok.
105
+ '<time class="entry-date" datetime="%1$s">%2$s</time>', $wl_product['date'], mysql2date( get_option( 'date_format' ), $wl_product['date'] )
106
+ ), $wl_product, $product );
107
+ ?>
108
+ </td>
109
+ <?php } ?>
110
+ <?php if ( isset( $wishlist_table_row['colm_stock'] ) && $wishlist_table_row['colm_stock'] ) { ?>
111
+ <td class="product-stock">
112
+ <?php
113
+ $availability = (array) $product->get_availability();
114
+ if ( ! array_key_exists( 'availability', $availability ) ) {
115
+ $availability['availability'] = '';
116
+ }
117
+ if ( ! array_key_exists( 'class', $availability ) ) {
118
+ $availability['class'] = '';
119
+ }
120
+ $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
121
+
122
+ echo apply_filters( 'tinvwl_wishlist_item_status', $availability_html, $availability['availability'], $wl_product, $product ); // WPCS: xss ok.
123
+ ?>
124
+ </td>
125
+ <?php } ?>
126
+ <?php if ( isset( $wishlist_table_row['add_to_cart'] ) && $wishlist_table_row['add_to_cart'] ) { ?>
127
+ <td class="product-action">
128
+ <?php
129
+ if ( apply_filters( 'tinvwl_wishlist_item_action_add_to_cart', $wishlist_table_row['add_to_cart'], $wl_product, $product ) ) {
130
+ ?>
131
+ <button class="button alt" name="tinvwl-add-to-cart"
132
+ value="<?php echo esc_attr( $wl_product['ID'] ); ?>"><i
133
+ class="fa fa-shopping-cart"></i><span
134
+ class="tinvwl-txt"><?php echo esc_html( apply_filters( 'tinvwl_wishlist_item_add_to_cart', $wishlist_table_row['text_add_to_cart'], $wl_product, $product ) ); ?></span>
135
+ </button>
136
+ <?php } ?>
137
+ </td>
138
+ <?php } ?>
139
+ </tr>
140
+ <?php
141
+ do_action( 'tinvwl_wishlist_row_after', $wl_product, $product );
142
+ } // End if().
143
+ } // End foreach().
144
+ ?>
145
+ <?php do_action( 'tinvwl_wishlist_contents_after' ); ?>
146
+ </tbody>
147
+ <tfoot>
148
+ <tr>
149
+ <td colspan="100">
150
+ <?php do_action( 'tinvwl_after_wishlist_table', $wishlist ); ?>
151
+ <?php wp_nonce_field( 'tinvwl_wishlist_owner', 'wishlist_nonce' ); ?>
152
+ </td>
153
+ </tr>
154
+ </tfoot>
155
+ </table>
156
+ </form>
157
+ <?php do_action( 'tinvwl_after_wishlist', $wishlist ); ?>
158
+ <div class="tinv-lists-nav tinv-wishlist-clear">
159
+ <?php do_action( 'tinvwl_pagenation_wishlist', $wishlist ); ?>
160
+ </div>
161
+ </div>
ti-woocommerce-wishlist.php CHANGED
@@ -4,7 +4,7 @@
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.6.0
8
  * Requires at least: 4.5
9
  * Tested up to: 4.9
10
  * WC requires at least: 2.6
@@ -41,7 +41,7 @@ if ( ! defined( 'TINVWL_DOMAIN' ) ) {
41
  }
42
 
43
  if ( ! defined( 'TINVWL_FVERSION' ) ) {
44
- define( 'TINVWL_FVERSION', '1.6.0' );
45
  }
46
 
47
  if ( ! defined( 'TINVWL_LOAD_FREE' ) ) {
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.6.1
8
  * Requires at least: 4.5
9
  * Tested up to: 4.9
10
  * WC requires at least: 2.6
41
  }
42
 
43
  if ( ! defined( 'TINVWL_FVERSION' ) ) {
44
+ define( 'TINVWL_FVERSION', '1.6.1' );
45
  }
46
 
47
  if ( ! defined( 'TINVWL_LOAD_FREE' ) ) {
tinv-wishlists-function-integration.php CHANGED
@@ -1,1747 +1,1777 @@
1
- <?php
2
- /**
3
- * Support functions for other plugins
4
- *
5
- * @since 1.5.0
6
- * @package TInvWishlist
7
- */
8
-
9
- // If this file is called directly, abort.
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- die;
12
- }
13
-
14
- if ( ! function_exists( 'tinvwl_rocket_reject_uri' ) ) {
15
-
16
- /**
17
- * Disable cache for WP Rocket
18
- *
19
- * @param array $uri URI.
20
- *
21
- * @return array
22
- */
23
- function tinvwl_rocket_reject_uri( $uri = array() ) {
24
- $ids = array(
25
- tinv_get_option( 'page', 'wishlist' ),
26
- );
27
- $pages = $ids;
28
- $languages = apply_filters( 'wpml_active_languages', array(), array(
29
- 'skip_missing' => 0,
30
- 'orderby' => 'code',
31
- ) );
32
- if ( ! empty( $languages ) ) {
33
- foreach ( $ids as $id ) {
34
- foreach ( $languages as $l ) {
35
- $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
36
- }
37
- }
38
- $pages = array_unique( $pages );
39
- }
40
- $pages = array_filter( $pages );
41
- if ( ! empty( $pages ) ) {
42
- foreach ( $pages as $page ) {
43
- $uri[] = str_replace( get_site_url(), '', get_permalink( $page ) );
44
- }
45
- }
46
-
47
- return $uri;
48
- }
49
-
50
- add_filter( 'rocket_cache_reject_uri', 'tinvwl_rocket_reject_uri' );
51
- } // End if().
52
-
53
- if ( ! function_exists( 'tinvwl_rocket_reject_cookies' ) ) {
54
-
55
- /**
56
- * Disable cache for WP Rocket
57
- *
58
- * @param array $cookies Cookies.
59
- *
60
- * @return array
61
- */
62
- function tinvwl_rocket_reject_cookies( $cookies = array() ) {
63
- $cookies[] = 'tinv_wishlist';
64
-
65
- return $cookies;
66
- }
67
-
68
- add_filter( 'rocket_cache_reject_cookies', 'tinvwl_rocket_reject_cookies' );
69
- }
70
-
71
- if ( ! function_exists( 'tinvwl_supercache_reject_uri' ) ) {
72
-
73
- /**
74
- * Disable cache for WP Super Cache
75
- *
76
- * @global array $cache_rejected_uri
77
- *
78
- * @param string $buffer Intercepted the output of the page.
79
- *
80
- * @return string
81
- */
82
- function tinvwl_supercache_reject_uri( $buffer ) {
83
- global $cache_rejected_uri;
84
- if ( ! is_null( $cache_rejected_uri ) && is_array( $cache_rejected_uri ) ) {
85
- $ids = array(
86
- tinv_get_option( 'page', 'wishlist' ),
87
- );
88
- $pages = $ids;
89
- $languages = apply_filters( 'wpml_active_languages', array(), array(
90
- 'skip_missing' => 0,
91
- 'orderby' => 'code',
92
- ) );
93
- if ( ! empty( $languages ) ) {
94
- foreach ( $ids as $id ) {
95
- foreach ( $languages as $l ) {
96
- $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
97
- }
98
- }
99
- $pages = array_unique( $pages );
100
- }
101
- $pages = array_filter( $pages );
102
- if ( ! empty( $pages ) ) {
103
- foreach ( $pages as $page ) {
104
- $cache_rejected_uri[] = str_replace( get_site_url(), '', get_permalink( $page ) );
105
- }
106
- }
107
- }
108
-
109
- return $buffer;
110
- }
111
-
112
- add_filter( 'wp_cache_ob_callback_filter', 'tinvwl_supercache_reject_uri' );
113
- } // End if().
114
-
115
- if ( ! function_exists( 'tinvwl_w3total_reject_uri' ) ) {
116
-
117
- /**
118
- * Disable cache for W3 Total Cache
119
- */
120
- function tinvwl_w3total_reject_uri() {
121
- if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
122
- return;
123
- }
124
- $ids = array(
125
- tinv_get_option( 'page', 'wishlist' ),
126
- );
127
- $pages = $ids;
128
- $languages = apply_filters( 'wpml_active_languages', array(), array(
129
- 'skip_missing' => 0,
130
- 'orderby' => 'code',
131
- ) );
132
- if ( ! empty( $languages ) ) {
133
- foreach ( $ids as $id ) {
134
- foreach ( $languages as $l ) {
135
- $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
136
- }
137
- }
138
- $pages = array_unique( $pages );
139
- }
140
- $pages = array_filter( $pages );
141
- if ( ! empty( $pages ) ) {
142
- foreach ( $pages as $i => $page ) {
143
- $pages[ $i ] = preg_replace( "/^\//", '', str_replace( get_site_url(), '', get_permalink( $page ) ) ); // @codingStandardsIgnoreLine Squiz.Strings.DoubleQuoteUsage.NotRequired
144
- }
145
- }
146
- $pages = array_unique( $pages );
147
- $pages = array_filter( $pages );
148
-
149
- $config = w3_instance( 'W3_Config' );
150
- if ( ! empty( $pages ) ) {
151
- $sections = array( 'dbcache.reject.uri', 'pgcache.reject.uri' );
152
- foreach ( $sections as $section ) {
153
- $settings = array_map( 'trim', $config->get_array( $section ) );
154
- $changed = false;
155
- foreach ( $pages as $page ) {
156
- if ( ! in_array( $page, $settings ) ) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
157
- $settings[] = $page;
158
- $changed = true;
159
- }
160
- }
161
- if ( $changed ) {
162
- $config->set( $section, $settings );
163
- $config->save();
164
- }
165
- }
166
- }
167
-
168
- $settings = array_map( 'trim', $config->get_array( 'pgcache.reject.cookie' ) );
169
- if ( ! in_array( 'tinv_wishlist', $settings ) ) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
170
- $settings[] = 'tinv_wishlist';
171
- $config->set( 'pgcache.reject.cookie', $settings );
172
- $config->save();
173
- }
174
- }
175
-
176
- add_action( 'admin_init', 'tinvwl_w3total_reject_uri' );
177
- } // End if().
178
-
179
- if ( ! function_exists( 'tinvwl_wp_fastest_cache_reject' ) ) {
180
-
181
- /**
182
- * Disable cache for WP Fastest Cache
183
- */
184
- function tinvwl_wp_fastest_cache_reject() {
185
- if ( defined( 'WPFC_WP_PLUGIN_DIR' ) ) {
186
- if ( $rules_json = get_option( 'WpFastestCacheExclude' ) ) {
187
- if ( 'null' !== $rules_json ) {
188
- $ids = array(
189
- tinv_get_option( 'page', 'wishlist' ),
190
- tinv_get_option( 'page', 'manage' ),
191
- );
192
- $pages = $ids;
193
- $languages = apply_filters( 'wpml_active_languages', array(), array(
194
- 'skip_missing' => 0,
195
- 'orderby' => 'code',
196
- ) );
197
- if ( ! empty( $languages ) ) {
198
- foreach ( $ids as $id ) {
199
- foreach ( $languages as $l ) {
200
- $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
201
- }
202
- }
203
- $pages = array_unique( $pages );
204
- }
205
- $pages = array_filter( $pages );
206
- if ( ! empty( $pages ) ) {
207
- foreach ( $pages as $i => $page ) {
208
- $pages[ $i ] = preg_replace( "/^\//", '', str_replace( get_site_url(), '', get_permalink( $page ) ) ); // @codingStandardsIgnoreLine Squiz.Strings.DoubleQuoteUsage.NotRequired
209
- }
210
- }
211
- $pages = array_unique( $pages );
212
- $pages = array_filter( $pages );
213
-
214
- $rules_std = json_decode( $rules_json, true );
215
- $ex_pages = array();
216
- foreach ( $rules_std as $key => $value ) {
217
- $value['type'] = isset( $value['type'] ) ? $value['type'] : 'page';
218
- if ( 'page' === $value['type'] ) {
219
- $ex_pages[] = $value['content'];
220
- }
221
- }
222
- $ex_pages = array_unique( $ex_pages );
223
- $ex_pages = array_filter( $ex_pages );
224
- $changed = false;
225
-
226
- foreach ( $pages as $page ) {
227
- $page = preg_replace( '/\/$/', '', $page );
228
-
229
- if ( ! in_array( $page, $ex_pages ) ) {
230
- $changed = true;
231
- $rules_std[] = array(
232
- 'prefix' => 'startwith',
233
- 'content' => $page,
234
- 'type' => 'page',
235
- );
236
- }
237
- }
238
- if ( $changed ) {
239
- $data = json_encode( $rules_std );
240
- update_option( 'WpFastestCacheExclude', $data );
241
- }
242
- } // End if().
243
- } // End if().
244
- } // End if().
245
- }
246
-
247
- add_action( 'admin_init', 'tinvwl_wp_fastest_cache_reject' );
248
- } // End if().
249
-
250
- if ( function_exists( 'tinvwl_comet_cache_reject' ) ) {
251
-
252
- /**
253
- * Set define disabled for Comet Cache
254
- *
255
- * @param mixed $data Any content.
256
- *
257
- * @return mixed
258
- */
259
- function tinvwl_comet_cache_reject( $data = '' ) {
260
- define( 'COMET_CACHE_ALLOWED', false );
261
-
262
- return $data;
263
- }
264
-
265
- add_filter( 'tinvwl_addtowishlist_return_ajax', 'tinvwl_comet_cache_reject' );
266
- add_action( 'tinvwl_before_action_owner', 'tinvwl_comet_cache_reject' );
267
- add_action( 'tinvwl_before_action_user', 'tinvwl_comet_cache_reject' );
268
- add_action( 'tinvwl_addproduct_tocart', 'tinvwl_comet_cache_reject' );
269
- add_action( 'tinv_wishlist_addtowishlist_button', 'tinvwl_comet_cache_reject' );
270
- add_action( 'tinv_wishlist_addtowishlist_dialogbox', 'tinvwl_comet_cache_reject' );
271
- }
272
-
273
- if ( ! function_exists( 'gf_productaddon_support' ) ) {
274
-
275
- /**
276
- * Add supports WooCommerce - Gravity Forms Product Add-Ons
277
- */
278
- function gf_productaddon_support() {
279
- if ( ! class_exists( 'woocommerce_gravityforms' ) ) {
280
- return false;
281
- }
282
- if ( ! function_exists( 'gf_productaddon_text_button' ) ) {
283
-
284
- /**
285
- * Change text for button add to cart
286
- *
287
- * @param string $text_add_to_cart Text "Add to cart".
288
- * @param array $wl_product Wishlist product.
289
- * @param object $product WooCommerce Product.
290
- *
291
- * @return string
292
- */
293
- function gf_productaddon_text_button( $text_add_to_cart, $wl_product, $product ) {
294
- $gravity_form_data = get_post_meta( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ), '_gravity_form_data', true );
295
-
296
- return ( $gravity_form_data ) ? __( 'Select options', 'woocommerce' ) : $text_add_to_cart;
297
- }
298
-
299
- add_filter( 'tinvwl_wishlist_item_add_to_cart', 'gf_productaddon_text_button', 10, 3 );
300
- }
301
-
302
- if ( ! function_exists( 'gf_productaddon_run_action_button' ) ) {
303
-
304
- /**
305
- * Check for make redirect to url
306
- *
307
- * @param boolean $need Need redirect or not.
308
- * @param object $product WooCommerce Product.
309
- *
310
- * @return boolean
311
- */
312
- function gf_productaddon_run_action_button( $need, $product ) {
313
- $gravity_form_data = get_post_meta( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ), '_gravity_form_data', true );
314
-
315
- return ( $gravity_form_data ) ? true : $need;
316
- }
317
-
318
- add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'gf_productaddon_run_action_button', 10, 2 );
319
- }
320
-
321
- if ( ! function_exists( 'gf_productaddon_action_button' ) ) {
322
-
323
- /**
324
- * Redirect url
325
- *
326
- * @param string $url Redirect URL.
327
- * @param object $product WooCommerce Product.
328
- *
329
- * @return string
330
- */
331
- function gf_productaddon_action_button( $url, $product ) {
332
- $gravity_form_data = get_post_meta( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ), '_gravity_form_data', true );
333
-
334
- return ( $gravity_form_data ) ? $product->get_permalink() : $url;
335
- }
336
-
337
- add_filter( 'tinvwl_product_add_to_cart_redirect_url', 'gf_productaddon_action_button', 10, 2 );
338
- }
339
- }
340
-
341
- add_action( 'init', 'gf_productaddon_support' );
342
- } // End if().
343
-
344
- if ( ! function_exists( 'tinvwl_wpml_product_get' ) ) {
345
-
346
- /**
347
- * Change product data if product need translate
348
- *
349
- * @param array $product Wishlistl product.
350
- *
351
- * @return array
352
- */
353
- function tinvwl_wpml_product_get( $product ) {
354
- if ( array_key_exists( 'data', $product ) ) {
355
- $_product_id = $product_id = $product['product_id'];
356
- $_variation_id = $variation_id = $product['variation_id'];
357
- $_product_id = apply_filters( 'wpml_object_id', $_product_id, 'product', true );
358
- if ( ! empty( $_variation_id ) ) {
359
- $_variation_id = apply_filters( 'wpml_object_id', $_variation_id, 'product', true );
360
- }
361
- if ( $_product_id !== $product_id || $_variation_id !== $variation_id ) {
362
- $product['data'] = wc_get_product( $variation_id ? $_variation_id : $_product_id );
363
- }
364
- }
365
-
366
- return $product;
367
- }
368
-
369
- add_filter( 'tinvwl_wishlist_product_get', 'tinvwl_wpml_product_get' );
370
- }
371
-
372
- if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare' ) ) {
373
-
374
- /**
375
- * Change product data if product need translate in WooCommerce Multilingual
376
- *
377
- * @param array $post_data Data for wishlist.
378
- *
379
- * @return array
380
- */
381
- function tinvwl_wpml_addtowishlist_prepare( $post_data ) {
382
- if ( class_exists( 'woocommerce_wpml' ) ) {
383
- $woo_wpml = woocommerce_wpml::instance();
384
- if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) ) {
385
- $post_data['product_id'] = $woo_wpml->products->get_original_product_id( $post_data['product_id'] );
386
- }
387
- if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) && array_key_exists( 'product_variation', $post_data ) && ! empty( $post_data['product_variation'] ) ) {
388
- $original_product_language = $woo_wpml->products->get_original_product_language( $post_data['product_id'] );
389
- $post_data['product_variation'] = apply_filters( 'translate_object_id', $post_data['product_variation'], 'product_variation', true, $original_product_language );
390
- }
391
- }
392
-
393
- return $post_data;
394
- }
395
-
396
- add_filter( 'tinvwl_addtowishlist_prepare', 'tinvwl_wpml_addtowishlist_prepare' );
397
- }
398
-
399
- if ( ! function_exists( 'tinvwl_wpml_addtowishlist_out_prepare' ) ) {
400
-
401
- /**
402
- * Change product data if product need translate in WooCommerce Multilingual
403
- *
404
- * @param array $attr Data for wishlist.
405
- *
406
- * @return array
407
- */
408
- function tinvwl_wpml_addtowishlist_out_prepare( $attr ) {
409
- if ( class_exists( 'woocommerce_wpml' ) ) {
410
- $woo_wpml = woocommerce_wpml::instance();
411
- if ( array_key_exists( 'product_id', $attr ) && ! empty( $attr['product_id'] ) ) {
412
- $attr['product_id'] = $woo_wpml->products->get_original_product_id( $attr['product_id'] );
413
- }
414
- if ( array_key_exists( 'product_id', $attr ) && ! empty( $attr['product_id'] ) && array_key_exists( 'variation_id', $attr ) && ! empty( $attr['variation_id'] ) ) {
415
- $original_product_language = $woo_wpml->products->get_original_product_language( $attr['product_id'] );
416
- $attr['variation_id'] = apply_filters( 'translate_object_id', $attr['variation_id'], 'product_variation', true, $original_product_language );
417
- }
418
- }
419
-
420
- return $attr;
421
- }
422
-
423
- add_filter( 'tinvwl_addtowishlist_out_prepare_attr', 'tinvwl_wpml_addtowishlist_out_prepare' );
424
- }
425
-
426
- if ( ! function_exists( 'tinvwl_wpml_addtowishlist_out_prepare_product' ) ) {
427
-
428
- /**
429
- * Change product if product need translate in WooCommerce Multilingual
430
- *
431
- * @param \WC_Product $product WooCommerce Product.
432
- *
433
- * @return \WC_Product
434
- */
435
- function tinvwl_wpml_addtowishlist_out_prepare_product( $product ) {
436
- if ( class_exists( 'woocommerce_wpml' ) && is_object( $product ) ) {
437
- $woo_wpml = woocommerce_wpml::instance();
438
- $product_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() );
439
- $variation_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 );
440
-
441
- if ( ! empty( $product_id ) ) {
442
- $product_id = $woo_wpml->products->get_original_product_id( $product_id );
443
- }
444
- if ( ! empty( $product_id ) && ! empty( $variation_id ) ) {
445
- $original_product_language = $woo_wpml->products->get_original_product_language( $product_id );
446
- $variation_id = apply_filters( 'translate_object_id', $variation_id, 'product_variation', true, $original_product_language );
447
- }
448
- if ( ! empty( $product_id ) ) {
449
- $product = wc_get_product( $variation_id ? $variation_id : $product_id );
450
- }
451
- }
452
-
453
- return $product;
454
- }
455
-
456
- add_filter( 'tinvwl_addtowishlist_out_prepare_product', 'tinvwl_wpml_addtowishlist_out_prepare_product' );
457
- }
458
-
459
- if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare_form' ) ) {
460
-
461
- /**
462
- * Change product form data if product need translate in WooCommerce Multilingual
463
- *
464
- * @param array $post_data Data for wishlist.
465
- *
466
- * @return array
467
- */
468
- function tinvwl_wpml_addtowishlist_prepare_form( $post_data ) {
469
- if ( class_exists( 'woocommerce_wpml' ) && is_array( $post_data ) ) {
470
- $woo_wpml = woocommerce_wpml::instance();
471
- if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) ) {
472
- $post_data['product_id'] = $woo_wpml->products->get_original_product_id( $post_data['product_id'] );
473
- }
474
- if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) && array_key_exists( 'variation_id', $post_data ) && ! empty( $post_data['variation_id'] ) ) {
475
- $original_product_language = $woo_wpml->products->get_original_product_language( $post_data['product_id'] );
476
- $post_data['variation_id'] = apply_filters( 'translate_object_id', $post_data['variation_id'], 'product_variation', true, $original_product_language );
477
- }
478
- }
479
-
480
- return $post_data;
481
- }
482
-
483
- add_filter( 'tinvwl_addtowishlist_prepare_form', 'tinvwl_wpml_addtowishlist_prepare_form' );
484
- }
485
-
486
- if ( ! function_exists( 'tinvwl_wpml_filter_link' ) ) {
487
-
488
- /**
489
- * Corect add wishlist key for WPML plugin.
490
- *
491
- * @param string $full_link Link for page.
492
- * @param array $l Language.
493
- *
494
- * @return string
495
- */
496
- function tinvwl_wpml_filter_link( $full_link, $l ) {
497
- $share_key = get_query_var( 'tinvwlID', null );
498
- if ( ! empty( $share_key ) ) {
499
- if ( get_option( 'permalink_structure' ) ) {
500
- $suffix = '';
501
- if ( preg_match( '/([^\?]+)\?*?(.*)/i', $full_link, $_full_link ) ) {
502
- $full_link = $_full_link[1];
503
- $suffix = $_full_link[2];
504
- }
505
- if ( ! preg_match( '/\/$/', $full_link ) ) {
506
- $full_link .= '/';
507
- }
508
- $full_link .= $share_key . '/' . $suffix;
509
- } else {
510
- $full_link .= add_query_arg( 'tinvwlID', $share_key, $full_link );
511
- }
512
- }
513
-
514
- return $full_link;
515
- }
516
-
517
- add_filter( 'WPML_filter_link', 'tinvwl_wpml_filter_link', 0, 2 );
518
- }
519
-
520
- if ( ! function_exists( 'tinvwl_gift_card_add' ) ) {
521
-
522
- /**
523
- * Support WooCommerce - Gift Cards
524
- * Redirect to page gift card, if requires that customers enter a name and email when purchasing a Gift Card.
525
- *
526
- * @param boolean $redirect Default value to redirect.
527
- * @param \WC_Product $product Product data.
528
- *
529
- * @return boolean
530
- */
531
- function tinvwl_gift_card_add( $redirect, $product ) {
532
- if ( $redirect ) {
533
- return true;
534
- }
535
- $is_required_field_giftcard = get_option( 'woocommerce_enable_giftcard_info_requirements' );
536
-
537
- if ( 'yes' == $is_required_field_giftcard ) { // WPCS: loose comparison ok.
538
- $is_giftcard = get_post_meta( $product->get_id(), '_giftcard', true );
539
- if ( 'yes' == $is_giftcard ) { // WPCS: loose comparison ok.
540
- return true;
541
- }
542
- }
543
-
544
- return $redirect;
545
- }
546
-
547
- add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'tinvwl_gift_card_add', 20, 2 );
548
- }
549
-
550
- if ( ! function_exists( 'tinvwl_gift_card_add_url' ) ) {
551
-
552
- /**
553
- * Support WooCommerce - Gift Cards
554
- * Redirect to page gift card, if requires that customers enter a name and email when purchasing a Gift Card.
555
- *
556
- * @param string $redirect_url Default value to redirect.
557
- * @param \WC_Product $product Product data.
558
- *
559
- * @return boolean
560
- */
561
- function tinvwl_gift_card_add_url( $redirect_url, $product ) {
562
- $is_required_field_giftcard = get_option( 'woocommerce_enable_giftcard_info_requirements' );
563
-
564
- if ( 'yes' == $is_required_field_giftcard ) { // WPCS: loose comparison ok.
565
- $is_giftcard = get_post_meta( $product->get_id(), '_giftcard', true );
566
- if ( 'yes' == $is_giftcard ) { // WPCS: loose comparison ok.
567
- return $product->get_permalink();
568
- }
569
- }
570
-
571
- return $redirect_url;
572
- }
573
-
574
- add_filter( 'tinvwl_product_add_to_cart_redirect_url', 'tinvwl_gift_card_add_url', 20, 2 );
575
- }
576
-
577
- if ( ! function_exists( 'tinv_wishlist_meta_support_rpgiftcards' ) ) {
578
-
579
- /**
580
- * Set descrition for meta WooCommerce - Gift Cards
581
- *
582
- * @param array $meta Meta array.
583
- *
584
- * @return array
585
- */
586
- function tinv_wishlist_metasupport_rpgiftcards( $meta ) {
587
- foreach ( $meta as $key => $data ) {
588
- switch ( $data['key'] ) {
589
- case 'rpgc_note':
590
- $meta[ $key ]['key'] = __( 'Note', 'rpgiftcards' );
591
- break;
592
- case 'rpgc_to':
593
- $meta[ $key ]['key'] = ( get_option( 'woocommerce_giftcard_to' ) <> null ? get_option( 'woocommerce_giftcard_to' ) : __( 'To', 'rpgiftcards' ) ); // WPCS: loose comparison ok.
594
- break;
595
- case 'rpgc_to_email':
596
- $meta[ $key ]['key'] = ( get_option( 'woocommerce_giftcard_toEmail' ) <> null ? get_option( 'woocommerce_giftcard_toEmail' ) : __( 'To Email', 'rpgiftcards' ) ); // WPCS: loose comparison ok.
597
- break;
598
- case 'rpgc_address':
599
- $meta[ $key ]['key'] = ( get_option( 'woocommerce_giftcard_address' ) <> null ? get_option( 'woocommerce_giftcard_address' ) : __( 'Address', 'rpgiftcards' ) ); // WPCS: loose comparison ok.
600
- break;
601
- case 'rpgc_reload_card':
602
- $meta[ $key ]['key'] = __( 'Reload existing Gift Card', 'rpgiftcards' );
603
- break;
604
- case 'rpgc_description':
605
- case 'rpgc_reload_check':
606
- unset( $meta[ $key ] );
607
- break;
608
- }
609
- }
610
-
611
- return $meta;
612
- }
613
-
614
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_rpgiftcards' );
615
- } // End if().
616
-
617
- if ( ! function_exists( 'tinv_wishlist_metaprepare_rpgiftcards' ) ) {
618
-
619
- /**
620
- * Prepare save meta for WooCommerce - Gift Cards
621
- *
622
- * @param array $meta Meta array.
623
- *
624
- * @return array
625
- */
626
- function tinv_wishlist_metaprepare_rpgiftcards( $meta ) {
627
- if ( array_key_exists( 'rpgc_reload_check', $meta ) ) {
628
- foreach ( array( 'rpgc_note', 'rpgc_to', 'rpgc_to_email', 'rpgc_address' ) as $value ) {
629
- if ( array_key_exists( $value, $meta ) ) {
630
- unset( $meta[ $value ] );
631
- }
632
- }
633
- }
634
-
635
- return $meta;
636
- }
637
-
638
- add_filter( 'tinvwl_product_prepare_meta', 'tinv_wishlist_metaprepare_rpgiftcards' );
639
- }
640
-
641
- if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_bookings' ) ) {
642
-
643
- /**
644
- * Set descrition for meta WooCommerce Bookings
645
- *
646
- * @param array $meta Meta array.
647
- * @param integer $product_id Priduct ID.
648
- * @param integer $variation_id Variation Product ID.
649
- *
650
- * @return array
651
- */
652
- function tinv_wishlist_metasupport_woocommerce_bookings( $meta, $product_id, $variation_id ) {
653
- if ( ! class_exists( 'WC_Booking_Form' ) || ! function_exists( 'is_wc_booking_product' ) ) {
654
- return $meta;
655
- }
656
- $product = wc_get_product( $variation_id ? $variation_id : $product_id );
657
- if ( is_wc_booking_product( $product ) ) {
658
- $booking_form = new WC_Booking_Form( $product );
659
- $post_data = array();
660
- foreach ( $meta as $data ) {
661
- $post_data[ $data['key'] ] = $data['display'];
662
- }
663
- $booking_data = $booking_form->get_posted_data( $post_data );
664
- $meta = array();
665
- foreach ( $booking_data as $key => $value ) {
666
- if ( ! preg_match( '/^_/', $key ) ) {
667
- $meta[ $key ] = array(
668
- 'key' => get_wc_booking_data_label( $key, $product ),
669
- 'display' => $value,
670
- );
671
- }
672
- }
673
- }
674
-
675
- return $meta;
676
- }
677
-
678
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_bookings', 10, 3 );
679
- } // End if().
680
-
681
- if ( ! function_exists( 'tinvwl_item_price_woocommerce_bookings' ) ) {
682
-
683
- /**
684
- * Modify price for WooCommerce Bookings
685
- *
686
- * @param string $price Returned price.
687
- * @param array $wl_product Wishlist Product.
688
- * @param \WC_Product $product Woocommerce Product.
689
- *
690
- * @return string
691
- */
692
- function tinvwl_item_price_woocommerce_bookings( $price, $wl_product, $product ) {
693
- if ( ! class_exists( 'WC_Booking_Form' ) || ! function_exists( 'is_wc_booking_product' ) ) {
694
- return $price;
695
- }
696
- if ( is_wc_booking_product( $product ) && array_key_exists( 'meta', $wl_product ) ) {
697
- $booking_form = new WC_Booking_Form( $product );
698
- $cost = $booking_form->calculate_booking_cost( $wl_product['meta'] );
699
- if ( is_wp_error( $cost ) ) {
700
- return $price;
701
- }
702
-
703
- $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
704
-
705
- if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
706
- if ( function_exists( 'wc_get_price_excluding_tax' ) ) {
707
- $display_price = wc_get_price_including_tax( $product, array( 'price' => $cost ) );
708
- } else {
709
- $display_price = $product->get_price_including_tax( 1, $cost );
710
- }
711
- } else {
712
- if ( function_exists( 'wc_get_price_excluding_tax' ) ) {
713
- $display_price = wc_get_price_excluding_tax( $product, array( 'price' => $cost ) );
714
- } else {
715
- $display_price = $product->get_price_excluding_tax( 1, $cost );
716
- }
717
- }
718
-
719
- if ( version_compare( WC_VERSION, '2.4.0', '>=' ) ) {
720
- $price_suffix = $product->get_price_suffix( $cost, 1 );
721
- } else {
722
- $price_suffix = $product->get_price_suffix();
723
- }
724
- $price = wc_price( $display_price ) . $price_suffix;
725
- }
726
-
727
- return $price;
728
- }
729
-
730
- add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_bookings', 10, 3 );
731
- } // End if().
732
-
733
- if ( ! function_exists( 'tinvwl_item_status_woocommerce_bookings' ) ) {
734
-
735
- /**
736
- * Modify availability for WooCommerce Bookings
737
- *
738
- * @param string $status Status availability.
739
- * @param string $availability Default availability.
740
- * @param array $wl_product Wishlist Product.
741
- * @param \WC_Product $product Woocommerce Product.
742
- *
743
- * @return type
744
- */
745
- function tinvwl_item_status_woocommerce_bookings( $status, $availability, $wl_product, $product ) {
746
- if ( ! class_exists( 'WC_Booking_Form' ) || ! function_exists( 'is_wc_booking_product' ) ) {
747
- return $status;
748
- }
749
- if ( is_wc_booking_product( $product ) && array_key_exists( 'meta', $wl_product ) ) {
750
- $booking_form = new WC_Booking_Form( $product );
751
- $cost = $booking_form->calculate_booking_cost( $wl_product['meta'] );
752
- if ( is_wp_error( $cost ) ) {
753
- return '<p class="stock out-of-stock"><span><i class="fa fa-times"></i></span><span>' . $cost->get_error_message() . '</span></p>';
754
- }
755
- }
756
-
757
- return $status;
758
- }
759
-
760
- add_filter( 'tinvwl_wishlist_item_status', 'tinvwl_item_status_woocommerce_bookings', 10, 4 );
761
- }
762
-
763
- if ( ! function_exists( 'tinv_wishlist_metasupport_wc_gf_addons' ) ) {
764
-
765
- /**
766
- * Set descrition for meta WooCommerce - Gravity Forms Product Add-Ons
767
- *
768
- * @param array $meta Meta array.
769
- *
770
- * @return array
771
- */
772
- function tinv_wishlist_metasupport_wc_gf_addons( $meta ) {
773
- if ( array_key_exists( 'wc_gforms_form_id', $meta ) && class_exists( 'RGFormsModel' ) ) {
774
- $form_meta = RGFormsModel::get_form_meta( $meta['wc_gforms_form_id']['display'] );
775
- if ( array_key_exists( 'fields', $form_meta ) ) {
776
- $_meta = array();
777
- foreach ( $form_meta['fields'] as $field ) {
778
- $field_name = $field->get_first_input_id( array( 'id' => 0 ) );
779
- if ( array_key_exists( $field_name, $meta ) ) {
780
- $meta[ $field_name ]['key'] = $field->label;
781
- $_meta[ $field_name ] = $meta[ $field_name ];
782
- }
783
- }
784
- $meta = $_meta;
785
- }
786
- }
787
-
788
- return $meta;
789
- }
790
-
791
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_wc_gf_addons' );
792
- }
793
-
794
- if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_composite_products' ) ) {
795
-
796
- /**
797
- * Set descrition for meta WooCommerce Composite Products
798
- *
799
- * @param array $meta Meta array.
800
- * @param integer $product_id Product ID.
801
- *
802
- * @return array
803
- */
804
- function tinv_wishlist_metasupport_woocommerce_composite_products( $meta, $product_id ) {
805
- if ( array_key_exists( 'wccp_component_selection', $meta ) && is_array( $meta['wccp_component_selection'] ) ) {
806
- $meta = array();
807
- } // End if().
808
-
809
- return $meta;
810
- }
811
-
812
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_composite_products', 10, 2 );
813
- } // End if().
814
-
815
- if ( ! function_exists( 'tinvwl_row_woocommerce_composite_products' ) ) {
816
-
817
- /**
818
- * Add rows for sub product for WooCommerce Composite Products
819
- *
820
- * @param array $wl_product Wishlist Product.
821
- * @param \WC_Product $product Woocommerce Product.
822
- */
823
- function tinvwl_row_woocommerce_composite_products( $wl_product, $product ) {
824
- if ( is_object( $product ) && $product->is_type( 'composite' ) && array_key_exists( 'wccp_component_selection', $wl_product['meta'] ) ) {
825
- $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
826
-
827
- $components = $product->get_components();
828
- foreach ( $components as $component_id => $component ) {
829
- $composited_product_id = ! empty( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) : '';
830
- $composited_product_quantity = isset( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) : $component->get_quantity( 'min' );
831
-
832
- $composited_variation_id = isset( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) ? wc_clean( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) : '';
833
-
834
- if ( $composited_product_id ) {
835
-
836
- $composited_product_wrapper = $component->get_option( $composited_variation_id ? $composited_variation_id : $composited_product_id );
837
-
838
- if ( ! $composited_product_wrapper ) {
839
- continue;
840
- }
841
-
842
- $composited_product = $composited_product_wrapper->get_product();
843
-
844
- if ( $composited_product->is_sold_individually() && $composited_product_quantity > 1 ) {
845
- $composited_product_quantity = 1;
846
- }
847
-
848
- $product_url = $composited_product->get_permalink();
849
- $product_image = $composited_product->get_image();
850
- $product_title = $composited_product->get_title();
851
- $product_price = $composited_product->get_price_html();
852
- if ( $composited_product->is_visible() ) {
853
- $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
854
- $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
855
- }
856
- $product_title .= tinv_wishlist_get_item_data( $composited_product, $wl_product );
857
-
858
- $availability = (array) $composited_product->get_availability();
859
- if ( ! array_key_exists( 'availability', $availability ) ) {
860
- $availability['availability'] = '';
861
- }
862
- if ( ! array_key_exists( 'class', $availability ) ) {
863
- $availability['class'] = '';
864
- }
865
- $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
866
- $row_string = '<tr>';
867
- $row_string .= '<td colspan="2"></td>&nbsp;<td class="product-thumbnail">%2$s</td><td class="product-name">%1$s:<br/>%3$s</td>';
868
- if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
869
- $row_string .= '<td class="product-price">%3$s &times; %6$s</td>';
870
- }
871
- if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
872
- $row_string .= '<td class="product-date">&nbsp;</td>';
873
- }
874
- if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
875
- $row_string .= '<td class="product-stock">%5$s</td>';
876
- }
877
- if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
878
- $row_string .= '<td class="product-action">&nbsp;</td>';
879
- }
880
- $row_string .= '</tr>';
881
-
882
- echo sprintf( $row_string, $component->get_title(), $product_image, $product_title, $product_price, $availability_html, $composited_product_quantity * $product_quantity ); // WPCS: xss ok.
883
- } // End if().
884
- } // End foreach().
885
- } // End if().
886
- }
887
-
888
- add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_composite_products', 10, 2 );
889
- } // End if().
890
-
891
- if ( ! function_exists( 'tinvwl_item_price_woocommerce_composite_products' ) ) {
892
-
893
- /**
894
- * Modify price for WooCommerce Composite Products
895
- *
896
- * @param string $price Returned price.
897
- * @param array $wl_product Wishlist Product.
898
- * @param \WC_Product $product Woocommerce Product.
899
- *
900
- * @return string
901
- */
902
- function tinvwl_item_price_woocommerce_composite_products( $price, $wl_product, $product ) {
903
- if ( is_object( $product ) && $product->is_type( 'composite' ) && array_key_exists( 'wccp_component_selection', $wl_product['meta'] ) ) {
904
- $components = $product->get_components();
905
- $_price = $product->get_price();
906
- $regular_price = $product->get_regular_price();
907
- foreach ( $components as $component_id => $component ) {
908
- $composited_product_id = ! empty( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) : '';
909
- $composited_product_quantity = isset( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) : $component->get_quantity( 'min' );
910
-
911
- $composited_variation_id = isset( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) ? wc_clean( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) : '';
912
-
913
- if ( $composited_product_id ) {
914
- $composited_product_wrapper = $component->get_option( $composited_variation_id ? $composited_variation_id : $composited_product_id );
915
- if ( $component->is_priced_individually() ) {
916
- $_price += $composited_product_wrapper->get_price() * $composited_product_quantity;
917
- $regular_price += $composited_product_wrapper->get_regular_price() * $composited_product_quantity;
918
- }
919
- }
920
- }
921
- if ( $_price == $regular_price ) {
922
- $price = wc_price( $_price ) . $product->get_price_suffix();
923
- } else {
924
- $price = wc_format_sale_price( $regular_price, $_price ) . $product->get_price_suffix();
925
- }
926
- }
927
-
928
- return $price;
929
- }
930
-
931
- add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_composite_products', 10, 3 );
932
- } // End if().
933
-
934
- if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_bundles' ) ) {
935
-
936
- /**
937
- * Set descrition for meta WooCommerce Product Bundles
938
- *
939
- * @param array $meta Meta array.
940
- * @param integer $product_id Product ID.
941
- *
942
- * @return array
943
- */
944
- function tinv_wishlist_metasupport_woocommerce_product_bundles( $meta, $product_id ) {
945
- $product = wc_get_product( $product_id );
946
- if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
947
- $meta = array();
948
- }
949
-
950
- return $meta;
951
- }
952
-
953
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_product_bundles', 10, 2 );
954
- } // End if().
955
-
956
- if ( ! function_exists( 'tinvwl_row_woocommerce_product_bundles' ) ) {
957
-
958
- /**
959
- * Add rows for sub product for WooCommerce Product Bundles
960
- *
961
- * @param array $wl_product Wishlist Product.
962
- * @param \WC_Product $product Woocommerce Product.
963
- */
964
- function tinvwl_row_woocommerce_product_bundles( $wl_product, $product ) {
965
- if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
966
- $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
967
-
968
- $product_id = WC_PB_Core_Compatibility::get_id( $product );
969
- $bundled_items = $product->get_bundled_items();
970
- if ( ! empty( $bundled_items ) ) {
971
- foreach ( $bundled_items as $bundled_item_id => $bundled_item ) {
972
- $bundled_product_id = $bundled_item->product_id;
973
- $bundled_item_variation_id_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_variation_id_' . $bundled_item_id;
974
- $bundled_variation_id = absint( isset( $wl_product['meta'][ $bundled_item_variation_id_request_key ] ) ? $wl_product['meta'][ $bundled_item_variation_id_request_key ] : 0 );
975
- if ( ! empty( $bundled_variation_id ) ) {
976
- $bundled_item->product = wc_get_product( $bundled_variation_id );
977
- }
978
- $bundled_product_type = $bundled_item->product->get_type();
979
- $is_optional = $bundled_item->is_optional();
980
-
981
- $bundled_item_quantity_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_quantity_' . $bundled_item_id;
982
- $bundled_product_qty = isset( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) ? absint( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) : $bundled_item->get_quantity();
983
-
984
- if ( $is_optional ) {
985
-
986
- /** Documented in method 'get_posted_bundle_configuration'. */
987
- $bundled_item_selected_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_selected_optional_' . $bundled_item_id;
988
-
989
- if ( ! array_key_exists( $bundled_item_selected_request_key, $wl_product['meta'] ) ) {
990
- $bundled_product_qty = 0;
991
- }
992
- }
993
- if ( 0 === $bundled_product_qty || 'visible' != $bundled_item->cart_visibility ) {
994
- continue;
995
- }
996
-
997
- $product_url = $bundled_item->product->get_permalink();
998
- $product_image = $bundled_item->product->get_image();
999
- $product_title = $bundled_item->product->get_title();
1000
- $product_price = $bundled_item->product->get_price_html();
1001
- if ( $bundled_item->product->is_visible() ) {
1002
- $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
1003
- $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
1004
- }
1005
- $product_title .= tinv_wishlist_get_item_data( $bundled_item->product, $wl_product );
1006
-
1007
- $availability = (array) $bundled_item->product->get_availability();
1008
- if ( ! array_key_exists( 'availability', $availability ) ) {
1009
- $availability['availability'] = '';
1010
- }
1011
- if ( ! array_key_exists( 'class', $availability ) ) {
1012
- $availability['class'] = '';
1013
- }
1014
- $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1015
- $row_string = '<tr>';
1016
- $row_string .= '<td colspan="2">&nbsp;</td><td class="product-thumbnail">%1$s</td><td class="product-name">%2$s</td>';
1017
- if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
1018
- $row_string .= '<td class="product-price">%3$s &times; %5$s</td>';
1019
- }
1020
- if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
1021
- $row_string .= '<td class="product-date">&nbsp;</td>';
1022
- }
1023
- if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
1024
- $row_string .= '<td class="product-stock">%4$s</td>';
1025
- }
1026
-
1027
- if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
1028
- $row_string .= '<td class="product-action">&nbsp;</td>';
1029
- }
1030
- $row_string .= '</tr>';
1031
-
1032
- echo sprintf( $row_string, $product_image, $product_title, $product_price, $availability_html, $bundled_product_qty ); // WPCS: xss ok.
1033
- } // End foreach().
1034
- } // End if().
1035
- } // End if().
1036
- }
1037
-
1038
- add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_product_bundles', 10, 2 );
1039
- } // End if().
1040
-
1041
- if ( ! function_exists( 'tinvwl_item_price_woocommerce_product_bundles' ) ) {
1042
-
1043
- /**
1044
- * Modify price for WooCommerce Product Bundles
1045
- *
1046
- * @param string $price Returned price.
1047
- * @param array $wl_product Wishlist Product.
1048
- * @param \WC_Product $product Woocommerce Product.
1049
- *
1050
- * @return string
1051
- */
1052
- function tinvwl_item_price_woocommerce_product_bundles( $price, $wl_product, $product ) {
1053
- if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
1054
-
1055
- $bundle_price = $product->get_price();
1056
- $product_id = WC_PB_Core_Compatibility::get_id( $product );
1057
- $bundled_items = $product->get_bundled_items();
1058
-
1059
- if ( ! empty( $bundled_items ) ) {
1060
-
1061
- $bundled_items_price = 0.0;
1062
-
1063
- foreach ( $bundled_items as $bundled_item_id => $bundled_item ) {
1064
- $is_optional = $bundled_item->is_optional();
1065
-
1066
- $bundled_item_quantity_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_quantity_' . $bundled_item_id;
1067
- $bundled_product_qty = isset( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) ? absint( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) : $bundled_item->get_quantity();
1068
-
1069
- if ( $is_optional ) {
1070
-
1071
- /** Documented in method 'get_posted_bundle_configuration'. */
1072
- $bundled_item_selected_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_selected_optional_' . $bundled_item_id;
1073
-
1074
- if ( ! array_key_exists( $bundled_item_selected_request_key, $wl_product['meta'] ) ) {
1075
- $bundled_product_qty = 0;
1076
- }
1077
- }
1078
- if ( 0 === $bundled_product_qty ) {
1079
- continue;
1080
- }
1081
-
1082
- $bundled_item_price = $bundled_item->product->get_price() * $bundled_product_qty;
1083
-
1084
- $bundled_items_price += (double) $bundled_item_price;
1085
-
1086
- } // End foreach().
1087
- $price = wc_price( (double) $bundle_price + $bundled_items_price );
1088
- $price = apply_filters( 'woocommerce_get_price_html', $price, $product );
1089
- } // End if().
1090
- } // End if().
1091
-
1092
- return $price;
1093
- }
1094
-
1095
- add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_product_bundles', 10, 3 );
1096
- } // End if().
1097
-
1098
- if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_mix_and_match_products' ) ) {
1099
-
1100
- /**
1101
- * Set descrition for meta WooCommerce Mix and Match
1102
- *
1103
- * @param array $meta Meta array.
1104
- * @param integer $product_id Product ID.
1105
- *
1106
- * @return array
1107
- */
1108
- function tinv_wishlist_metasupport_woocommerce_mix_and_match_products( $meta, $product_id ) {
1109
- if ( array_key_exists( 'mnm_quantity', $meta ) ) {
1110
- $product = wc_get_product( $product_id );
1111
- if ( is_object( $product ) && $product->is_type( 'mix-and-match' ) ) {
1112
- $meta = array();
1113
- }
1114
- }
1115
-
1116
- return $meta;
1117
- }
1118
-
1119
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_mix_and_match_products', 10, 2 );
1120
- } // End if().
1121
-
1122
- if ( ! function_exists( 'tinvwl_row_woocommerce_mix_and_match_products' ) ) {
1123
-
1124
- /**
1125
- * Add rows for sub product for WooCommerce Mix and Match
1126
- *
1127
- * @param array $wl_product Wishlist Product.
1128
- * @param \WC_Product $product Woocommerce Product.
1129
- */
1130
- function tinvwl_row_woocommerce_mix_and_match_products( $wl_product, $product ) {
1131
- if ( is_object( $product ) && $product->is_type( 'mix-and-match' ) && array_key_exists( 'mnm_quantity', $wl_product['meta'] ) ) {
1132
- $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
1133
- $mnm_items = $product->get_children();
1134
- if ( ! empty( $mnm_items ) ) {
1135
- foreach ( $mnm_items as $id => $mnm_item ) {
1136
- $item_quantity = 0;
1137
- if ( array_key_exists( $id, $wl_product['meta']['mnm_quantity'] ) ) {
1138
- $item_quantity = absint( $wl_product['meta']['mnm_quantity'][ $id ] );
1139
- }
1140
- if ( 0 >= $item_quantity ) {
1141
- continue;
1142
- }
1143
-
1144
- $product_url = $mnm_item->get_permalink();
1145
- $product_image = $mnm_item->get_image();
1146
- $product_title = $mnm_item->get_title();
1147
- $product_price = $mnm_item->get_price_html();
1148
- if ( $mnm_item->is_visible() ) {
1149
- $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
1150
- $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
1151
- }
1152
- $product_title .= tinv_wishlist_get_item_data( $mnm_item, $wl_product );
1153
-
1154
- $availability = (array) $mnm_item->get_availability();
1155
- if ( ! array_key_exists( 'availability', $availability ) ) {
1156
- $availability['availability'] = '';
1157
- }
1158
- if ( ! array_key_exists( 'class', $availability ) ) {
1159
- $availability['class'] = '';
1160
- }
1161
- $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1162
- $row_string = '<tr>';
1163
- $row_string .= '<td colspan="2">&nbsp;</td><td class="product-thumbnail">%1$s</td><td class="product-name">%2$s</td>';
1164
- if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
1165
- $row_string .= '<td class="product-price">%3$s &times; %5$s</td>';
1166
- }
1167
- if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
1168
- $row_string .= '<td class="product-date">&nbsp;</td>';
1169
- }
1170
- if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
1171
- $row_string .= '<td class="product-stock">%4$s</td>';
1172
- }
1173
- if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
1174
- $row_string .= '<td class="product-action">&nbsp;</td>';
1175
- }
1176
- $row_string .= '</tr>';
1177
-
1178
- echo sprintf( $row_string, $product_image, $product_title, $product_price, $availability_html, $item_quantity * $product_quantity ); // WPCS: xss ok.
1179
- } // End foreach().
1180
- } // End if().
1181
- } // End if().
1182
- }
1183
-
1184
- add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_mix_and_match_products', 10, 2 );
1185
- } // End if().
1186
-
1187
- if ( ! function_exists( 'tinvwl_item_price_woocommerce_mix_and_match_products' ) ) {
1188
-
1189
- /**
1190
- * Modify price for WooCommerce Mix and Match
1191
- *
1192
- * @param string $price Returned price.
1193
- * @param array $wl_product Wishlist Product.
1194
- * @param \WC_Product $product Woocommerce Product.
1195
- *
1196
- * @return string
1197
- */
1198
- function tinvwl_item_price_woocommerce_mix_and_match_products( $price, $wl_product, $product ) {
1199
- if ( is_object( $product ) && $product->is_type( 'mix-and-match' ) && $product->is_priced_per_product() ) {
1200
- $mnm_items = $product->get_children();
1201
- if ( ! empty( $mnm_items ) ) {
1202
- $_price = 0;
1203
- foreach ( $mnm_items as $id => $mnm_item ) {
1204
- $item_quantity = 0;
1205
- if ( array_key_exists( $id, $wl_product['meta']['mnm_quantity'] ) ) {
1206
- $item_quantity = absint( $wl_product['meta']['mnm_quantity'][ $id ] );
1207
- }
1208
- if ( 0 >= $item_quantity ) {
1209
- continue;
1210
- }
1211
- $_price += wc_get_price_to_display( $mnm_item, array( 'qty' => $item_quantity ) );
1212
- }
1213
- if ( 0 < $_price ) {
1214
- if ( $product->is_on_sale() ) {
1215
- $price = wc_format_sale_price( $_price + wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ), $_price + wc_get_price_to_display( $product ) ) . $product->get_price_suffix();
1216
- } else {
1217
- $price = wc_price( $_price + wc_get_price_to_display( $product ) ) . $product->get_price_suffix();
1218
- }
1219
- $price = apply_filters( 'woocommerce_get_price_html', $price, $product );
1220
- }
1221
- }
1222
- }
1223
-
1224
- return $price;
1225
- }
1226
-
1227
- add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_mix_and_match_products', 10, 3 );
1228
- } // End if().
1229
-
1230
- if ( ! function_exists( 'tinvwl_add_form_woocommerce_mix_and_match_products' ) ) {
1231
-
1232
- /**
1233
- * Remove empty meta for WooCommerce Mix and Match
1234
- *
1235
- * @param array $form Post form data.
1236
- *
1237
- * @return array
1238
- */
1239
- function tinvwl_add_form_woocommerce_mix_and_match_products( $form = array() ) {
1240
- if ( array_key_exists( 'mnm_quantity', $form ) ) {
1241
- if ( is_array( $form['mnm_quantity'] ) && ! empty( $form['mnm_quantity'] ) ) {
1242
- foreach ( $form['mnm_quantity'] as $key => $value ) {
1243
- $value = absint( $value );
1244
- if ( empty( $value ) ) {
1245
- unset( $form['mnm_quantity'][ $key ] );
1246
- }
1247
- }
1248
- if ( empty( $form['mnm_quantity'] ) ) {
1249
- unset( $form['mnm_quantity'] );
1250
- }
1251
- }
1252
- }
1253
-
1254
- return $form;
1255
- }
1256
-
1257
- add_filter( 'tinvwl_addtowishlist_add_form', 'tinvwl_add_form_woocommerce_mix_and_match_products' );
1258
- } // End if().
1259
-
1260
- if ( ! function_exists( 'tinv_wishlist_metasupport_yith_woocommerce_product_bundles' ) ) {
1261
-
1262
- /**
1263
- * Set descrition for meta WooCommerce Mix and Match
1264
- *
1265
- * @param array $meta Meta array.
1266
- * @param integer $product_id Product ID.
1267
- *
1268
- * @return array
1269
- */
1270
- function tinv_wishlist_metasupport_yith_woocommerce_product_bundles( $meta, $product_id ) {
1271
- if ( array_key_exists( 'yith_bundle_quantity_1', $meta ) ) {
1272
- $product = wc_get_product( $product_id );
1273
- if ( is_object( $product ) && $product->is_type( 'yith_bundle' ) ) {
1274
- $meta = array();
1275
- }
1276
- }
1277
-
1278
- return $meta;
1279
- }
1280
-
1281
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_yith_woocommerce_product_bundles', 10, 2 );
1282
- } // End if().
1283
-
1284
- if ( ! function_exists( 'tinvwl_item_status_yith_woocommerce_product_bundles' ) ) {
1285
-
1286
- /**
1287
- * Modify status for YITH WooCommerce Product Bundles
1288
- *
1289
- * @param string $availability_html Returned availability status.
1290
- * @param string $availability Availability status.
1291
- * @param array $wl_product Wishlist Product.
1292
- * @param \WC_Product $product Woocommerce Product.
1293
- *
1294
- * @return string
1295
- */
1296
- function tinvwl_item_status_yith_woocommerce_product_bundles( $availability_html, $availability, $wl_product, $product ) {
1297
- if ( empty( $availability ) && is_object( $product ) && $product->is_type( 'yith_bundle' ) ) {
1298
- $response = true;
1299
- $bundled_items = $product->get_bundled_items();
1300
- foreach ( $bundled_items as $key => $bundled_item ) {
1301
- if ( method_exists( $bundled_item, 'is_optional' ) ) {
1302
- if ( $bundled_item->is_optional() && ! array_key_exists( 'yith_bundle_optional_' . $key, $wl_product['meta'] ) ) {
1303
- continue;
1304
- }
1305
- }
1306
- if ( ! $bundled_item->get_product()->is_in_stock() ) {
1307
- $response = false;
1308
- }
1309
- }
1310
-
1311
- if ( ! $response ) {
1312
- $availability = array(
1313
- 'class' => 'out-of-stock',
1314
- 'availability' => __( 'Out of stock', 'woocommerce' ),
1315
- );
1316
- $availability_html = '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1317
- }
1318
- }
1319
-
1320
- return $availability_html;
1321
- }
1322
-
1323
- add_filter( 'tinvwl_wishlist_item_status', 'tinvwl_item_status_yith_woocommerce_product_bundles', 10, 4 );
1324
- } // End if().
1325
-
1326
- if ( ! function_exists( 'tinvwl_row_yith_woocommerce_product_bundles' ) ) {
1327
-
1328
- /**
1329
- * Add rows for sub product for YITH WooCommerce Product Bundles
1330
- *
1331
- * @param array $wl_product Wishlist Product.
1332
- * @param \WC_Product $product Woocommerce Product.
1333
- */
1334
- function tinvwl_row_yith_woocommerce_product_bundles( $wl_product, $product ) {
1335
- if ( is_object( $product ) && $product->is_type( 'yith_bundle' ) ) {
1336
- $bundled_items = $product->get_bundled_items();
1337
- $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
1338
- if ( ! empty( $bundled_items ) ) {
1339
- foreach ( $bundled_items as $key => $bundled_item ) {
1340
- $item_quantity = $bundled_item->get_quantity();
1341
- if ( array_key_exists( 'yith_bundle_quantity_' . $key, $wl_product['meta'] ) ) {
1342
- $item_quantity = absint( $wl_product['meta'][ 'yith_bundle_quantity_' . $key ] );
1343
- }
1344
- if ( method_exists( $bundled_item, 'is_optional' ) ) {
1345
- if ( $bundled_item->is_optional() && ! array_key_exists( 'yith_bundle_optional_' . $key, $wl_product['meta'] ) ) {
1346
- $item_quantity = 0;
1347
- }
1348
- }
1349
- if ( 0 >= $item_quantity ) {
1350
- continue;
1351
- }
1352
-
1353
- $product = $bundled_item->get_product();
1354
- if ( ! is_object( $product ) ) {
1355
- continue;
1356
- }
1357
-
1358
- $product_url = $product->get_permalink();
1359
- $product_image = $product->get_image();
1360
- $product_title = $product->get_title();
1361
- $product_price = $product->get_price_html();
1362
- if ( $product->is_visible() ) {
1363
- $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
1364
- $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
1365
- }
1366
- $product_title .= tinv_wishlist_get_item_data( $product, $wl_product );
1367
-
1368
- $availability = (array) $product->get_availability();
1369
- if ( ! array_key_exists( 'availability', $availability ) ) {
1370
- $availability['availability'] = '';
1371
- }
1372
- if ( ! array_key_exists( 'class', $availability ) ) {
1373
- $availability['class'] = '';
1374
- }
1375
- $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1376
- $row_string = '<tr>';
1377
- $row_string .= '<td colspan="2">&nbsp;</td><td class="product-thumbnail">%1$s</td><td class="product-name">%2$s</td>';
1378
- if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
1379
- $row_string .= '<td class="product-price">%3$s &times; %5$s</td>';
1380
- }
1381
- if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
1382
- $row_string .= '<td class="product-date">&nbsp;</td>';
1383
- }
1384
- if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
1385
- $row_string .= '<td class="product-stock">%4$s</td>';
1386
- }
1387
- if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
1388
- $row_string .= '<td class="product-action">&nbsp;</td>';
1389
- }
1390
- $row_string .= '</tr>';
1391
-
1392
- echo sprintf( $row_string, $product_image, $product_title, $product_price, $availability_html, $item_quantity * $product_quantity ); // WPCS: xss ok.
1393
- } // End foreach().
1394
- } // End if().
1395
- } // End if().
1396
- }
1397
-
1398
- add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_yith_woocommerce_product_bundles', 10, 2 );
1399
- } // End if().
1400
-
1401
- if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_add_on' ) ) {
1402
-
1403
- /**
1404
- * Set descrition for meta WooCommerce Product Add-on
1405
- *
1406
- * @param array $meta Meta array.
1407
- * @param integer $product_id Product ID.
1408
- *
1409
- * @return array
1410
- */
1411
- function tinv_wishlist_metasupport_woocommerce_product_add_on( $meta, $product_id ) {
1412
- $personalized_meta = absint( get_post_meta( $product_id, '_product_meta_id', true ) );
1413
- if ( ! empty( $personalized_meta ) ) {
1414
- $meta = array();
1415
- }
1416
-
1417
- return $meta;
1418
- }
1419
-
1420
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_product_add_on', 10, 2 );
1421
- } // End if().
1422
-
1423
- if ( ! function_exists( 'tinv_wishlist_item_meta_woocommerce_product_add_on' ) ) {
1424
-
1425
- /**
1426
- * Set descrition for meta WooCommerce Product Add-on
1427
- *
1428
- * @param array $meta Meta array.
1429
- * @param array $wl_product Wishlist Product.
1430
- * @param \WC_Product $product Woocommerce Product.
1431
- *
1432
- * @return array
1433
- */
1434
- function tinv_wishlist_item_meta_woocommerce_product_add_on( $meta, $wl_product, $product ) {
1435
- $personalized_meta = absint( get_post_meta( $wl_product['product_id'], '_product_meta_id', true ) );
1436
- if ( ! empty( $personalized_meta ) && class_exists( 'NM_PersonalizedProduct' ) ) {
1437
- $_meta = $wl_product['meta'];
1438
- $single_meta = NM_PersonalizedProduct::get_instance()->get_product_meta( $personalized_meta );
1439
- $product_meta = json_decode( $single_meta->the_meta );
1440
- $product_meta_data = array();
1441
- $item_meta = array();
1442
-
1443
- if ( $product_meta ) {
1444
- foreach ( $product_meta as $__meta ) {
1445
- if ( ! isset( $__meta->data_name ) ) {
1446
- continue;
1447
- }
1448
-
1449
- $element_name = strtolower( preg_replace( '![^a-z0-9]+!i', '_', $__meta->data_name ) );
1450
- $element_value = '';
1451
- $thefiles_key = 'thefile_' . $element_name;
1452
- if ( ! isset( $_meta[ $element_name ] ) && ! isset( $_meta[ $thefiles_key ] ) ) {
1453
- continue;
1454
- }
1455
-
1456
- switch ( $__meta->type ) {
1457
- case 'checkbox':
1458
- if ( array_key_exists( $element_name, $_meta ) ) {
1459
- $element_value = implode( ',', array_map( 'sanitize_text_field', wp_unslash( $_meta[ $element_name ] ) ) );
1460
- }
1461
- break;
1462
- case 'select':
1463
- case 'radio':
1464
- $element_value = sanitize_text_field( $_meta[ $element_name ] );
1465
- break;
1466
- case 'file':
1467
- case 'facebook':
1468
- break;
1469
- case 'image':
1470
- $element_value = isset( $_meta[ $element_name ] ) ? sanitize_text_field( $_meta[ $element_name ] ) : '';
1471
- case 'section':
1472
- if ( ! is_array( $element_value ) ) {
1473
- $post_element_name = '';
1474
- if ( isset( $_meta[ $element_name ] ) && is_array( $_meta[ $element_name ] ) ) {
1475
- $post_element_name = array_map( 'sanitize_text_field', wp_unslash( $_meta[ $element_name ] ) );
1476
- $nele = array();
1477
- foreach ( $post_element_name as $ele ) {
1478
- $ele = stripslashes( nl2br( $ele ) );
1479
- $nele[] = $ele;
1480
- }
1481
- $post_element_name = $nele;
1482
- } else {
1483
- $post_element_name = sanitize_text_field( $_meta[ $element_name ] );
1484
- }
1485
- if ( $post_element_name != '' ) { // @codingStandardsIgnoreLine WordPress.PHP.YodaConditions.NotYoda
1486
- $element_value = $post_element_name;
1487
- }
1488
- }
1489
- break;
1490
- default:
1491
- $element_value = sanitize_text_field( $_meta[ $element_name ] );
1492
- } // End switch().
1493
- if ( ! empty( $element_value ) ) {
1494
- switch ( $__meta->type ) {
1495
- case 'image':
1496
- // If selected designs are more then one.
1497
- if ( is_array( $element_value ) ) {
1498
-
1499
- $_v = '';
1500
- foreach ( $element_value as $selected ) {
1501
- $selecte_image_meta = json_decode( stripslashes( $selected ) );
1502
- $_v .= $selecte_image_meta->title . ',';
1503
- }
1504
- $item_meta[] = array(
1505
- 'key' => $__meta->title,
1506
- 'display' => __( 'Photos imported - ', 'nm-personalizedproduct' ) . count( $element_value ),
1507
- );
1508
- } else {
1509
- $selecte_image_meta = json_decode( stripslashes( $element_value ) );
1510
- $item_meta[] = array(
1511
- 'key' => $__meta->title,
1512
- 'display' => $selecte_image_meta->title,
1513
- );
1514
- }
1515
- break;
1516
- default:
1517
- if ( is_array( $element_value ) ) {
1518
- list( $filekey, $filename ) = each( $element_value );
1519
- if ( NM_PersonalizedProduct::get_instance()->is_image( $filename ) ) {
1520
- $item_meta[] = array(
1521
- 'key' => $__meta->title,
1522
- 'display' => NM_PersonalizedProduct::get_instance()->make_filename_link( $element_value ),
1523
- );
1524
- } else {
1525
- $item_meta[] = array(
1526
- 'key' => $__meta->title,
1527
- 'display' => implode( ',', $element_value ),
1528
- );
1529
- }
1530
- } else {
1531
- $item_meta[] = array(
1532
- 'key' => $__meta->title,
1533
- 'display' => stripslashes( $element_value ),
1534
- );
1535
- }
1536
- break;
1537
- } // End switch().
1538
- } // End if().
1539
- } // End foreach().
1540
- } // End if().
1541
-
1542
- if ( 0 < count( $item_meta ) ) {
1543
- ob_start();
1544
- tinv_wishlist_template( 'ti-wishlist-item-data.php', array( 'item_data' => $item_meta ) );
1545
- $meta .= '<br/>' . ob_get_clean();
1546
- }
1547
- } // End if().
1548
-
1549
- return $meta;
1550
- }
1551
-
1552
- add_filter( 'tinvwl_wishlist_item_meta_data', 'tinv_wishlist_item_meta_woocommerce_product_add_on', 10, 3 );
1553
- } // End if().
1554
-
1555
- if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_tm_extra_product_options' ) ) {
1556
-
1557
- /**
1558
- * Set descrition for meta WooCommerce TM Extra Product Options
1559
- *
1560
- * @param array $meta Meta array.
1561
- * @param integer $product_id Product ID.
1562
- * @param integer $variation_id Product variation ID.
1563
- *
1564
- * @return array
1565
- */
1566
- function tinv_wishlist_metasupport_woocommerce_tm_extra_product_options( $meta, $product_id, $variation_id ) {
1567
- if ( array_key_exists( 'tcaddtocart', $meta ) && function_exists( 'TM_EPO_API' ) && function_exists( 'TM_EPO' ) ) {
1568
- $has_epo = TM_EPO_API()->has_options( $product_id );
1569
- if ( TM_EPO_API()->is_valid_options( $has_epo ) ) {
1570
- $post_data = array();
1571
- foreach ( $meta as $key => $value ) {
1572
- $post_data[ $key ] = $value['display'];
1573
- }
1574
- $cart_item = TM_EPO()->add_cart_item_data_helper( array(), $product_id, $post_data );
1575
-
1576
- if ( 'normal' == TM_EPO()->tm_epo_hide_options_in_cart && 'advanced' != TM_EPO()->tm_epo_cart_field_display && ! empty( $cart_item['tmcartepo'] ) ) {
1577
- $cart_item['quantity'] = 1;
1578
- $cart_item['data'] = wc_get_product( $variation_id ? $variation_id : $product_id );
1579
- $cart_item['tm_cart_item_key'] = '';
1580
- $item_data = TM_EPO()->get_item_data_array( array(), $cart_item );
1581
-
1582
- foreach ( $item_data as $key => $data ) {
1583
- // Set hidden to true to not display meta on cart.
1584
- if ( ! empty( $data['hidden'] ) ) {
1585
- unset( $item_data[ $key ] );
1586
- continue;
1587
- }
1588
- $item_data[ $key ]['key'] = ! empty( $data['key'] ) ? $data['key'] : $data['name'];
1589
- $item_data[ $key ]['display'] = ! empty( $data['display'] ) ? $data['display'] : $data['value'];
1590
- }
1591
-
1592
- return $item_data;
1593
- }
1594
- }
1595
- return array();
1596
- }
1597
-
1598
- return $meta;
1599
- }
1600
-
1601
- add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_tm_extra_product_options', 10, 3 );
1602
- } // End if().
1603
-
1604
- if ( ! function_exists( 'tinvwl_item_price_woocommerce_tm_extra_product_options' ) ) {
1605
-
1606
- /**
1607
- * Modify price for WooCommerce TM Extra Product Options
1608
- *
1609
- * @param string $price Returned price.
1610
- * @param array $wl_product Wishlist Product.
1611
- * @param \WC_Product $product Woocommerce Product.
1612
- *
1613
- * @return string
1614
- */
1615
- function tinvwl_item_price_woocommerce_tm_extra_product_options( $price, $wl_product, $product ) {
1616
- if ( array_key_exists( 'tcaddtocart', (array) @$wl_product['meta'] ) && function_exists( 'TM_EPO_API' ) && function_exists( 'TM_EPO' ) && TM_EPO()->tm_epo_hide_options_in_cart == 'normal' ) {
1617
- $product_id = $wl_product['product_id'];
1618
- $has_epo = TM_EPO_API()->has_options( $product_id );
1619
- if ( TM_EPO_API()->is_valid_options( $has_epo ) ) {
1620
- $cart_item = TM_EPO()->add_cart_item_data_helper( array(), $product_id, $wl_product['meta'] );
1621
- $cart_item['quantity'] = 1;
1622
- $cart_item['data'] = $product;
1623
-
1624
- $product_price = apply_filters( 'wc_epo_add_cart_item_original_price', $cart_item['data']->get_price(), $cart_item );
1625
- if ( ! empty( $cart_item['tmcartepo'] ) ) {
1626
- $to_currency = tc_get_woocommerce_currency();
1627
- foreach ( $cart_item['tmcartepo'] as $value ) {
1628
- if ( array_key_exists( $to_currency, $value['price_per_currency'] ) ) {
1629
- $value = floatval( $value['price_per_currency'][ $to_currency ] );
1630
- $product_price += $value;
1631
- }
1632
- }
1633
- }
1634
-
1635
- $price = apply_filters( 'wc_tm_epo_ac_product_price', apply_filters( 'woocommerce_cart_item_price', TM_EPO()->get_price_for_cart( $product_price, $cart_item, '' ), $cart_item, '' ), '', $cart_item, $product, $product_id );
1636
- }
1637
- }
1638
- return $price;
1639
- }
1640
-
1641
- add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_tm_extra_product_options', 10, 3 );
1642
- } // End if().
1643
-
1644
- if ( ! function_exists( 'TII18n' ) ) {
1645
-
1646
- /**
1647
- * Return TI Yoasti 18n module class
1648
- *
1649
- * @return \TInvWL_Includes_API_Yoasti18n
1650
- */
1651
- function TII18n() { // @codingStandardsIgnoreLine WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
1652
- return TInvWL_Includes_API_Yoasti18n::instance();
1653
- }
1654
- }
1655
-
1656
- // Create a helper function for easy SDK access.
1657
- if ( ! function_exists( 'tinvwl_fs' ) ) {
1658
-
1659
- /**
1660
- * Freemius
1661
- *
1662
- * @return array
1663
- */
1664
- function tinvwl_fs() {
1665
- global $tinvwl_fs;
1666
-
1667
- if ( ! isset( $tinvwl_fs ) ) {
1668
- // Include Freemius SDK.
1669
- require_once dirname( __FILE__ ) . '/freemius/start.php';
1670
-
1671
- $tinvwl_fs = fs_dynamic_init( array(
1672
- 'id' => '839',
1673
- 'slug' => 'ti-woocommerce-wishlist',
1674
- 'type' => 'plugin',
1675
- 'public_key' => 'pk_1944d351ab27040c8f65c72d1e7e7',
1676
- 'is_premium' => false,
1677
- 'has_premium_version' => false,
1678
- 'has_addons' => false,
1679
- 'has_paid_plans' => false,
1680
- 'menu' => array(
1681
- 'slug' => 'tinvwl',
1682
- 'first-path' => 'admin.php?page=tinvwl' . ( get_option( TINVWL_PREFIX . '_wizard' ) ? '' : '-wizard' ),
1683
- 'account' => false,
1684
- 'support' => false,
1685
- ),
1686
- ) );
1687
- }
1688
-
1689
- return $tinvwl_fs;
1690
- }
1691
-
1692
- // Init Freemius.
1693
- tinvwl_fs();
1694
-
1695
- if ( ! function_exists( 'tinvwl_fs_custom_connect_message_on_update' ) ) {
1696
- function tinvwl_fs_custom_connect_message_on_update(
1697
- $message, $user_first_name, $plugin_title, $user_login, $site_link,
1698
- $freemius_link
1699
- ) {
1700
- return sprintf(
1701
- __fs( 'hey-x' ) . '<br>' .
1702
- __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'ti-woocommerce-wishlist' ), $user_first_name, '<b>' . $plugin_title . '</b>', '<b>' . $user_login . '</b>', $site_link, $freemius_link
1703
- );
1704
- }
1705
-
1706
- tinvwl_fs()->add_filter( 'connect_message_on_update', 'tinvwl_fs_custom_connect_message_on_update', 10, 6 );
1707
- }
1708
-
1709
- if ( ! function_exists( 'tinvwl_fs_custom_connect_message' ) ) {
1710
- function tinvwl_fs_custom_connect_message(
1711
- $message, $user_first_name, $plugin_title, $user_login, $site_link,
1712
- $freemius_link
1713
- ) {
1714
- return sprintf(
1715
- __fs( 'hey-x' ) . '<br>' .
1716
- __( 'Allow %6$s to collect some usage data with %5$s to make the plugin even more awesome. If you skip this, that\'s okay! %2$s will still work just fine.', 'ti-woocommerce-wishlist' ), $user_first_name, '<b>' . __( 'WooCommerce Wishlist Plugin', 'ti-woocommerce-wishlist' ) . '</b>', '<b>' . $user_login . '</b>', $site_link, $freemius_link, '<b>' . __( 'TemplateInvaders', 'ti-woocommerce-wishlist' ) . '</b>'
1717
- );
1718
- }
1719
-
1720
- tinvwl_fs()->add_filter( 'connect_message', 'tinvwl_fs_custom_connect_message', 10, 6 );
1721
- }
1722
-
1723
- tinvwl_fs()->add_action( 'after_uninstall', 'uninstall_tinv_wishlist' );
1724
- } // End if().
1725
-
1726
- // WP Multilang string translations.
1727
- if ( function_exists( 'wpm_translate_string' ) ) {
1728
-
1729
- add_filter( 'tinvwl-general-default_title', 'wpm_translate_string' );
1730
- add_filter( 'tinvwl-general-text_browse', 'wpm_translate_string' );
1731
- add_filter( 'tinvwl-general-text_added_to', 'wpm_translate_string' );
1732
- add_filter( 'tinvwl-general-text_already_in', 'wpm_translate_string' );
1733
- add_filter( 'tinvwl-general-text_removed_from', 'wpm_translate_string' );
1734
-
1735
- add_filter( 'tinvwl-add_to_wishlist_catalog-text', 'wpm_translate_string' );
1736
- add_filter( 'tinvwl-add_to_wishlist_catalog-text_remove', 'wpm_translate_string' );
1737
-
1738
- add_filter( 'tinvwl-product_table-text_add_to_cart', 'wpm_translate_string' );
1739
-
1740
- add_filter( 'tinvwl-table-text_add_select_to_cart', 'wpm_translate_string' );
1741
- add_filter( 'tinvwl-table-text_add_all_to_cart', 'wpm_translate_string' );
1742
-
1743
- add_filter( 'tinvwl-social-share_on', 'wpm_translate_string' );
1744
-
1745
- add_filter( 'tinvwl-topline-text', 'wpm_translate_string' );
1746
-
1747
- } // End if().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Support functions for other plugins
4
+ *
5
+ * @since 1.5.0
6
+ * @package TInvWishlist
7
+ */
8
+
9
+ // If this file is called directly, abort.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ die;
12
+ }
13
+
14
+ if ( ! function_exists( 'tinvwl_rocket_reject_uri' ) ) {
15
+
16
+ /**
17
+ * Disable cache for WP Rocket
18
+ *
19
+ * @param array $uri URI.
20
+ *
21
+ * @return array
22
+ */
23
+ function tinvwl_rocket_reject_uri( $uri = array() ) {
24
+ $ids = array(
25
+ tinv_get_option( 'page', 'wishlist' ),
26
+ );
27
+ $pages = $ids;
28
+ $languages = apply_filters( 'wpml_active_languages', array(), array(
29
+ 'skip_missing' => 0,
30
+ 'orderby' => 'code',
31
+ ) );
32
+ if ( ! empty( $languages ) ) {
33
+ foreach ( $ids as $id ) {
34
+ foreach ( $languages as $l ) {
35
+ $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
36
+ }
37
+ }
38
+ $pages = array_unique( $pages );
39
+ }
40
+ $pages = array_filter( $pages );
41
+ if ( ! empty( $pages ) ) {
42
+ foreach ( $pages as $page ) {
43
+ $uri[] = str_replace( get_site_url(), '', get_permalink( $page ) );
44
+ }
45
+ }
46
+
47
+ return $uri;
48
+ }
49
+
50
+ add_filter( 'rocket_cache_reject_uri', 'tinvwl_rocket_reject_uri' );
51
+ } // End if().
52
+
53
+ if ( ! function_exists( 'tinvwl_rocket_reject_cookies' ) ) {
54
+
55
+ /**
56
+ * Disable cache for WP Rocket
57
+ *
58
+ * @param array $cookies Cookies.
59
+ *
60
+ * @return array
61
+ */
62
+ function tinvwl_rocket_reject_cookies( $cookies = array() ) {
63
+ $cookies[] = 'tinv_wishlist';
64
+
65
+ return $cookies;
66
+ }
67
+
68
+ add_filter( 'rocket_cache_reject_cookies', 'tinvwl_rocket_reject_cookies' );
69
+ }
70
+
71
+ if ( ! function_exists( 'tinvwl_supercache_reject_uri' ) ) {
72
+
73
+ /**
74
+ * Disable cache for WP Super Cache
75
+ *
76
+ * @global array $cache_rejected_uri
77
+ *
78
+ * @param string $buffer Intercepted the output of the page.
79
+ *
80
+ * @return string
81
+ */
82
+ function tinvwl_supercache_reject_uri( $buffer ) {
83
+ global $cache_rejected_uri;
84
+ if ( ! is_null( $cache_rejected_uri ) && is_array( $cache_rejected_uri ) ) {
85
+ $ids = array(
86
+ tinv_get_option( 'page', 'wishlist' ),
87
+ );
88
+ $pages = $ids;
89
+ $languages = apply_filters( 'wpml_active_languages', array(), array(
90
+ 'skip_missing' => 0,
91
+ 'orderby' => 'code',
92
+ ) );
93
+ if ( ! empty( $languages ) ) {
94
+ foreach ( $ids as $id ) {
95
+ foreach ( $languages as $l ) {
96
+ $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
97
+ }
98
+ }
99
+ $pages = array_unique( $pages );
100
+ }
101
+ $pages = array_filter( $pages );
102
+ if ( ! empty( $pages ) ) {
103
+ foreach ( $pages as $page ) {
104
+ $cache_rejected_uri[] = str_replace( get_site_url(), '', get_permalink( $page ) );
105
+ }
106
+ }
107
+ }
108
+
109
+ return $buffer;
110
+ }
111
+
112
+ add_filter( 'wp_cache_ob_callback_filter', 'tinvwl_supercache_reject_uri' );
113
+ } // End if().
114
+
115
+ if ( ! function_exists( 'tinvwl_w3total_reject_uri' ) ) {
116
+
117
+ /**
118
+ * Disable cache for W3 Total Cache
119
+ */
120
+ function tinvwl_w3total_reject_uri() {
121
+ if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
122
+ return;
123
+ }
124
+ $ids = array(
125
+ tinv_get_option( 'page', 'wishlist' ),
126
+ );
127
+ $pages = $ids;
128
+ $languages = apply_filters( 'wpml_active_languages', array(), array(
129
+ 'skip_missing' => 0,
130
+ 'orderby' => 'code',
131
+ ) );
132
+ if ( ! empty( $languages ) ) {
133
+ foreach ( $ids as $id ) {
134
+ foreach ( $languages as $l ) {
135
+ $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
136
+ }
137
+ }
138
+ $pages = array_unique( $pages );
139
+ }
140
+ $pages = array_filter( $pages );
141
+ if ( ! empty( $pages ) ) {
142
+ foreach ( $pages as $i => $page ) {
143
+ $pages[ $i ] = preg_replace( "/^\//", '', str_replace( get_site_url(), '', get_permalink( $page ) ) ); // @codingStandardsIgnoreLine Squiz.Strings.DoubleQuoteUsage.NotRequired
144
+ }
145
+ }
146
+ $pages = array_unique( $pages );
147
+ $pages = array_filter( $pages );
148
+
149
+ $config = w3_instance( 'W3_Config' );
150
+ if ( ! empty( $pages ) ) {
151
+ $sections = array( 'dbcache.reject.uri', 'pgcache.reject.uri' );
152
+ foreach ( $sections as $section ) {
153
+ $settings = array_map( 'trim', $config->get_array( $section ) );
154
+ $changed = false;
155
+ foreach ( $pages as $page ) {
156
+ if ( ! in_array( $page, $settings ) ) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
157
+ $settings[] = $page;
158
+ $changed = true;
159
+ }
160
+ }
161
+ if ( $changed ) {
162
+ $config->set( $section, $settings );
163
+ $config->save();
164
+ }
165
+ }
166
+ }
167
+
168
+ $settings = array_map( 'trim', $config->get_array( 'pgcache.reject.cookie' ) );
169
+ if ( ! in_array( 'tinv_wishlist', $settings ) ) { // @codingStandardsIgnoreLine WordPress.PHP.StrictInArray.MissingTrueStrict
170
+ $settings[] = 'tinv_wishlist';
171
+ $config->set( 'pgcache.reject.cookie', $settings );
172
+ $config->save();
173
+ }
174
+ }
175
+
176
+ add_action( 'admin_init', 'tinvwl_w3total_reject_uri' );
177
+ } // End if().
178
+
179
+ if ( ! function_exists( 'tinvwl_wp_fastest_cache_reject' ) ) {
180
+
181
+ /**
182
+ * Disable cache for WP Fastest Cache
183
+ */
184
+ function tinvwl_wp_fastest_cache_reject() {
185
+ if ( defined( 'WPFC_WP_PLUGIN_DIR' ) ) {
186
+ if ( $rules_json = get_option( 'WpFastestCacheExclude' ) ) {
187
+ if ( 'null' !== $rules_json ) {
188
+ $ids = array(
189
+ tinv_get_option( 'page', 'wishlist' ),
190
+ tinv_get_option( 'page', 'manage' ),
191
+ );
192
+ $pages = $ids;
193
+ $languages = apply_filters( 'wpml_active_languages', array(), array(
194
+ 'skip_missing' => 0,
195
+ 'orderby' => 'code',
196
+ ) );
197
+ if ( ! empty( $languages ) ) {
198
+ foreach ( $ids as $id ) {
199
+ foreach ( $languages as $l ) {
200
+ $pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
201
+ }
202
+ }
203
+ $pages = array_unique( $pages );
204
+ }
205
+ $pages = array_filter( $pages );
206
+ if ( ! empty( $pages ) ) {
207
+ foreach ( $pages as $i => $page ) {
208
+ $pages[ $i ] = preg_replace( "/^\//", '', str_replace( get_site_url(), '', get_permalink( $page ) ) ); // @codingStandardsIgnoreLine Squiz.Strings.DoubleQuoteUsage.NotRequired
209
+ }
210
+ }
211
+ $pages = array_unique( $pages );
212
+ $pages = array_filter( $pages );
213
+
214
+ $rules_std = json_decode( $rules_json, true );
215
+ $ex_pages = array();
216
+ foreach ( $rules_std as $key => $value ) {
217
+ $value['type'] = isset( $value['type'] ) ? $value['type'] : 'page';
218
+ if ( 'page' === $value['type'] ) {
219
+ $ex_pages[] = $value['content'];
220
+ }
221
+ }
222
+ $ex_pages = array_unique( $ex_pages );
223
+ $ex_pages = array_filter( $ex_pages );
224
+ $changed = false;
225
+
226
+ foreach ( $pages as $page ) {
227
+ $page = preg_replace( '/\/$/', '', $page );
228
+
229
+ if ( ! in_array( $page, $ex_pages ) ) {
230
+ $changed = true;
231
+ $rules_std[] = array(
232
+ 'prefix' => 'startwith',
233
+ 'content' => $page,
234
+ 'type' => 'page',
235
+ );
236
+ }
237
+ }
238
+ if ( $changed ) {
239
+ $data = json_encode( $rules_std );
240
+ update_option( 'WpFastestCacheExclude', $data );
241
+ }
242
+ } // End if().
243
+ } // End if().
244
+ } // End if().
245
+ }
246
+
247
+ add_action( 'admin_init', 'tinvwl_wp_fastest_cache_reject' );
248
+ } // End if().
249
+
250
+ if ( function_exists( 'tinvwl_comet_cache_reject' ) ) {
251
+
252
+ /**
253
+ * Set define disabled for Comet Cache
254
+ *
255
+ * @param mixed $data Any content.
256
+ *
257
+ * @return mixed
258
+ */
259
+ function tinvwl_comet_cache_reject( $data = '' ) {
260
+ define( 'COMET_CACHE_ALLOWED', false );
261
+
262
+ return $data;
263
+ }
264
+
265
+ add_filter( 'tinvwl_addtowishlist_return_ajax', 'tinvwl_comet_cache_reject' );
266
+ add_action( 'tinvwl_before_action_owner', 'tinvwl_comet_cache_reject' );
267
+ add_action( 'tinvwl_before_action_user', 'tinvwl_comet_cache_reject' );
268
+ add_action( 'tinvwl_addproduct_tocart', 'tinvwl_comet_cache_reject' );
269
+ add_action( 'tinv_wishlist_addtowishlist_button', 'tinvwl_comet_cache_reject' );
270
+ add_action( 'tinv_wishlist_addtowishlist_dialogbox', 'tinvwl_comet_cache_reject' );
271
+ }
272
+
273
+ if ( ! function_exists( 'gf_productaddon_support' ) ) {
274
+
275
+ /**
276
+ * Add supports WooCommerce - Gravity Forms Product Add-Ons
277
+ */
278
+ function gf_productaddon_support() {
279
+ if ( ! class_exists( 'woocommerce_gravityforms' ) ) {
280
+ return false;
281
+ }
282
+ if ( ! function_exists( 'gf_productaddon_text_button' ) ) {
283
+
284
+ /**
285
+ * Change text for button add to cart
286
+ *
287
+ * @param string $text_add_to_cart Text "Add to cart".
288
+ * @param array $wl_product Wishlist product.
289
+ * @param object $product WooCommerce Product.
290
+ *
291
+ * @return string
292
+ */
293
+ function gf_productaddon_text_button( $text_add_to_cart, $wl_product, $product ) {
294
+ $gravity_form_data = get_post_meta( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ), '_gravity_form_data', true );
295
+
296
+ return ( $gravity_form_data ) ? __( 'Select options', 'woocommerce' ) : $text_add_to_cart;
297
+ }
298
+
299
+ add_filter( 'tinvwl_wishlist_item_add_to_cart', 'gf_productaddon_text_button', 10, 3 );
300
+ }
301
+
302
+ if ( ! function_exists( 'gf_productaddon_run_action_button' ) ) {
303
+
304
+ /**
305
+ * Check for make redirect to url
306
+ *
307
+ * @param boolean $need Need redirect or not.
308
+ * @param object $product WooCommerce Product.
309
+ *
310
+ * @return boolean
311
+ */
312
+ function gf_productaddon_run_action_button( $need, $product ) {
313
+ $gravity_form_data = get_post_meta( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ), '_gravity_form_data', true );
314
+
315
+ return ( $gravity_form_data ) ? true : $need;
316
+ }
317
+
318
+ add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'gf_productaddon_run_action_button', 10, 2 );
319
+ }
320
+
321
+ if ( ! function_exists( 'gf_productaddon_action_button' ) ) {
322
+
323
+ /**
324
+ * Redirect url
325
+ *
326
+ * @param string $url Redirect URL.
327
+ * @param object $product WooCommerce Product.
328
+ *
329
+ * @return string
330
+ */
331
+ function gf_productaddon_action_button( $url, $product ) {
332
+ $gravity_form_data = get_post_meta( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ), '_gravity_form_data', true );
333
+
334
+ return ( $gravity_form_data ) ? $product->get_permalink() : $url;
335
+ }
336
+
337
+ add_filter( 'tinvwl_product_add_to_cart_redirect_url', 'gf_productaddon_action_button', 10, 2 );
338
+ }
339
+ }
340
+
341
+ add_action( 'init', 'gf_productaddon_support' );
342
+ } // End if().
343
+
344
+ if ( ! function_exists( 'tinvwl_wpml_product_get' ) ) {
345
+
346
+ /**
347
+ * Change product data if product need translate
348
+ *
349
+ * @param array $product Wishlistl product.
350
+ *
351
+ * @return array
352
+ */
353
+ function tinvwl_wpml_product_get( $product ) {
354
+ if ( array_key_exists( 'data', $product ) ) {
355
+ $_product_id = $product_id = $product['product_id'];
356
+ $_variation_id = $variation_id = $product['variation_id'];
357
+ $_product_id = apply_filters( 'wpml_object_id', $_product_id, 'product', true );
358
+ if ( ! empty( $_variation_id ) ) {
359
+ $_variation_id = apply_filters( 'wpml_object_id', $_variation_id, 'product', true );
360
+ }
361
+ if ( $_product_id !== $product_id || $_variation_id !== $variation_id ) {
362
+ $product['data'] = wc_get_product( $variation_id ? $_variation_id : $_product_id );
363
+ }
364
+ }
365
+
366
+ return $product;
367
+ }
368
+
369
+ add_filter( 'tinvwl_wishlist_product_get', 'tinvwl_wpml_product_get' );
370
+ }
371
+
372
+ if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare' ) ) {
373
+
374
+ /**
375
+ * Change product data if product need translate in WooCommerce Multilingual
376
+ *
377
+ * @param array $post_data Data for wishlist.
378
+ *
379
+ * @return array
380
+ */
381
+ function tinvwl_wpml_addtowishlist_prepare( $post_data ) {
382
+ if ( class_exists( 'woocommerce_wpml' ) ) {
383
+
384
+ global $woocommerce_wpml, $sitepress, $wpdb;
385
+
386
+ // Reload products class.
387
+ $woocommerce_wpml->products = new WCML_Products( $woocommerce_wpml, $sitepress, $wpdb );
388
+
389
+ if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) ) {
390
+ $post_data['product_id'] = $woocommerce_wpml->products->get_original_product_id( $post_data['product_id'] );
391
+ }
392
+ if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) && array_key_exists( 'product_variation', $post_data ) && ! empty( $post_data['product_variation'] ) ) {
393
+ $original_product_language = $woocommerce_wpml->products->get_original_product_language( $post_data['product_id'] );
394
+ $post_data['product_variation'] = apply_filters( 'translate_object_id', $post_data['product_variation'], 'product_variation', true, $original_product_language );
395
+ }
396
+ }
397
+
398
+ return $post_data;
399
+ }
400
+
401
+ add_filter( 'tinvwl_addtowishlist_prepare', 'tinvwl_wpml_addtowishlist_prepare' );
402
+ }
403
+
404
+ if ( ! function_exists( 'tinvwl_wpml_addtowishlist_out_prepare' ) ) {
405
+
406
+ /**
407
+ * Change product data if product need translate in WooCommerce Multilingual
408
+ *
409
+ * @param array $attr Data for wishlist.
410
+ *
411
+ * @return array
412
+ */
413
+ function tinvwl_wpml_addtowishlist_out_prepare( $attr ) {
414
+ if ( class_exists( 'woocommerce_wpml' ) ) {
415
+
416
+ global $woocommerce_wpml, $sitepress, $wpdb;
417
+
418
+ // Reload products class.
419
+ $woocommerce_wpml->products = new WCML_Products( $woocommerce_wpml, $sitepress, $wpdb );
420
+ if ( array_key_exists( 'product_id', $attr ) && ! empty( $attr['product_id'] ) ) {
421
+ $attr['product_id'] = $woocommerce_wpml->products->get_original_product_id( $attr['product_id'] );
422
+ }
423
+ if ( array_key_exists( 'product_id', $attr ) && ! empty( $attr['product_id'] ) && array_key_exists( 'variation_id', $attr ) && ! empty( $attr['variation_id'] ) ) {
424
+ $original_product_language = $woocommerce_wpml->products->get_original_product_language( $attr['product_id'] );
425
+ $attr['variation_id'] = apply_filters( 'translate_object_id', $attr['variation_id'], 'product_variation', true, $original_product_language );
426
+ }
427
+ }
428
+
429
+ return $attr;
430
+ }
431
+
432
+ add_filter( 'tinvwl_addtowishlist_out_prepare_attr', 'tinvwl_wpml_addtowishlist_out_prepare' );
433
+ }
434
+
435
+ if ( ! function_exists( 'tinvwl_wpml_addtowishlist_out_prepare_product' ) ) {
436
+
437
+ /**
438
+ * Change product if product need translate in WooCommerce Multilingual
439
+ *
440
+ * @param \WC_Product $product WooCommerce Product.
441
+ *
442
+ * @return \WC_Product
443
+ */
444
+ function tinvwl_wpml_addtowishlist_out_prepare_product( $product ) {
445
+ if ( class_exists( 'woocommerce_wpml' ) && is_object( $product ) ) {
446
+
447
+ global $woocommerce_wpml, $sitepress, $wpdb;
448
+
449
+ // Reload products class.
450
+ $woocommerce_wpml->products = new WCML_Products( $woocommerce_wpml, $sitepress, $wpdb );
451
+
452
+ $product_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() );
453
+ $variation_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 );
454
+
455
+ if ( ! empty( $product_id ) ) {
456
+ $product_id = $woocommerce_wpml->products->get_original_product_id( $product_id );
457
+ }
458
+ if ( ! empty( $product_id ) && ! empty( $variation_id ) ) {
459
+ $original_product_language = $woocommerce_wpml->products->get_original_product_language( $product_id );
460
+ $variation_id = apply_filters( 'translate_object_id', $variation_id, 'product_variation', true, $original_product_language );
461
+ }
462
+ if ( ! empty( $product_id ) ) {
463
+ $product = wc_get_product( $variation_id ? $variation_id : $product_id );
464
+ }
465
+ }
466
+
467
+ return $product;
468
+ }
469
+
470
+ add_filter( 'tinvwl_addtowishlist_out_prepare_product', 'tinvwl_wpml_addtowishlist_out_prepare_product' );
471
+ }
472
+
473
+ if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare_form' ) ) {
474
+
475
+ /**
476
+ * Change product form data if product need translate in WooCommerce Multilingual
477
+ *
478
+ * @param array $post_data Data for wishlist.
479
+ *
480
+ * @return array
481
+ */
482
+ function tinvwl_wpml_addtowishlist_prepare_form( $post_data ) {
483
+ if ( class_exists( 'woocommerce_wpml' ) && is_array( $post_data ) ) {
484
+
485
+ global $woocommerce_wpml, $sitepress, $wpdb;
486
+
487
+ // Reload products class.
488
+ $woocommerce_wpml->products = new WCML_Products( $woocommerce_wpml, $sitepress, $wpdb );
489
+
490
+ if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) ) {
491
+ $post_data['product_id'] = $woocommerce_wpml->products->get_original_product_id( $post_data['product_id'] );
492
+ }
493
+ if ( array_key_exists( 'product_id', $post_data ) && ! empty( $post_data['product_id'] ) && array_key_exists( 'variation_id', $post_data ) && ! empty( $post_data['variation_id'] ) ) {
494
+ $original_product_language = $woocommerce_wpml->products->get_original_product_language( $post_data['product_id'] );
495
+ $post_data['variation_id'] = apply_filters( 'translate_object_id', $post_data['variation_id'], 'product_variation', true, $original_product_language );
496
+ }
497
+ }
498
+
499
+ return $post_data;
500
+ }
501
+
502
+ add_filter( 'tinvwl_addtowishlist_prepare_form', 'tinvwl_wpml_addtowishlist_prepare_form' );
503
+ }
504
+
505
+ if ( ! function_exists( 'tinvwl_wpml_filter_link' ) ) {
506
+
507
+ /**
508
+ * Corect add wishlist key for WPML plugin.
509
+ *
510
+ * @param string $full_link Link for page.
511
+ * @param array $l Language.
512
+ *
513
+ * @return string
514
+ */
515
+ function tinvwl_wpml_filter_link( $full_link, $l ) {
516
+ $share_key = get_query_var( 'tinvwlID', null );
517
+ if ( ! empty( $share_key ) ) {
518
+ if ( get_option( 'permalink_structure' ) ) {
519
+ $suffix = '';
520
+ if ( preg_match( '/([^\?]+)\?*?(.*)/i', $full_link, $_full_link ) ) {
521
+ $full_link = $_full_link[1];
522
+ $suffix = $_full_link[2];
523
+ }
524
+ if ( ! preg_match( '/\/$/', $full_link ) ) {
525
+ $full_link .= '/';
526
+ }
527
+ $full_link .= $share_key . '/' . $suffix;
528
+ } else {
529
+ $full_link .= add_query_arg( 'tinvwlID', $share_key, $full_link );
530
+ }
531
+ }
532
+
533
+ return $full_link;
534
+ }
535
+
536
+ add_filter( 'WPML_filter_link', 'tinvwl_wpml_filter_link', 0, 2 );
537
+ }
538
+
539
+ if ( ! function_exists( 'tinvwl_gift_card_add' ) ) {
540
+
541
+ /**
542
+ * Support WooCommerce - Gift Cards
543
+ * Redirect to page gift card, if requires that customers enter a name and email when purchasing a Gift Card.
544
+ *
545
+ * @param boolean $redirect Default value to redirect.
546
+ * @param \WC_Product $product Product data.
547
+ *
548
+ * @return boolean
549
+ */
550
+ function tinvwl_gift_card_add( $redirect, $product ) {
551
+ if ( $redirect ) {
552
+ return true;
553
+ }
554
+ $is_required_field_giftcard = get_option( 'woocommerce_enable_giftcard_info_requirements' );
555
+
556
+ if ( 'yes' == $is_required_field_giftcard ) { // WPCS: loose comparison ok.
557
+ $is_giftcard = get_post_meta( $product->get_id(), '_giftcard', true );
558
+ if ( 'yes' == $is_giftcard ) { // WPCS: loose comparison ok.
559
+ return true;
560
+ }
561
+ }
562
+
563
+ return $redirect;
564
+ }
565
+
566
+ add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'tinvwl_gift_card_add', 20, 2 );
567
+ }
568
+
569
+ if ( ! function_exists( 'tinvwl_gift_card_add_url' ) ) {
570
+
571
+ /**
572
+ * Support WooCommerce - Gift Cards
573
+ * Redirect to page gift card, if requires that customers enter a name and email when purchasing a Gift Card.
574
+ *
575
+ * @param string $redirect_url Default value to redirect.
576
+ * @param \WC_Product $product Product data.
577
+ *
578
+ * @return boolean
579
+ */
580
+ function tinvwl_gift_card_add_url( $redirect_url, $product ) {
581
+ $is_required_field_giftcard = get_option( 'woocommerce_enable_giftcard_info_requirements' );
582
+
583
+ if ( 'yes' == $is_required_field_giftcard ) { // WPCS: loose comparison ok.
584
+ $is_giftcard = get_post_meta( $product->get_id(), '_giftcard', true );
585
+ if ( 'yes' == $is_giftcard ) { // WPCS: loose comparison ok.
586
+ return $product->get_permalink();
587
+ }
588
+ }
589
+
590
+ return $redirect_url;
591
+ }
592
+
593
+ add_filter( 'tinvwl_product_add_to_cart_redirect_url', 'tinvwl_gift_card_add_url', 20, 2 );
594
+ }
595
+
596
+ if ( ! function_exists( 'tinv_wishlist_meta_support_rpgiftcards' ) ) {
597
+
598
+ /**
599
+ * Set descrition for meta WooCommerce - Gift Cards
600
+ *
601
+ * @param array $meta Meta array.
602
+ *
603
+ * @return array
604
+ */
605
+ function tinv_wishlist_metasupport_rpgiftcards( $meta ) {
606
+ foreach ( $meta as $key => $data ) {
607
+ switch ( $data['key'] ) {
608
+ case 'rpgc_note':
609
+ $meta[ $key ]['key'] = __( 'Note', 'rpgiftcards' );
610
+ break;
611
+ case 'rpgc_to':
612
+ $meta[ $key ]['key'] = ( get_option( 'woocommerce_giftcard_to' ) <> null ? get_option( 'woocommerce_giftcard_to' ) : __( 'To', 'rpgiftcards' ) ); // WPCS: loose comparison ok.
613
+ break;
614
+ case 'rpgc_to_email':
615
+ $meta[ $key ]['key'] = ( get_option( 'woocommerce_giftcard_toEmail' ) <> null ? get_option( 'woocommerce_giftcard_toEmail' ) : __( 'To Email', 'rpgiftcards' ) ); // WPCS: loose comparison ok.
616
+ break;
617
+ case 'rpgc_address':
618
+ $meta[ $key ]['key'] = ( get_option( 'woocommerce_giftcard_address' ) <> null ? get_option( 'woocommerce_giftcard_address' ) : __( 'Address', 'rpgiftcards' ) ); // WPCS: loose comparison ok.
619
+ break;
620
+ case 'rpgc_reload_card':
621
+ $meta[ $key ]['key'] = __( 'Reload existing Gift Card', 'rpgiftcards' );
622
+ break;
623
+ case 'rpgc_description':
624
+ case 'rpgc_reload_check':
625
+ unset( $meta[ $key ] );
626
+ break;
627
+ }
628
+ }
629
+
630
+ return $meta;
631
+ }
632
+
633
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_rpgiftcards' );
634
+ } // End if().
635
+
636
+ if ( ! function_exists( 'tinv_wishlist_metaprepare_rpgiftcards' ) ) {
637
+
638
+ /**
639
+ * Prepare save meta for WooCommerce - Gift Cards
640
+ *
641
+ * @param array $meta Meta array.
642
+ *
643
+ * @return array
644
+ */
645
+ function tinv_wishlist_metaprepare_rpgiftcards( $meta ) {
646
+ if ( array_key_exists( 'rpgc_reload_check', $meta ) ) {
647
+ foreach ( array( 'rpgc_note', 'rpgc_to', 'rpgc_to_email', 'rpgc_address' ) as $value ) {
648
+ if ( array_key_exists( $value, $meta ) ) {
649
+ unset( $meta[ $value ] );
650
+ }
651
+ }
652
+ }
653
+
654
+ return $meta;
655
+ }
656
+
657
+ add_filter( 'tinvwl_product_prepare_meta', 'tinv_wishlist_metaprepare_rpgiftcards' );
658
+ }
659
+
660
+ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_bookings' ) ) {
661
+
662
+ /**
663
+ * Set descrition for meta WooCommerce Bookings
664
+ *
665
+ * @param array $meta Meta array.
666
+ * @param integer $product_id Priduct ID.
667
+ * @param integer $variation_id Variation Product ID.
668
+ *
669
+ * @return array
670
+ */
671
+ function tinv_wishlist_metasupport_woocommerce_bookings( $meta, $product_id, $variation_id ) {
672
+ if ( ! class_exists( 'WC_Booking_Form' ) || ! function_exists( 'is_wc_booking_product' ) ) {
673
+ return $meta;
674
+ }
675
+ $product = wc_get_product( $variation_id ? $variation_id : $product_id );
676
+ if ( is_wc_booking_product( $product ) ) {
677
+ $booking_form = new WC_Booking_Form( $product );
678
+ $post_data = array();
679
+ foreach ( $meta as $data ) {
680
+ $post_data[ $data['key'] ] = $data['display'];
681
+ }
682
+ $booking_data = $booking_form->get_posted_data( $post_data );
683
+ $meta = array();
684
+ foreach ( $booking_data as $key => $value ) {
685
+ if ( ! preg_match( '/^_/', $key ) ) {
686
+ $meta[ $key ] = array(
687
+ 'key' => get_wc_booking_data_label( $key, $product ),
688
+ 'display' => $value,
689
+ );
690
+ }
691
+ }
692
+ }
693
+
694
+ return $meta;
695
+ }
696
+
697
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_bookings', 10, 3 );
698
+ } // End if().
699
+
700
+ if ( ! function_exists( 'tinvwl_item_price_woocommerce_bookings' ) ) {
701
+
702
+ /**
703
+ * Modify price for WooCommerce Bookings
704
+ *
705
+ * @param string $price Returned price.
706
+ * @param array $wl_product Wishlist Product.
707
+ * @param \WC_Product $product Woocommerce Product.
708
+ *
709
+ * @return string
710
+ */
711
+ function tinvwl_item_price_woocommerce_bookings( $price, $wl_product, $product ) {
712
+ if ( ! class_exists( 'WC_Booking_Form' ) || ! function_exists( 'is_wc_booking_product' ) ) {
713
+ return $price;
714
+ }
715
+ if ( is_wc_booking_product( $product ) && array_key_exists( 'meta', $wl_product ) ) {
716
+ $booking_form = new WC_Booking_Form( $product );
717
+ $cost = $booking_form->calculate_booking_cost( $wl_product['meta'] );
718
+ if ( is_wp_error( $cost ) ) {
719
+ return $price;
720
+ }
721
+
722
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
723
+
724
+ if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
725
+ if ( function_exists( 'wc_get_price_excluding_tax' ) ) {
726
+ $display_price = wc_get_price_including_tax( $product, array( 'price' => $cost ) );
727
+ } else {
728
+ $display_price = $product->get_price_including_tax( 1, $cost );
729
+ }
730
+ } else {
731
+ if ( function_exists( 'wc_get_price_excluding_tax' ) ) {
732
+ $display_price = wc_get_price_excluding_tax( $product, array( 'price' => $cost ) );
733
+ } else {
734
+ $display_price = $product->get_price_excluding_tax( 1, $cost );
735
+ }
736
+ }
737
+
738
+ if ( version_compare( WC_VERSION, '2.4.0', '>=' ) ) {
739
+ $price_suffix = $product->get_price_suffix( $cost, 1 );
740
+ } else {
741
+ $price_suffix = $product->get_price_suffix();
742
+ }
743
+ $price = wc_price( $display_price ) . $price_suffix;
744
+ }
745
+
746
+ return $price;
747
+ }
748
+
749
+ add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_bookings', 10, 3 );
750
+ } // End if().
751
+
752
+ if ( ! function_exists( 'tinvwl_item_status_woocommerce_bookings' ) ) {
753
+
754
+ /**
755
+ * Modify availability for WooCommerce Bookings
756
+ *
757
+ * @param string $status Status availability.
758
+ * @param string $availability Default availability.
759
+ * @param array $wl_product Wishlist Product.
760
+ * @param \WC_Product $product Woocommerce Product.
761
+ *
762
+ * @return type
763
+ */
764
+ function tinvwl_item_status_woocommerce_bookings( $status, $availability, $wl_product, $product ) {
765
+ if ( ! class_exists( 'WC_Booking_Form' ) || ! function_exists( 'is_wc_booking_product' ) ) {
766
+ return $status;
767
+ }
768
+ if ( is_wc_booking_product( $product ) && array_key_exists( 'meta', $wl_product ) ) {
769
+ $booking_form = new WC_Booking_Form( $product );
770
+ $cost = $booking_form->calculate_booking_cost( $wl_product['meta'] );
771
+ if ( is_wp_error( $cost ) ) {
772
+ return '<p class="stock out-of-stock"><span><i class="fa fa-times"></i></span><span>' . $cost->get_error_message() . '</span></p>';
773
+ }
774
+ }
775
+
776
+ return $status;
777
+ }
778
+
779
+ add_filter( 'tinvwl_wishlist_item_status', 'tinvwl_item_status_woocommerce_bookings', 10, 4 );
780
+ }
781
+
782
+ if ( ! function_exists( 'tinv_wishlist_metasupport_wc_gf_addons' ) ) {
783
+
784
+ /**
785
+ * Set descrition for meta WooCommerce - Gravity Forms Product Add-Ons
786
+ *
787
+ * @param array $meta Meta array.
788
+ *
789
+ * @return array
790
+ */
791
+ function tinv_wishlist_metasupport_wc_gf_addons( $meta ) {
792
+ if ( array_key_exists( 'wc_gforms_form_id', $meta ) && class_exists( 'RGFormsModel' ) ) {
793
+ $form_meta = RGFormsModel::get_form_meta( $meta['wc_gforms_form_id']['display'] );
794
+ if ( array_key_exists( 'fields', $form_meta ) ) {
795
+ $_meta = array();
796
+ foreach ( $form_meta['fields'] as $field ) {
797
+ $field_name = $field->get_first_input_id( array( 'id' => 0 ) );
798
+ if ( array_key_exists( $field_name, $meta ) ) {
799
+ $meta[ $field_name ]['key'] = $field->label;
800
+ $_meta[ $field_name ] = $meta[ $field_name ];
801
+ }
802
+ }
803
+ $meta = $_meta;
804
+ }
805
+ }
806
+
807
+ return $meta;
808
+ }
809
+
810
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_wc_gf_addons' );
811
+ }
812
+
813
+ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_composite_products' ) ) {
814
+
815
+ /**
816
+ * Set descrition for meta WooCommerce Composite Products
817
+ *
818
+ * @param array $meta Meta array.
819
+ * @param integer $product_id Product ID.
820
+ *
821
+ * @return array
822
+ */
823
+ function tinv_wishlist_metasupport_woocommerce_composite_products( $meta, $product_id ) {
824
+ if ( array_key_exists( 'wccp_component_selection', $meta ) && is_array( $meta['wccp_component_selection'] ) ) {
825
+ $meta = array();
826
+ } // End if().
827
+
828
+ return $meta;
829
+ }
830
+
831
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_composite_products', 10, 2 );
832
+ } // End if().
833
+
834
+ if ( ! function_exists( 'tinvwl_row_woocommerce_composite_products' ) ) {
835
+
836
+ /**
837
+ * Add rows for sub product for WooCommerce Composite Products
838
+ *
839
+ * @param array $wl_product Wishlist Product.
840
+ * @param \WC_Product $product Woocommerce Product.
841
+ */
842
+ function tinvwl_row_woocommerce_composite_products( $wl_product, $product ) {
843
+ if ( is_object( $product ) && $product->is_type( 'composite' ) && array_key_exists( 'wccp_component_selection', $wl_product['meta'] ) ) {
844
+ $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
845
+
846
+ $components = $product->get_components();
847
+ foreach ( $components as $component_id => $component ) {
848
+ $composited_product_id = ! empty( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) : '';
849
+ $composited_product_quantity = isset( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) : $component->get_quantity( 'min' );
850
+
851
+ $composited_variation_id = isset( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) ? wc_clean( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) : '';
852
+
853
+ if ( $composited_product_id ) {
854
+
855
+ $composited_product_wrapper = $component->get_option( $composited_variation_id ? $composited_variation_id : $composited_product_id );
856
+
857
+ if ( ! $composited_product_wrapper ) {
858
+ continue;
859
+ }
860
+
861
+ $composited_product = $composited_product_wrapper->get_product();
862
+
863
+ if ( $composited_product->is_sold_individually() && $composited_product_quantity > 1 ) {
864
+ $composited_product_quantity = 1;
865
+ }
866
+
867
+ $product_url = $composited_product->get_permalink();
868
+ $product_image = $composited_product->get_image();
869
+ $product_title = $composited_product->get_title();
870
+ $product_price = $composited_product->get_price_html();
871
+ if ( $composited_product->is_visible() ) {
872
+ $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
873
+ $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
874
+ }
875
+ $product_title .= tinv_wishlist_get_item_data( $composited_product, $wl_product );
876
+
877
+ $availability = (array) $composited_product->get_availability();
878
+ if ( ! array_key_exists( 'availability', $availability ) ) {
879
+ $availability['availability'] = '';
880
+ }
881
+ if ( ! array_key_exists( 'class', $availability ) ) {
882
+ $availability['class'] = '';
883
+ }
884
+ $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
885
+ $row_string = '<tr>';
886
+ $row_string .= '<td colspan="2"></td>&nbsp;<td class="product-thumbnail">%2$s</td><td class="product-name">%1$s:<br/>%3$s</td>';
887
+ if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
888
+ $row_string .= '<td class="product-price">%3$s &times; %6$s</td>';
889
+ }
890
+ if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
891
+ $row_string .= '<td class="product-date">&nbsp;</td>';
892
+ }
893
+ if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
894
+ $row_string .= '<td class="product-stock">%5$s</td>';
895
+ }
896
+ if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
897
+ $row_string .= '<td class="product-action">&nbsp;</td>';
898
+ }
899
+ $row_string .= '</tr>';
900
+
901
+ echo sprintf( $row_string, $component->get_title(), $product_image, $product_title, $product_price, $availability_html, $composited_product_quantity * $product_quantity ); // WPCS: xss ok.
902
+ } // End if().
903
+ } // End foreach().
904
+ } // End if().
905
+ }
906
+
907
+ add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_composite_products', 10, 2 );
908
+ } // End if().
909
+
910
+ if ( ! function_exists( 'tinvwl_item_price_woocommerce_composite_products' ) ) {
911
+
912
+ /**
913
+ * Modify price for WooCommerce Composite Products
914
+ *
915
+ * @param string $price Returned price.
916
+ * @param array $wl_product Wishlist Product.
917
+ * @param \WC_Product $product Woocommerce Product.
918
+ *
919
+ * @return string
920
+ */
921
+ function tinvwl_item_price_woocommerce_composite_products( $price, $wl_product, $product ) {
922
+ if ( is_object( $product ) && $product->is_type( 'composite' ) && array_key_exists( 'wccp_component_selection', $wl_product['meta'] ) ) {
923
+ $components = $product->get_components();
924
+ $_price = $product->get_price();
925
+ $regular_price = $product->get_regular_price();
926
+ foreach ( $components as $component_id => $component ) {
927
+ $composited_product_id = ! empty( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) : '';
928
+ $composited_product_quantity = isset( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_quantity'][ $component_id ] ) : $component->get_quantity( 'min' );
929
+
930
+ $composited_variation_id = isset( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) ? wc_clean( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) : '';
931
+
932
+ if ( $composited_product_id ) {
933
+ $composited_product_wrapper = $component->get_option( $composited_variation_id ? $composited_variation_id : $composited_product_id );
934
+ if ( $component->is_priced_individually() ) {
935
+ $_price += $composited_product_wrapper->get_price() * $composited_product_quantity;
936
+ $regular_price += $composited_product_wrapper->get_regular_price() * $composited_product_quantity;
937
+ }
938
+ }
939
+ }
940
+ if ( $_price == $regular_price ) {
941
+ $price = wc_price( $_price ) . $product->get_price_suffix();
942
+ } else {
943
+ $price = wc_format_sale_price( $regular_price, $_price ) . $product->get_price_suffix();
944
+ }
945
+ }
946
+
947
+ return $price;
948
+ }
949
+
950
+ add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_composite_products', 10, 3 );
951
+ } // End if().
952
+
953
+ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_bundles' ) ) {
954
+
955
+ /**
956
+ * Set descrition for meta WooCommerce Product Bundles
957
+ *
958
+ * @param array $meta Meta array.
959
+ * @param integer $product_id Product ID.
960
+ *
961
+ * @return array
962
+ */
963
+ function tinv_wishlist_metasupport_woocommerce_product_bundles( $meta, $product_id ) {
964
+ $product = wc_get_product( $product_id );
965
+ if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
966
+ $meta = array();
967
+ }
968
+
969
+ return $meta;
970
+ }
971
+
972
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_product_bundles', 10, 2 );
973
+ } // End if().
974
+
975
+ if ( ! function_exists( 'tinvwl_row_woocommerce_product_bundles' ) ) {
976
+
977
+ /**
978
+ * Add rows for sub product for WooCommerce Product Bundles
979
+ *
980
+ * @param array $wl_product Wishlist Product.
981
+ * @param \WC_Product $product Woocommerce Product.
982
+ */
983
+ function tinvwl_row_woocommerce_product_bundles( $wl_product, $product ) {
984
+ if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
985
+ $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
986
+
987
+ $product_id = WC_PB_Core_Compatibility::get_id( $product );
988
+ $bundled_items = $product->get_bundled_items();
989
+ if ( ! empty( $bundled_items ) ) {
990
+ foreach ( $bundled_items as $bundled_item_id => $bundled_item ) {
991
+ $bundled_product_id = $bundled_item->product_id;
992
+ $bundled_item_variation_id_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_variation_id_' . $bundled_item_id;
993
+ $bundled_variation_id = absint( isset( $wl_product['meta'][ $bundled_item_variation_id_request_key ] ) ? $wl_product['meta'][ $bundled_item_variation_id_request_key ] : 0 );
994
+ if ( ! empty( $bundled_variation_id ) ) {
995
+ $bundled_item->product = wc_get_product( $bundled_variation_id );
996
+ }
997
+ $bundled_product_type = $bundled_item->product->get_type();
998
+ $is_optional = $bundled_item->is_optional();
999
+
1000
+ $bundled_item_quantity_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_quantity_' . $bundled_item_id;
1001
+ $bundled_product_qty = isset( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) ? absint( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) : $bundled_item->get_quantity();
1002
+
1003
+ if ( $is_optional ) {
1004
+
1005
+ /** Documented in method 'get_posted_bundle_configuration'. */
1006
+ $bundled_item_selected_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_selected_optional_' . $bundled_item_id;
1007
+
1008
+ if ( ! array_key_exists( $bundled_item_selected_request_key, $wl_product['meta'] ) ) {
1009
+ $bundled_product_qty = 0;
1010
+ }
1011
+ }
1012
+ if ( 0 === $bundled_product_qty || 'visible' != $bundled_item->cart_visibility ) {
1013
+ continue;
1014
+ }
1015
+
1016
+ $product_url = $bundled_item->product->get_permalink();
1017
+ $product_image = $bundled_item->product->get_image();
1018
+ $product_title = $bundled_item->product->get_title();
1019
+ $product_price = $bundled_item->product->get_price_html();
1020
+ if ( $bundled_item->product->is_visible() ) {
1021
+ $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
1022
+ $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
1023
+ }
1024
+ $product_title .= tinv_wishlist_get_item_data( $bundled_item->product, $wl_product );
1025
+
1026
+ $availability = (array) $bundled_item->product->get_availability();
1027
+ if ( ! array_key_exists( 'availability', $availability ) ) {
1028
+ $availability['availability'] = '';
1029
+ }
1030
+ if ( ! array_key_exists( 'class', $availability ) ) {
1031
+ $availability['class'] = '';
1032
+ }
1033
+ $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1034
+ $row_string = '<tr>';
1035
+ $row_string .= '<td colspan="2">&nbsp;</td><td class="product-thumbnail">%1$s</td><td class="product-name">%2$s</td>';
1036
+ if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
1037
+ $row_string .= '<td class="product-price">%3$s &times; %5$s</td>';
1038
+ }
1039
+ if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
1040
+ $row_string .= '<td class="product-date">&nbsp;</td>';
1041
+ }
1042
+ if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
1043
+ $row_string .= '<td class="product-stock">%4$s</td>';
1044
+ }
1045
+
1046
+ if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
1047
+ $row_string .= '<td class="product-action">&nbsp;</td>';
1048
+ }
1049
+ $row_string .= '</tr>';
1050
+
1051
+ echo sprintf( $row_string, $product_image, $product_title, $product_price, $availability_html, $bundled_product_qty ); // WPCS: xss ok.
1052
+ } // End foreach().
1053
+ } // End if().
1054
+ } // End if().
1055
+ }
1056
+
1057
+ add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_product_bundles', 10, 2 );
1058
+ } // End if().
1059
+
1060
+ if ( ! function_exists( 'tinvwl_item_price_woocommerce_product_bundles' ) ) {
1061
+
1062
+ /**
1063
+ * Modify price for WooCommerce Product Bundles
1064
+ *
1065
+ * @param string $price Returned price.
1066
+ * @param array $wl_product Wishlist Product.
1067
+ * @param \WC_Product $product Woocommerce Product.
1068
+ *
1069
+ * @return string
1070
+ */
1071
+ function tinvwl_item_price_woocommerce_product_bundles( $price, $wl_product, $product ) {
1072
+ if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
1073
+
1074
+ $bundle_price = $product->get_price();
1075
+ $product_id = WC_PB_Core_Compatibility::get_id( $product );
1076
+ $bundled_items = $product->get_bundled_items();
1077
+
1078
+ if ( ! empty( $bundled_items ) ) {
1079
+
1080
+ $bundled_items_price = 0.0;
1081
+
1082
+ foreach ( $bundled_items as $bundled_item_id => $bundled_item ) {
1083
+ $is_optional = $bundled_item->is_optional();
1084
+
1085
+ $bundled_item_quantity_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_quantity_' . $bundled_item_id;
1086
+ $bundled_product_qty = isset( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) ? absint( $wl_product['meta'][ $bundled_item_quantity_request_key ] ) : $bundled_item->get_quantity();
1087
+
1088
+ if ( $is_optional ) {
1089
+
1090
+ /** Documented in method 'get_posted_bundle_configuration'. */
1091
+ $bundled_item_selected_request_key = apply_filters( 'woocommerce_product_bundle_field_prefix', '', $product_id ) . 'bundle_selected_optional_' . $bundled_item_id;
1092
+
1093
+ if ( ! array_key_exists( $bundled_item_selected_request_key, $wl_product['meta'] ) ) {
1094
+ $bundled_product_qty = 0;
1095
+ }
1096
+ }
1097
+ if ( 0 === $bundled_product_qty ) {
1098
+ continue;
1099
+ }
1100
+
1101
+ $bundled_item_price = $bundled_item->product->get_price() * $bundled_product_qty;
1102
+
1103
+ $bundled_items_price += (double) $bundled_item_price;
1104
+
1105
+ } // End foreach().
1106
+ $price = wc_price( (double) $bundle_price + $bundled_items_price );
1107
+ $price = apply_filters( 'woocommerce_get_price_html', $price, $product );
1108
+ } // End if().
1109
+ } // End if().
1110
+
1111
+ return $price;
1112
+ }
1113
+
1114
+ add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_product_bundles', 10, 3 );
1115
+ } // End if().
1116
+
1117
+ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_mix_and_match_products' ) ) {
1118
+
1119
+ /**
1120
+ * Set description for meta WooCommerce Mix and Match
1121
+ *
1122
+ * @param array $meta Meta array.
1123
+ * @param integer $product_id Product ID.
1124
+ *
1125
+ * @return array
1126
+ */
1127
+ function tinv_wishlist_metasupport_woocommerce_mix_and_match_products( $meta, $product_id ) {
1128
+ if ( array_key_exists( 'mnm_quantity', $meta ) ) {
1129
+ $product = wc_get_product( $product_id );
1130
+ if ( is_object( $product ) && $product->is_type( 'mix-and-match' ) ) {
1131
+ $meta = array();
1132
+ }
1133
+ }
1134
+
1135
+ return $meta;
1136
+ }
1137
+
1138
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_mix_and_match_products', 10, 2 );
1139
+ } // End if().
1140
+
1141
+ if ( ! function_exists( 'tinvwl_row_woocommerce_mix_and_match_products' ) ) {
1142
+
1143
+ /**
1144
+ * Add rows for sub product for WooCommerce Mix and Match
1145
+ *
1146
+ * @param array $wl_product Wishlist Product.
1147
+ * @param \WC_Product $product Woocommerce Product.
1148
+ */
1149
+ function tinvwl_row_woocommerce_mix_and_match_products( $wl_product, $product ) {
1150
+ if ( is_object( $product ) && $product->is_type( 'mix-and-match' ) && array_key_exists( 'mnm_quantity', $wl_product['meta'] ) ) {
1151
+ $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
1152
+ $mnm_items = $product->get_children();
1153
+ if ( ! empty( $mnm_items ) ) {
1154
+ foreach ( $mnm_items as $id => $mnm_item ) {
1155
+ $item_quantity = 0;
1156
+ if ( array_key_exists( $id, $wl_product['meta']['mnm_quantity'] ) ) {
1157
+ $item_quantity = absint( $wl_product['meta']['mnm_quantity'][ $id ] );
1158
+ }
1159
+ if ( 0 >= $item_quantity ) {
1160
+ continue;
1161
+ }
1162
+
1163
+ $product_url = $mnm_item->get_permalink();
1164
+ $product_image = $mnm_item->get_image();
1165
+ $product_title = $mnm_item->get_title();
1166
+ $product_price = $mnm_item->get_price_html();
1167
+ if ( $mnm_item->is_visible() ) {
1168
+ $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
1169
+ $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
1170
+ }
1171
+ $product_title .= tinv_wishlist_get_item_data( $mnm_item, $wl_product );
1172
+
1173
+ $availability = (array) $mnm_item->get_availability();
1174
+ if ( ! array_key_exists( 'availability', $availability ) ) {
1175
+ $availability['availability'] = '';
1176
+ }
1177
+ if ( ! array_key_exists( 'class', $availability ) ) {
1178
+ $availability['class'] = '';
1179
+ }
1180
+ $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1181
+ $row_string = '<tr>';
1182
+ $row_string .= '<td colspan="2">&nbsp;</td><td class="product-thumbnail">%1$s</td><td class="product-name">%2$s</td>';
1183
+ if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
1184
+ $row_string .= '<td class="product-price">%3$s &times; %5$s</td>';
1185
+ }
1186
+ if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
1187
+ $row_string .= '<td class="product-date">&nbsp;</td>';
1188
+ }
1189
+ if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
1190
+ $row_string .= '<td class="product-stock">%4$s</td>';
1191
+ }
1192
+ if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
1193
+ $row_string .= '<td class="product-action">&nbsp;</td>';
1194
+ }
1195
+ $row_string .= '</tr>';
1196
+
1197
+ echo sprintf( $row_string, $product_image, $product_title, $product_price, $availability_html, $item_quantity * $product_quantity ); // WPCS: xss ok.
1198
+ } // End foreach().
1199
+ } // End if().
1200
+ } // End if().
1201
+ }
1202
+
1203
+ add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_mix_and_match_products', 10, 2 );
1204
+ } // End if().
1205
+
1206
+ if ( ! function_exists( 'tinvwl_item_price_woocommerce_mix_and_match_products' ) ) {
1207
+
1208
+ /**
1209
+ * Modify price for WooCommerce Mix and Match
1210
+ *
1211
+ * @param string $price Returned price.
1212
+ * @param array $wl_product Wishlist Product.
1213
+ * @param \WC_Product $product Woocommerce Product.
1214
+ *
1215
+ * @return string
1216
+ */
1217
+ function tinvwl_item_price_woocommerce_mix_and_match_products( $price, $wl_product, $product ) {
1218
+ if ( is_object( $product ) && $product->is_type( 'mix-and-match' ) && $product->is_priced_per_product() ) {
1219
+ $mnm_items = $product->get_children();
1220
+ if ( ! empty( $mnm_items ) ) {
1221
+ $_price = 0;
1222
+ foreach ( $mnm_items as $id => $mnm_item ) {
1223
+ $item_quantity = 0;
1224
+ if ( array_key_exists( $id, $wl_product['meta']['mnm_quantity'] ) ) {
1225
+ $item_quantity = absint( $wl_product['meta']['mnm_quantity'][ $id ] );
1226
+ }
1227
+ if ( 0 >= $item_quantity ) {
1228
+ continue;
1229
+ }
1230
+ $_price += wc_get_price_to_display( $mnm_item, array( 'qty' => $item_quantity ) );
1231
+ }
1232
+ if ( 0 < $_price ) {
1233
+ if ( $product->is_on_sale() ) {
1234
+ $price = wc_format_sale_price( $_price + wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ), $_price + wc_get_price_to_display( $product ) ) . $product->get_price_suffix();
1235
+ } else {
1236
+ $price = wc_price( $_price + wc_get_price_to_display( $product ) ) . $product->get_price_suffix();
1237
+ }
1238
+ $price = apply_filters( 'woocommerce_get_price_html', $price, $product );
1239
+ }
1240
+ }
1241
+ }
1242
+
1243
+ return $price;
1244
+ }
1245
+
1246
+ add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_mix_and_match_products', 10, 3 );
1247
+ } // End if().
1248
+
1249
+ if ( ! function_exists( 'tinvwl_add_form_woocommerce_mix_and_match_products' ) ) {
1250
+
1251
+ /**
1252
+ * Remove empty meta for WooCommerce Mix and Match
1253
+ *
1254
+ * @param array $form Post form data.
1255
+ *
1256
+ * @return array
1257
+ */
1258
+ function tinvwl_add_form_woocommerce_mix_and_match_products( $form = array() ) {
1259
+ if ( array_key_exists( 'mnm_quantity', $form ) ) {
1260
+ if ( is_array( $form['mnm_quantity'] ) && ! empty( $form['mnm_quantity'] ) ) {
1261
+ foreach ( $form['mnm_quantity'] as $key => $value ) {
1262
+ $value = absint( $value );
1263
+ if ( empty( $value ) ) {
1264
+ unset( $form['mnm_quantity'][ $key ] );
1265
+ }
1266
+ }
1267
+ if ( empty( $form['mnm_quantity'] ) ) {
1268
+ unset( $form['mnm_quantity'] );
1269
+ }
1270
+ }
1271
+ }
1272
+
1273
+ return $form;
1274
+ }
1275
+
1276
+ add_filter( 'tinvwl_addtowishlist_add_form', 'tinvwl_add_form_woocommerce_mix_and_match_products' );
1277
+ } // End if().
1278
+
1279
+ if ( ! function_exists( 'tinv_wishlist_metasupport_yith_woocommerce_product_bundles' ) ) {
1280
+
1281
+ /**
1282
+ * Set descrition for meta WooCommerce Mix and Match
1283
+ *
1284
+ * @param array $meta Meta array.
1285
+ * @param integer $product_id Product ID.
1286
+ *
1287
+ * @return array
1288
+ */
1289
+ function tinv_wishlist_metasupport_yith_woocommerce_product_bundles( $meta, $product_id ) {
1290
+ if ( array_key_exists( 'yith_bundle_quantity_1', $meta ) ) {
1291
+ $product = wc_get_product( $product_id );
1292
+ if ( is_object( $product ) && $product->is_type( 'yith_bundle' ) ) {
1293
+ $meta = array();
1294
+ }
1295
+ }
1296
+
1297
+ return $meta;
1298
+ }
1299
+
1300
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_yith_woocommerce_product_bundles', 10, 2 );
1301
+ } // End if().
1302
+
1303
+ if ( ! function_exists( 'tinvwl_item_status_yith_woocommerce_product_bundles' ) ) {
1304
+
1305
+ /**
1306
+ * Modify status for YITH WooCommerce Product Bundles
1307
+ *
1308
+ * @param string $availability_html Returned availability status.
1309
+ * @param string $availability Availability status.
1310
+ * @param array $wl_product Wishlist Product.
1311
+ * @param \WC_Product $product Woocommerce Product.
1312
+ *
1313
+ * @return string
1314
+ */
1315
+ function tinvwl_item_status_yith_woocommerce_product_bundles( $availability_html, $availability, $wl_product, $product ) {
1316
+ if ( empty( $availability ) && is_object( $product ) && $product->is_type( 'yith_bundle' ) ) {
1317
+ $response = true;
1318
+ $bundled_items = $product->get_bundled_items();
1319
+ foreach ( $bundled_items as $key => $bundled_item ) {
1320
+ if ( method_exists( $bundled_item, 'is_optional' ) ) {
1321
+ if ( $bundled_item->is_optional() && ! array_key_exists( 'yith_bundle_optional_' . $key, $wl_product['meta'] ) ) {
1322
+ continue;
1323
+ }
1324
+ }
1325
+ if ( ! $bundled_item->get_product()->is_in_stock() ) {
1326
+ $response = false;
1327
+ }
1328
+ }
1329
+
1330
+ if ( ! $response ) {
1331
+ $availability = array(
1332
+ 'class' => 'out-of-stock',
1333
+ 'availability' => __( 'Out of stock', 'woocommerce' ),
1334
+ );
1335
+ $availability_html = '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1336
+ }
1337
+ }
1338
+
1339
+ return $availability_html;
1340
+ }
1341
+
1342
+ add_filter( 'tinvwl_wishlist_item_status', 'tinvwl_item_status_yith_woocommerce_product_bundles', 10, 4 );
1343
+ } // End if().
1344
+
1345
+ if ( ! function_exists( 'tinvwl_row_yith_woocommerce_product_bundles' ) ) {
1346
+
1347
+ /**
1348
+ * Add rows for sub product for YITH WooCommerce Product Bundles
1349
+ *
1350
+ * @param array $wl_product Wishlist Product.
1351
+ * @param \WC_Product $product Woocommerce Product.
1352
+ */
1353
+ function tinvwl_row_yith_woocommerce_product_bundles( $wl_product, $product ) {
1354
+ if ( is_object( $product ) && $product->is_type( 'yith_bundle' ) ) {
1355
+ $bundled_items = $product->get_bundled_items();
1356
+ $product_quantity = $product->is_sold_individually() ? 1 : $wl_product['quantity'];
1357
+ if ( ! empty( $bundled_items ) ) {
1358
+ foreach ( $bundled_items as $key => $bundled_item ) {
1359
+ $item_quantity = $bundled_item->get_quantity();
1360
+ if ( array_key_exists( 'yith_bundle_quantity_' . $key, $wl_product['meta'] ) ) {
1361
+ $item_quantity = absint( $wl_product['meta'][ 'yith_bundle_quantity_' . $key ] );
1362
+ }
1363
+ if ( method_exists( $bundled_item, 'is_optional' ) ) {
1364
+ if ( $bundled_item->is_optional() && ! array_key_exists( 'yith_bundle_optional_' . $key, $wl_product['meta'] ) ) {
1365
+ $item_quantity = 0;
1366
+ }
1367
+ }
1368
+ if ( 0 >= $item_quantity ) {
1369
+ continue;
1370
+ }
1371
+
1372
+ $product = $bundled_item->get_product();
1373
+ if ( ! is_object( $product ) ) {
1374
+ continue;
1375
+ }
1376
+
1377
+ $product_url = $product->get_permalink();
1378
+ $product_image = $product->get_image();
1379
+ $product_title = $product->get_title();
1380
+ $product_price = $product->get_price_html();
1381
+ if ( $product->is_visible() ) {
1382
+ $product_image = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_image );
1383
+ $product_title = sprintf( '<a href="%s">%s</a>', esc_url( $product_url ), $product_title );
1384
+ }
1385
+ $product_title .= tinv_wishlist_get_item_data( $product, $wl_product );
1386
+
1387
+ $availability = (array) $product->get_availability();
1388
+ if ( ! array_key_exists( 'availability', $availability ) ) {
1389
+ $availability['availability'] = '';
1390
+ }
1391
+ if ( ! array_key_exists( 'class', $availability ) ) {
1392
+ $availability['class'] = '';
1393
+ }
1394
+ $availability_html = empty( $availability['availability'] ) ? '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-check"></i></span><span class="tinvwl-txt">' . esc_html__( 'In stock', 'ti-woocommerce-wishlist' ) . '</span></p>' : '<p class="stock ' . esc_attr( $availability['class'] ) . '"><span><i class="fa fa-times"></i></span><span>' . esc_html( $availability['availability'] ) . '</span></p>';
1395
+ $row_string = '<tr>';
1396
+ $row_string .= '<td colspan="2">&nbsp;</td><td class="product-thumbnail">%1$s</td><td class="product-name">%2$s</td>';
1397
+ if ( tinv_get_option( 'product_table', 'colm_price' ) ) {
1398
+ $row_string .= '<td class="product-price">%3$s &times; %5$s</td>';
1399
+ }
1400
+ if ( tinv_get_option( 'product_table', 'colm_date' ) ) {
1401
+ $row_string .= '<td class="product-date">&nbsp;</td>';
1402
+ }
1403
+ if ( tinv_get_option( 'product_table', 'colm_stock' ) ) {
1404
+ $row_string .= '<td class="product-stock">%4$s</td>';
1405
+ }
1406
+ if ( tinv_get_option( 'product_table', 'add_to_cart' ) ) {
1407
+ $row_string .= '<td class="product-action">&nbsp;</td>';
1408
+ }
1409
+ $row_string .= '</tr>';
1410
+
1411
+ echo sprintf( $row_string, $product_image, $product_title, $product_price, $availability_html, $item_quantity * $product_quantity ); // WPCS: xss ok.
1412
+ } // End foreach().
1413
+ } // End if().
1414
+ } // End if().
1415
+ }
1416
+
1417
+ add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_yith_woocommerce_product_bundles', 10, 2 );
1418
+ } // End if().
1419
+
1420
+ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_add_on' ) ) {
1421
+
1422
+ /**
1423
+ * Set descrition for meta WooCommerce Product Add-on
1424
+ *
1425
+ * @param array $meta Meta array.
1426
+ * @param integer $product_id Product ID.
1427
+ *
1428
+ * @return array
1429
+ */
1430
+ function tinv_wishlist_metasupport_woocommerce_product_add_on( $meta, $product_id ) {
1431
+ $personalized_meta = absint( get_post_meta( $product_id, '_product_meta_id', true ) );
1432
+ if ( ! empty( $personalized_meta ) ) {
1433
+ $meta = array();
1434
+ }
1435
+
1436
+ return $meta;
1437
+ }
1438
+
1439
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_product_add_on', 10, 2 );
1440
+ } // End if().
1441
+
1442
+ if ( ! function_exists( 'tinv_wishlist_item_meta_woocommerce_product_add_on' ) ) {
1443
+
1444
+ /**
1445
+ * Set descrition for meta WooCommerce Product Add-on
1446
+ *
1447
+ * @param array $meta Meta array.
1448
+ * @param array $wl_product Wishlist Product.
1449
+ * @param \WC_Product $product Woocommerce Product.
1450
+ *
1451
+ * @return array
1452
+ */
1453
+ function tinv_wishlist_item_meta_woocommerce_product_add_on( $meta, $wl_product, $product ) {
1454
+ $personalized_meta = absint( get_post_meta( $wl_product['product_id'], '_product_meta_id', true ) );
1455
+ if ( ! empty( $personalized_meta ) && class_exists( 'NM_PersonalizedProduct' ) ) {
1456
+
1457
+ $product_meta = $wl_product['meta']['ppom']['fields'];
1458
+
1459
+ if ( $product_meta ) {
1460
+
1461
+ $item_meta = array();
1462
+
1463
+ foreach ( $product_meta as $key => $value ) {
1464
+
1465
+ if ( empty( $value ) ) {
1466
+ continue;
1467
+ }
1468
+
1469
+ $product_id = $wl_product['product_id'];
1470
+ $field_meta = ppom_get_field_meta_by_dataname( $product_id, $key );
1471
+
1472
+ if ( empty( $field_meta ) ) {
1473
+ continue;
1474
+ }
1475
+
1476
+ $field_type = $field_meta['type'];
1477
+ $field_title = $field_meta['title'];
1478
+
1479
+
1480
+ switch ( $field_type ) {
1481
+ case 'quantities':
1482
+ $total_qty = 0;
1483
+ foreach ( $value as $label => $qty ) {
1484
+ if ( ! empty( $qty ) ) {
1485
+ $item_meta[] = array(
1486
+ 'key' => $label,
1487
+ 'display' => $qty,
1488
+ );
1489
+ $total_qty += $qty;
1490
+ }
1491
+ }
1492
+ break;
1493
+
1494
+ case 'file':
1495
+ $file_thumbs_html = '';
1496
+ foreach ( $value as $file_id => $file_uploaded ) {
1497
+ $file_name = $file_uploaded['org'];
1498
+ $file_thumbs_html .= ppom_show_file_thumb( $file_name );
1499
+ }
1500
+ $item_meta[] = array(
1501
+ 'key' => $field_title,
1502
+ 'display' => $file_thumbs_html,
1503
+ );
1504
+
1505
+ break;
1506
+
1507
+ case 'cropper':
1508
+ $file_thumbs_html = '';
1509
+ foreach ( $value as $file_id => $file_cropped ) {
1510
+
1511
+ $file_name = $file_cropped['org'];
1512
+ $file_thumbs_html .= ppom_show_file_thumb( $file_name, true );
1513
+ }
1514
+ $item_meta[] = array(
1515
+ 'key' => $field_title,
1516
+ 'display' => $file_thumbs_html,
1517
+ );
1518
+ break;
1519
+
1520
+ case 'image':
1521
+ if ( $value ) {
1522
+ foreach ( $value as $id => $images_meta ) {
1523
+ $images_meta = json_decode( stripslashes( $images_meta ), true );
1524
+ $image_url = stripslashes( $images_meta['link'] );
1525
+ $image_html = '<img class="img-thumbnail" style="width:' . esc_attr( ppom_get_thumbs_size() ) . '" src="' . esc_url( $image_url ) . '" title="' . esc_attr( $images_meta['title'] ) . '">';
1526
+ $meta_key = $field_title . '(' . $images_meta['title'] . ')';
1527
+ $item_meta[] = array(
1528
+ 'key' => $meta_key,
1529
+ 'display' => $image_html,
1530
+ );
1531
+ }
1532
+ }
1533
+ break;
1534
+
1535
+ case 'audio':
1536
+ if ( $value ) {
1537
+ $ppom_file_count = 1;
1538
+ foreach ( $value as $id => $audio_meta ) {
1539
+ $audio_meta = json_decode( stripslashes( $audio_meta ), true );
1540
+ $audio_url = stripslashes( $audio_meta['link'] );
1541
+ $audio_html = '<a href="' . esc_url( $audio_url ) . '" title="' . esc_attr( $audio_meta['title'] ) . '">' . $audio_meta['title'] . '</a>';
1542
+ $meta_key = $field_title . ': ' . $ppom_file_count ++;
1543
+ $item_meta[] = array(
1544
+ 'key' => $meta_key,
1545
+ 'display' => $audio_html,
1546
+ );
1547
+ }
1548
+ }
1549
+ break;
1550
+
1551
+ case 'bulkquantity':
1552
+ $item_meta[] = array(
1553
+ 'key' => $key,
1554
+ 'display' => $value['option'] . ' (' . $value['qty'] . ')',
1555
+ );
1556
+ break;
1557
+
1558
+ default:
1559
+ $value = is_array( $value ) ? implode( ",", $value ) : $value;
1560
+ $item_meta[] = array(
1561
+ 'key' => $field_title,
1562
+ 'display' => stripcslashes( $value ),
1563
+ );
1564
+ break;
1565
+ }
1566
+
1567
+ } // End foreach().
1568
+ } // End if().
1569
+
1570
+ if ( 0 < count( $item_meta ) ) {
1571
+ ob_start();
1572
+ tinv_wishlist_template( 'ti-wishlist-item-data.php', array( 'item_data' => $item_meta ) );
1573
+ $meta .= '<br/>' . ob_get_clean();
1574
+ }
1575
+ } // End if().
1576
+
1577
+ return $meta;
1578
+ }
1579
+
1580
+ add_filter( 'tinvwl_wishlist_item_meta_data', 'tinv_wishlist_item_meta_woocommerce_product_add_on', 10, 3 );
1581
+ } // End if().
1582
+
1583
+ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_tm_extra_product_options' ) ) {
1584
+
1585
+ /**
1586
+ * Set descrition for meta WooCommerce TM Extra Product Options
1587
+ *
1588
+ * @param array $meta Meta array.
1589
+ * @param integer $product_id Product ID.
1590
+ * @param integer $variation_id Product variation ID.
1591
+ *
1592
+ * @return array
1593
+ */
1594
+ function tinv_wishlist_metasupport_woocommerce_tm_extra_product_options( $meta, $product_id, $variation_id ) {
1595
+ if ( array_key_exists( 'tcaddtocart', $meta ) && function_exists( 'TM_EPO_API' ) && function_exists( 'TM_EPO' ) ) {
1596
+ $has_epo = TM_EPO_API()->has_options( $product_id );
1597
+ if ( TM_EPO_API()->is_valid_options( $has_epo ) ) {
1598
+ $post_data = array();
1599
+ foreach ( $meta as $key => $value ) {
1600
+ $post_data[ $key ] = $value['display'];
1601
+ }
1602
+ $cart_item = TM_EPO()->add_cart_item_data_helper( array(), $product_id, $post_data );
1603
+
1604
+ if ( 'normal' == TM_EPO()->tm_epo_hide_options_in_cart && 'advanced' != TM_EPO()->tm_epo_cart_field_display && ! empty( $cart_item['tmcartepo'] ) ) {
1605
+ $cart_item['quantity'] = 1;
1606
+ $cart_item['data'] = wc_get_product( $variation_id ? $variation_id : $product_id );
1607
+ $cart_item['tm_cart_item_key'] = '';
1608
+ $item_data = TM_EPO()->get_item_data_array( array(), $cart_item );
1609
+
1610
+ foreach ( $item_data as $key => $data ) {
1611
+ // Set hidden to true to not display meta on cart.
1612
+ if ( ! empty( $data['hidden'] ) ) {
1613
+ unset( $item_data[ $key ] );
1614
+ continue;
1615
+ }
1616
+ $item_data[ $key ]['key'] = ! empty( $data['key'] ) ? $data['key'] : $data['name'];
1617
+ $item_data[ $key ]['display'] = ! empty( $data['display'] ) ? $data['display'] : $data['value'];
1618
+ }
1619
+
1620
+ return $item_data;
1621
+ }
1622
+ }
1623
+
1624
+ return array();
1625
+ }
1626
+
1627
+ return $meta;
1628
+ }
1629
+
1630
+ add_filter( 'tinvwl_wishlist_item_meta_post', 'tinv_wishlist_metasupport_woocommerce_tm_extra_product_options', 10, 3 );
1631
+ } // End if().
1632
+
1633
+ if ( ! function_exists( 'tinvwl_item_price_woocommerce_tm_extra_product_options' ) ) {
1634
+
1635
+ /**
1636
+ * Modify price for WooCommerce TM Extra Product Options
1637
+ *
1638
+ * @param string $price Returned price.
1639
+ * @param array $wl_product Wishlist Product.
1640
+ * @param \WC_Product $product Woocommerce Product.
1641
+ *
1642
+ * @return string
1643
+ */
1644
+ function tinvwl_item_price_woocommerce_tm_extra_product_options( $price, $wl_product, $product ) {
1645
+ if ( array_key_exists( 'tcaddtocart', (array) @$wl_product['meta'] ) && function_exists( 'TM_EPO_API' ) && function_exists( 'TM_EPO' ) && TM_EPO()->tm_epo_hide_options_in_cart == 'normal' ) {
1646
+ $product_id = $wl_product['product_id'];
1647
+ $has_epo = TM_EPO_API()->has_options( $product_id );
1648
+ if ( TM_EPO_API()->is_valid_options( $has_epo ) ) {
1649
+ $cart_item = TM_EPO()->add_cart_item_data_helper( array(), $product_id, $wl_product['meta'] );
1650
+ $cart_item['quantity'] = 1;
1651
+ $cart_item['data'] = $product;
1652
+
1653
+ $product_price = apply_filters( 'wc_epo_add_cart_item_original_price', $cart_item['data']->get_price(), $cart_item );
1654
+ if ( ! empty( $cart_item['tmcartepo'] ) ) {
1655
+ $to_currency = tc_get_woocommerce_currency();
1656
+ foreach ( $cart_item['tmcartepo'] as $value ) {
1657
+ if ( array_key_exists( $to_currency, $value['price_per_currency'] ) ) {
1658
+ $value = floatval( $value['price_per_currency'][ $to_currency ] );
1659
+ $product_price += $value;
1660
+ }
1661
+ }
1662
+ }
1663
+
1664
+ $price = apply_filters( 'wc_tm_epo_ac_product_price', apply_filters( 'woocommerce_cart_item_price', TM_EPO()->get_price_for_cart( $product_price, $cart_item, '' ), $cart_item, '' ), '', $cart_item, $product, $product_id );
1665
+ }
1666
+ }
1667
+
1668
+ return $price;
1669
+ }
1670
+
1671
+ add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_tm_extra_product_options', 10, 3 );
1672
+ } // End if().
1673
+
1674
+ if ( ! function_exists( 'TII18n' ) ) {
1675
+
1676
+ /**
1677
+ * Return TI Yoasti 18n module class
1678
+ *
1679
+ * @return \TInvWL_Includes_API_Yoasti18n
1680
+ */
1681
+ function TII18n() { // @codingStandardsIgnoreLine WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
1682
+ return TInvWL_Includes_API_Yoasti18n::instance();
1683
+ }
1684
+ }
1685
+
1686
+ // Create a helper function for easy SDK access.
1687
+ if ( ! function_exists( 'tinvwl_fs' ) ) {
1688
+
1689
+ /**
1690
+ * Freemius
1691
+ *
1692
+ * @return array
1693
+ */
1694
+ function tinvwl_fs() {
1695
+ global $tinvwl_fs;
1696
+
1697
+ if ( ! isset( $tinvwl_fs ) ) {
1698
+ // Include Freemius SDK.
1699
+ require_once dirname( __FILE__ ) . '/freemius/start.php';
1700
+
1701
+ $tinvwl_fs = fs_dynamic_init( array(
1702
+ 'id' => '839',
1703
+ 'slug' => 'ti-woocommerce-wishlist',
1704
+ 'type' => 'plugin',
1705
+ 'public_key' => 'pk_1944d351ab27040c8f65c72d1e7e7',
1706
+ 'is_premium' => false,
1707
+ 'has_premium_version' => false,
1708
+ 'has_addons' => false,
1709
+ 'has_paid_plans' => false,
1710
+ 'menu' => array(
1711
+ 'slug' => 'tinvwl',
1712
+ 'first-path' => 'admin.php?page=tinvwl' . ( get_option( TINVWL_PREFIX . '_wizard' ) ? '' : '-wizard' ),
1713
+ 'account' => false,
1714
+ 'support' => false,
1715
+ ),
1716
+ ) );
1717
+ }
1718
+
1719
+ return $tinvwl_fs;
1720
+ }
1721
+
1722
+ // Init Freemius.
1723
+ tinvwl_fs();
1724
+
1725
+ if ( ! function_exists( 'tinvwl_fs_custom_connect_message_on_update' ) ) {
1726
+ function tinvwl_fs_custom_connect_message_on_update(
1727
+ $message, $user_first_name, $plugin_title, $user_login, $site_link,
1728
+ $freemius_link
1729
+ ) {
1730
+ return sprintf(
1731
+ __fs( 'hey-x' ) . '<br>' .
1732
+ __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'ti-woocommerce-wishlist' ), $user_first_name, '<b>' . $plugin_title . '</b>', '<b>' . $user_login . '</b>', $site_link, $freemius_link
1733
+ );
1734
+ }
1735
+
1736
+ tinvwl_fs()->add_filter( 'connect_message_on_update', 'tinvwl_fs_custom_connect_message_on_update', 10, 6 );
1737
+ }
1738
+
1739
+ if ( ! function_exists( 'tinvwl_fs_custom_connect_message' ) ) {
1740
+ function tinvwl_fs_custom_connect_message(
1741
+ $message, $user_first_name, $plugin_title, $user_login, $site_link,
1742
+ $freemius_link
1743
+ ) {
1744
+ return sprintf(
1745
+ __fs( 'hey-x' ) . '<br>' .
1746
+ __( 'Allow %6$s to collect some usage data with %5$s to make the plugin even more awesome. If you skip this, that\'s okay! %2$s will still work just fine.', 'ti-woocommerce-wishlist' ), $user_first_name, '<b>' . __( 'WooCommerce Wishlist Plugin', 'ti-woocommerce-wishlist' ) . '</b>', '<b>' . $user_login . '</b>', $site_link, $freemius_link, '<b>' . __( 'TemplateInvaders', 'ti-woocommerce-wishlist' ) . '</b>'
1747
+ );
1748
+ }
1749
+
1750
+ tinvwl_fs()->add_filter( 'connect_message', 'tinvwl_fs_custom_connect_message', 10, 6 );
1751
+ }
1752
+
1753
+ tinvwl_fs()->add_action( 'after_uninstall', 'uninstall_tinv_wishlist' );
1754
+ } // End if().
1755
+
1756
+ // WP Multilang string translations.
1757
+ if ( function_exists( 'wpm_translate_string' ) ) {
1758
+
1759
+ add_filter( 'tinvwl-general-default_title', 'wpm_translate_string' );
1760
+ add_filter( 'tinvwl-general-text_browse', 'wpm_translate_string' );
1761
+ add_filter( 'tinvwl-general-text_added_to', 'wpm_translate_string' );
1762
+ add_filter( 'tinvwl-general-text_already_in', 'wpm_translate_string' );
1763
+ add_filter( 'tinvwl-general-text_removed_from', 'wpm_translate_string' );
1764
+
1765
+ add_filter( 'tinvwl-add_to_wishlist_catalog-text', 'wpm_translate_string' );
1766
+ add_filter( 'tinvwl-add_to_wishlist_catalog-text_remove', 'wpm_translate_string' );
1767
+
1768
+ add_filter( 'tinvwl-product_table-text_add_to_cart', 'wpm_translate_string' );
1769
+
1770
+ add_filter( 'tinvwl-table-text_add_select_to_cart', 'wpm_translate_string' );
1771
+ add_filter( 'tinvwl-table-text_add_all_to_cart', 'wpm_translate_string' );
1772
+
1773
+ add_filter( 'tinvwl-social-share_on', 'wpm_translate_string' );
1774
+
1775
+ add_filter( 'tinvwl-topline-text', 'wpm_translate_string' );
1776
+
1777
+ } // End if().
tinv-wishlists-function.php CHANGED
@@ -1,1010 +1,1010 @@
1
- <?php
2
- /**
3
- * Basic function for plugin
4
- *
5
- * @since 1.0.0
6
- * @package TInvWishlist
7
- */
8
-
9
- // If this file is called directly, abort.
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- die;
12
- }
13
-
14
- if ( function_exists( 'spl_autoload_register' ) ) {
15
-
16
- /**
17
- * Autoloader class. If no function spl_autoload_register, then all the files will be required
18
- *
19
- * @param string $_class Required class name.
20
- *
21
- * @return boolean
22
- */
23
- function autoload_tinv_wishlist( $_class ) {
24
- $preffix = 'TInvWL';
25
- $ext = '.php';
26
- $class = explode( '_', $_class );
27
- $object = array_shift( $class );
28
- if ( $preffix !== $object ) {
29
- return false;
30
- }
31
- if ( empty( $class ) ) {
32
- $class = array( $preffix );
33
- }
34
- $basicclass = $class;
35
- array_unshift( $class, 'includes' );
36
- $classs = array(
37
- TINVWL_PATH . strtolower( implode( DIRECTORY_SEPARATOR, $basicclass ) ),
38
- TINVWL_PATH . strtolower( implode( DIRECTORY_SEPARATOR, $class ) ),
39
- );
40
- foreach ( $classs as $class ) {
41
- foreach ( array( '.class', '.helper' ) as $suffix ) {
42
- $filename = $class . $suffix . $ext;
43
- if ( file_exists( $filename ) ) {
44
- require_once $filename;
45
-
46
- return true;
47
- }
48
- }
49
- }
50
-
51
- return false;
52
- }
53
-
54
- spl_autoload_register( 'autoload_tinv_wishlist' );
55
- } // End if().
56
-
57
- if ( ! function_exists( 'tinv_array_merge' ) ) {
58
-
59
- /**
60
- * Function to merge arrays with replacement options
61
- *
62
- * @param array $array1 Array.
63
- * @param array $_ Array.
64
- *
65
- * @return array
66
- */
67
- function tinv_array_merge( $array1, $_ = null ) {
68
- if ( ! is_array( $array1 ) ) {
69
- return $array1;
70
- }
71
- $args = func_get_args();
72
- array_shift( $args );
73
- foreach ( $args as $array2 ) {
74
- if ( is_array( $array2 ) ) {
75
- foreach ( $array2 as $key => $value ) {
76
- $array1[ $key ] = $value;
77
- }
78
- }
79
- }
80
-
81
- return $array1;
82
- }
83
- }
84
-
85
- if ( ! function_exists( 'tinv_get_option_defaults' ) ) {
86
-
87
- /**
88
- * Extract default options from settings class
89
- *
90
- * @param string $category Name category settings.
91
- *
92
- * @return array
93
- */
94
- function tinv_get_option_defaults( $category ) {
95
- $dir = TINVWL_PATH . 'admin/settings/';
96
- if ( ! file_exists( $dir ) || ! is_dir( $dir ) ) {
97
- return array();
98
- }
99
- $files = scandir( $dir );
100
- foreach ( $files as $key => $value ) {
101
- if ( preg_match( '/\.class\.php$/i', $value ) ) {
102
- $files[ $key ] = preg_replace( '/\.class\.php$/i', '', $value );
103
- } else {
104
- unset( $files[ $key ] );
105
- }
106
- }
107
- $defaults = array();
108
- foreach ( $files as $file ) {
109
- $class = 'TInvWL_Admin_Settings_' . ucfirst( $file );
110
- $class = new $class( '', '' );
111
- $class_methods = get_class_methods( $class );
112
- foreach ( $class_methods as $method ) {
113
- if ( preg_match( '/_data$/i', $method ) ) {
114
- $settings = $class->get_defaults( $class->$method() );
115
- $defaults = tinv_array_merge( $defaults, $settings );
116
- }
117
- }
118
- }
119
- if ( 'all' === $category ) {
120
- return $defaults;
121
- }
122
- if ( array_key_exists( $category, $defaults ) ) {
123
- return $defaults[ $category ];
124
- }
125
-
126
- return array();
127
- }
128
- } // End if().
129
-
130
- if ( ! function_exists( 'tinv_get_option' ) ) {
131
-
132
- /**
133
- * Extract options from database or default array settings.
134
- *
135
- * @param string $category Name category settings.
136
- * @param string $option Name paremetr. If is empty string, then function return array category settings.
137
- *
138
- * @return mixed
139
- */
140
- function tinv_get_option( $category, $option = '' ) {
141
- $prefix = TINVWL_PREFIX . '-';
142
- $values = get_option( $prefix . $category, array() );
143
- if ( empty( $values ) ) {
144
- $values = tinv_get_option_defaults( $category );
145
- }
146
- if ( empty( $option ) ) {
147
- return $values;
148
- } else {
149
- if ( array_key_exists( $option, (array) $values ) ) {
150
- return $values[ $option ];
151
- } else {
152
- $values = tinv_get_option_defaults( $category );
153
- if ( array_key_exists( $option, (array) $values ) ) {
154
- return $values[ $option ];
155
- }
156
- }
157
- }
158
-
159
- return null;
160
- }
161
- }
162
-
163
- if ( ! function_exists( 'tinv_get_option_admin' ) ) {
164
-
165
- /**
166
- * Extract options from database or default array settings.
167
- *
168
- * @param string $category Name category settings.
169
- * @param string $option Name paremetr. If is empty string, then function return array category settings.
170
- *
171
- * @return mixed
172
- */
173
- function tinv_get_option_admin( $category, $option = '' ) {
174
- $prefix = TINVWL_PREFIX . '-';
175
- $values = get_option( $prefix . $category, array() );
176
- if ( empty( $values ) ) {
177
- $values = array();
178
- }
179
- if ( empty( $option ) ) {
180
- return $values;
181
- } elseif ( array_key_exists( $option, $values ) ) {
182
- return $values[ $option ];
183
- }
184
-
185
- return null;
186
- }
187
- }
188
-
189
- if ( ! function_exists( 'tinv_style' ) ) {
190
-
191
- /**
192
- * Get style for custom style
193
- *
194
- * @param string $selector Selector style.
195
- * @param string $element Attribute name.
196
- *
197
- * @return string
198
- */
199
- function tinv_style( $selector = '', $element = '' ) {
200
- $key = md5( $selector . '||' . $element );
201
- $values = get_option( TINVWL_PREFIX . '-style_options', array() );
202
- if ( empty( $values ) ) {
203
- return '';
204
- }
205
- if ( array_key_exists( $key, $values ) ) {
206
- return $values[ $key ];
207
- }
208
-
209
- return '';
210
- }
211
- }
212
-
213
- if ( ! function_exists( 'tinv_update_option' ) ) {
214
-
215
- /**
216
- * Update options in database.
217
- *
218
- * @param string $category Name category settings.
219
- * @param string $option Name paremetr. If is empty string, then function update array category settings.
220
- * @param mixed $value Value option.
221
- *
222
- * @return boolean
223
- */
224
- function tinv_update_option( $category, $option = '', $value = false ) {
225
- $prefix = TINVWL_PREFIX . '-';
226
- if ( empty( $option ) ) {
227
- if ( is_array( $value ) ) {
228
- update_option( $prefix . $category, $value );
229
-
230
- return true;
231
- }
232
- } else {
233
- $values = get_option( $prefix . $category, array() );
234
-
235
- $values[ $option ] = $value;
236
- update_option( $prefix . $category, $values );
237
-
238
- return true;
239
- }
240
-
241
- return false;
242
- }
243
- }
244
-
245
- if ( ! function_exists( 'tinv_wishlist_template' ) ) {
246
-
247
- /**
248
- * The function overwrites the method output templates woocommerce
249
- *
250
- * @param string $template_name Name file template.
251
- * @param array $args Array variable in template.
252
- * @param string $template_path Customization path.
253
- */
254
- function tinv_wishlist_template( $template_name, $args = array(), $template_path = '' ) {
255
- if ( function_exists( 'wc_get_template' ) ) {
256
- wc_get_template( $template_name, $args, $template_path );
257
- } else {
258
- woocommerce_get_template( $template_name, $args, $template_path );
259
- }
260
- }
261
- }
262
-
263
- if ( ! function_exists( 'tinv_wishlist_locate_template' ) ) {
264
-
265
- /**
266
- * Overwrites path for email and other template
267
- *
268
- * @param string $template_name Requered Template file.
269
- * @param string $template_path Template path.
270
- * @param string $default_path Template default path.
271
- *
272
- * @return string
273
- */
274
- function tinv_wishlist_locate_template( $template_name, $template_path = '', $default_path = '' ) {
275
- if ( ! $template_path ) {
276
- $template_path = WC()->template_path();
277
- }
278
-
279
- if ( ! $default_path ) {
280
- $default_path = TINVWL_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
281
- }
282
-
283
- // Look within passed path within the theme - this is priority.
284
- $template = locate_template( array(
285
- trailingslashit( $template_path ) . $template_name,
286
- $template_name,
287
- ) );
288
-
289
- // Get default template.
290
- if ( ! $template && file_exists( $default_path . $template_name ) ) {
291
- $template = $default_path . $template_name;
292
- }
293
-
294
- // Return what we found.
295
- return apply_filters( 'tinvwl_locate_template', $template, $template_name, $template_path );
296
- }
297
- } // End if().
298
-
299
- if ( ! function_exists( 'tinv_wishlist_template_html' ) ) {
300
-
301
- /**
302
- * The function overwrites the method return templates woocommerce
303
- *
304
- * @param string $template_name Name file template.
305
- * @param array $args Array variable in template.
306
- * @param string $template_path Customization path.
307
- *
308
- * @return string
309
- */
310
- function tinv_wishlist_template_html( $template_name, $args = array(), $template_path = '' ) {
311
- ob_start();
312
- tinv_wishlist_template( $template_name, $args, $template_path );
313
-
314
- return ob_get_clean();
315
- }
316
- }
317
-
318
- if ( ! function_exists( 'tinv_wishlist_get_item_data' ) ) {
319
-
320
- /**
321
- * Extract meta attributes for product
322
- *
323
- * @param object $product Object selected product.
324
- * @param array $wl_product Wishlist selected product.
325
- * @param boolean $flat Return text or template.
326
- *
327
- * @return string
328
- */
329
- function tinv_wishlist_get_item_data( $product, $wl_product = array(), $flat = false ) {
330
- $item_data = array();
331
- $variation_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 );
332
- $variation_data = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_data : ( $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : array() );
333
- if ( ! empty( $variation_id ) && is_array( $variation_data ) ) {
334
- foreach ( $variation_data as $name => $value ) {
335
- if ( '' === $value ) {
336
- // Could be any value that saved to a custom meta.
337
- if ( array_key_exists( 'meta', $wl_product ) && array_key_exists( $name, $wl_product['meta'] ) ) {
338
- $value = $wl_product['meta'][ $name ];
339
- } else {
340
- continue;
341
- }
342
- }
343
-
344
- $taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $name ) ) );
345
-
346
- // If this is a term slug, get the term's nice name.
347
- if ( taxonomy_exists( $taxonomy ) ) {
348
- $term = get_term_by( 'slug', $value, $taxonomy ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.get_term_by
349
- if ( ! is_wp_error( $term ) && $term && $term->name ) {
350
- $value = $term->name;
351
- }
352
- $label = wc_attribute_label( $taxonomy );
353
-
354
- // If this is a custom option slug, get the options name.
355
- } else {
356
- $value = apply_filters( 'woocommerce_variation_option_name', $value );
357
- $product_attributes = $product->get_attributes();
358
- $_name = str_replace( 'attribute_', '', $name );
359
- if ( isset( $product_attributes[ $_name ] ) ) {
360
- $_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_attributes[ $_name ]['name'] : $_name;
361
- $label = wc_attribute_label( $_name, $product );
362
- } else {
363
- $label = $name;
364
- }
365
- }
366
- if ( '' === $value ) {
367
- continue;
368
- }
369
- $item_data[] = array(
370
- 'key' => $label,
371
- 'value' => $value,
372
- );
373
- } // End foreach().
374
- } // End if().
375
-
376
- // Filter item data to allow 3rd parties to add more to the array.
377
- $item_data = apply_filters( 'tinv_wishlist_get_item_data', $item_data, $product );
378
-
379
- // Format item data ready to display.
380
- foreach ( $item_data as $key => $data ) {
381
- // Set hidden to true to not display meta on cart.
382
- if ( ! empty( $data['hidden'] ) ) {
383
- unset( $item_data[ $key ] );
384
- continue;
385
- }
386
- $item_data[ $key ]['key'] = ! empty( $data['key'] ) ? $data['key'] : $data['name'];
387
- $item_data[ $key ]['display'] = ! empty( $data['display'] ) ? $data['display'] : $data['value'];
388
- }
389
-
390
- // Output flat or in list format.
391
- if ( 0 < count( $item_data ) ) {
392
- ob_start();
393
- if ( $flat ) {
394
- foreach ( $item_data as $data ) {
395
- echo esc_html( $data['key'] ) . ': ' . wp_kses_post( $data['display'] ) . '<br>';
396
- }
397
- } else {
398
- tinv_wishlist_template( 'ti-wishlist-item-data.php', array( 'item_data' => $item_data ) );
399
- }
400
-
401
- return ob_get_clean();
402
- }
403
-
404
- return '';
405
- }
406
- } // End if().
407
-
408
- if ( ! function_exists( 'tinv_wishlist_get' ) ) {
409
-
410
- /**
411
- * Return Wishlist by id or share key
412
- *
413
- * @param mixed $id Integer wishlist ID, or Share Key wishlist.
414
- * @param boolean $toend Switches to the extract the default or guest wishlist.
415
- *
416
- * @return array
417
- */
418
- function tinv_wishlist_get( $id = '', $toend = true ) {
419
- $wl = new TInvWL_Wishlist();
420
- $wishlist = null;
421
- if ( empty( $id ) ) {
422
- $id = get_query_var( 'tinvwlID', null );
423
- }
424
-
425
- if ( ! empty( $id ) ) {
426
- if ( is_integer( $id ) ) {
427
- $wishlist = $wl->get_by_id( $id );
428
- }
429
- if ( empty( $wishlist ) ) {
430
- $wishlist = $wl->get_by_share_key( $id );
431
- }
432
-
433
- if ( is_array( $wishlist ) ) {
434
- $wishlist['is_owner'] = false;
435
- if ( is_user_logged_in() ) {
436
- $wishlist['is_owner'] = get_current_user_id() == $wishlist['author']; // WPCS: loose comparison ok.
437
- } else {
438
- $wishlist['is_owner'] = $wl->get_sharekey() === $wishlist['share_key']; // WPCS: loose comparison ok.
439
- }
440
- }
441
- } elseif ( is_user_logged_in() && $toend ) {
442
- $wishlist = $wl->add_user_default();
443
-
444
- $wishlist['is_owner'] = true;
445
- } elseif ( $toend ) {
446
- $wishlist = $wl->get_by_sharekey_default();
447
- if ( ! empty( $wishlist ) ) {
448
- $wishlist = array_shift( $wishlist );
449
- $wishlist['is_owner'] = $wl->get_sharekey() === $wishlist['share_key'];
450
- }
451
- }
452
-
453
- return $wishlist;
454
- }
455
- } // End if().
456
-
457
- if ( ! function_exists( 'tinv_url_wishlist_default' ) ) {
458
-
459
- /**
460
- * Return the default wishlist url
461
- *
462
- * @return string
463
- */
464
- function tinv_url_wishlist_default() {
465
- $page = apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true ); // @codingStandardsIgnoreLine WordPress.Variables.GlobalVariables.OverrideProhibited
466
- if ( empty( $page ) ) {
467
- return '';
468
- }
469
- $link = get_permalink( $page );
470
-
471
- return $link;
472
- }
473
- }
474
-
475
- if ( ! function_exists( 'tinv_url_wishlist_by_key' ) ) {
476
-
477
- /**
478
- * Return the wishlist url by share key
479
- *
480
- * @param string $share_key Share Key wishlist.
481
- * @param integer $paged Page.
482
- *
483
- * @return string
484
- */
485
- function tinv_url_wishlist_by_key( $share_key, $paged = 1 ) {
486
- $paged = absint( $paged );
487
- $paged = 1 < $paged ? $paged : 1;
488
- $link = tinv_url_wishlist_default();
489
- if ( empty( $link ) || empty( $share_key ) ) {
490
- return $link;
491
- }
492
-
493
- if ( get_option( 'permalink_structure' ) ) {
494
- $suffix = '';
495
- if ( preg_match( '/([^\?]+)\?*?(.*)/i', $link, $_link ) ) {
496
- $link = $_link[1];
497
- $suffix = $_link[2];
498
- }
499
- if ( ! preg_match( '/\/$/', $link ) ) {
500
- $link .= '/';
501
- }
502
- $link .= $share_key . '/' . $suffix;
503
- } else {
504
- $link = add_query_arg( 'tinvwlID', $share_key, $link );
505
- }
506
-
507
- if ( 1 < $paged ) {
508
- $link = add_query_arg( 'paged', $paged, $link );
509
- }
510
-
511
- return $link;
512
- }
513
- } // End if().
514
-
515
- if ( ! function_exists( 'tinv_url_wishlist' ) ) {
516
-
517
- /**
518
- * Return the wishlist url by id or share key
519
- *
520
- * @param mixed $id Integer wishlist ID, or Share Key wishlist.
521
- * @param integer $paged Page.
522
- * @param boolean $full Return full url or shroted url for logged in user.
523
- *
524
- * @return string
525
- */
526
- function tinv_url_wishlist( $id = '', $paged = 1, $full = true ) {
527
- $share_key = $id;
528
- if ( ! ( is_string( $id ) && preg_match( '/^[A-Fa-f0-9]{6}$/', $id ) ) ) {
529
- $wishlist = tinv_wishlist_get( $id, false );
530
- $share_key = $wishlist['share_key'];
531
- }
532
-
533
- return tinv_url_wishlist_by_key( $share_key, $paged );
534
- }
535
- }
536
-
537
- if ( ! function_exists( 'tinv_wishlist_status' ) ) {
538
-
539
- /**
540
- * Check status free or premium plugin and disable free
541
- *
542
- * @global string $status
543
- * @global string $page
544
- * @global string $s
545
- *
546
- * @param string $transient Plugin transient name.
547
- *
548
- * @return string
549
- */
550
- function tinv_wishlist_status( $transient ) {
551
- if ( TINVWL_LOAD_FREE === $transient ) {
552
- TInvWL_PluginExtend::deactivate_self( TINVWL_LOAD_FREE );
553
-
554
- return 'plugins.php';
555
- }
556
- if ( TINVWL_LOAD_PREMIUM === $transient ) {
557
- if ( is_plugin_active( TINVWL_LOAD_FREE ) ) {
558
- TInvWL_PluginExtend::deactivate_self( TINVWL_LOAD_FREE );
559
- if ( ! function_exists( 'wp_create_nonce' ) ) {
560
- return 'plugins.php';
561
- }
562
-
563
- global $status, $page, $s;
564
- $redirect = 'plugins.php?';
565
- $redirect .= http_build_query( array(
566
- 'action' => 'activate',
567
- 'plugin' => $transient,
568
- 'plugin_status' => $status,
569
- 'paged' => $page,
570
- 's' => $s,
571
- ) );
572
- $redirect = esc_url_raw( add_query_arg( '_wpnonce', wp_create_nonce( 'activate-plugin_' . $transient ), $redirect ) );
573
-
574
- return $redirect;
575
- }
576
- }
577
-
578
- return false;
579
- }
580
- } // End if().
581
-
582
- if ( ! function_exists( 'tinvwl_body_classes' ) ) {
583
-
584
- /**
585
- * Add custom class
586
- *
587
- * @param array $classes Current classes.
588
- *
589
- * @return array
590
- */
591
- function tinvwl_body_classes( $classes ) {
592
- if ( tinv_get_option( 'style', 'customstyle' ) ) {
593
- $classes[] = 'tinvwl-theme-style';
594
- } else {
595
- $classes[] = 'tinvwl-custom-style';
596
- }
597
-
598
- return $classes;
599
- }
600
-
601
- add_filter( 'body_class', 'tinvwl_body_classes' );
602
- }
603
-
604
- if ( ! function_exists( 'tinvwl_shortcode_addtowishlist' ) ) {
605
-
606
- /**
607
- * Shortcode Add To Wishlist
608
- *
609
- * @param array $atts Array parameter from shortcode.
610
- *
611
- * @return string
612
- */
613
- function tinvwl_shortcode_addtowishlist( $atts = array() ) {
614
- $class = TInvWL_Public_AddToWishlist::instance();
615
-
616
- return $class->shortcode( $atts );
617
- }
618
-
619
- add_shortcode( 'ti_wishlists_addtowishlist', 'tinvwl_shortcode_addtowishlist' );
620
- }
621
-
622
- if ( ! function_exists( 'tinvwl_shortcode_view' ) ) {
623
-
624
- /**
625
- * Shortcode view Wishlist
626
- *
627
- * @param array $atts Array parameter from shortcode.
628
- *
629
- * @return string
630
- */
631
- function tinvwl_shortcode_view( $atts = array() ) {
632
- $class = TInvWL_Public_Wishlist_View::instance();
633
-
634
- return $class->shortcode( $atts );
635
- }
636
-
637
- add_shortcode( 'ti_wishlistsview', 'tinvwl_shortcode_view' );
638
- }
639
-
640
- if ( ! function_exists( 'tinvwl_shortcode_products_counter' ) ) {
641
-
642
- /**
643
- * Shortcode view Wishlist
644
- *
645
- * @param array $atts Array parameter from shortcode.
646
- *
647
- * @return string
648
- */
649
- function tinvwl_shortcode_products_counter( $atts = array() ) {
650
- $class = TInvWL_Public_TopWishlist::instance();
651
-
652
- return $class->shortcode( $atts );
653
- }
654
-
655
- add_shortcode( 'ti_wishlist_products_counter', 'tinvwl_shortcode_products_counter' );
656
- }
657
-
658
- if ( ! function_exists( 'tinvwl_view_addto_html' ) ) {
659
-
660
- /**
661
- * Show button Add to Wishlsit
662
- */
663
- function tinvwl_view_addto_html() {
664
- $class = TInvWL_Public_AddToWishlist::instance();
665
- $class->htmloutput();
666
- }
667
- }
668
-
669
- if ( ! function_exists( 'tinvwl_view_addto_htmlout' ) ) {
670
-
671
- /**
672
- * Show button Add to Wishlsit, if product is not purchasable
673
- */
674
- function tinvwl_view_addto_htmlout() {
675
- $class = TInvWL_Public_AddToWishlist::instance();
676
- $class->htmloutput_out();
677
- }
678
- }
679
-
680
- if ( ! function_exists( 'tinvwl_view_addto_htmlloop' ) ) {
681
-
682
- /**
683
- * Show button Add to Wishlsit, in loop
684
- */
685
- function tinvwl_view_addto_htmlloop() {
686
- $class = TInvWL_Public_AddToWishlist::instance();
687
- $class->htmloutput_loop();
688
- }
689
- }
690
-
691
- if ( ! function_exists( 'tinvwl_clean_url' ) ) {
692
-
693
- /**
694
- * Clear esc_url to original
695
- *
696
- * @param string $good_protocol_url Cleared URL.
697
- * @param string $original_url Original URL.
698
- *
699
- * @return string
700
- */
701
- function tinvwl_clean_url( $good_protocol_url, $original_url ) {
702
- return $original_url;
703
- }
704
- }
705
-
706
- if ( ! function_exists( 'tinvwl_add_to_cart_need_redirect' ) ) {
707
-
708
- /**
709
- * Check if the product is third-party, or has another link added to the cart then redirect to the product page.
710
- *
711
- * @param boolean $redirect Default value to redirect.
712
- * @param \WC_Product $product Product data.
713
- * @param string $redirect_url Current url for redirect.
714
- *
715
- * @return boolean
716
- */
717
- function tinvwl_add_to_cart_need_redirect( $redirect, $product, $redirect_url ) {
718
- if ( $redirect ) {
719
- return true;
720
- }
721
- if ( 'external' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
722
- return true;
723
- }
724
-
725
- $need_url_data = array_filter( array_merge( array(
726
- 'variation_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 ) ),
727
- 'add-to-cart' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->get_id() : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ),
728
- ), array_map( 'urlencode', ( version_compare( WC_VERSION, '3.0.0', '<' ) ? ( is_array( $product->variation_data ) ? $product->variation_data : array() ) : array() ) ) ) );
729
- $need_url = apply_filters( 'woocommerce_product_add_to_cart_url', remove_query_arg( 'added-to-cart', add_query_arg( $need_url_data ) ), $product );
730
- $need_url_full = apply_filters( 'woocommerce_product_add_to_cart_url', remove_query_arg( 'added-to-cart', add_query_arg( $need_url_data, $product->get_permalink() ) ), $product );
731
- add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
732
- $_redirect_url = apply_filters( 'tinvwl_product_add_to_cart_redirect_url', $product->add_to_cart_url(), $product );
733
- remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
734
- if ( $_redirect_url !== $need_url && $_redirect_url !== $need_url_full ) {
735
- return true;
736
- }
737
-
738
- return $redirect;
739
- }
740
-
741
- add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'tinvwl_add_to_cart_need_redirect', 10, 3 );
742
- } // End if().
743
-
744
- if ( ! function_exists( 'tinvwl_meta_validate_cart_add' ) ) {
745
-
746
- /**
747
- * Checks the ability to add a product
748
- *
749
- * @param boolean $redirect Default value to redirect.
750
- * @param \WC_Product $product Product data.
751
- * @param string $redirect_url Current url for redirect.
752
- * @param array $wl_product Wishlist Product.
753
- *
754
- * @return boolean
755
- */
756
- function tinvwl_meta_validate_cart_add( $redirect, $product, $redirect_url, $wl_product ) {
757
- if ( $redirect && array_key_exists( 'meta', $wl_product ) && ! empty( $wl_product['meta'] ) ) {
758
-
759
- TInvWL_Public_Cart::prepare_post( $wl_product );
760
-
761
- $wl_product = apply_filters( 'tinvwl_addproduct_tocart', $wl_product );
762
- $product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $wl_product['product_id'] ) );
763
- $quantity = empty( $wl_quantity ) ? 1 : wc_stock_amount( $wl_quantity );
764
- $variation_id = $wl_product['variation_id'];
765
- $variations = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_data : ( $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : array() ) );
766
- $passed_validation = $product->is_purchasable() && ( $product->is_in_stock() || $product->backorders_allowed() ) && 'external' !== ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() );
767
- ob_start();
768
- wc_clear_notices();
769
- $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', $passed_validation, $product_id, $quantity, $variation_id, $variations );
770
- $wc_errors = wc_get_notices( 'error' );
771
- $wc_output = ob_get_clean();
772
- if ( $passed_validation && empty( $wc_errors ) && empty( $wc_output ) ) {
773
- $redirect = false;
774
- }
775
-
776
- TInvWL_Public_Cart::unprepare_post();
777
- }
778
-
779
- return $redirect;
780
- }
781
-
782
- add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'tinvwl_meta_validate_cart_add', 90, 4 );
783
- } // End if().
784
-
785
- if ( ! function_exists( 'tinv_wishlist_print_meta' ) ) {
786
-
787
- /**
788
- * Print meta data for wishlist form
789
- *
790
- * @param array $meta Meta Array.
791
- * @param boolean $flat Return text or template.
792
- *
793
- * @return string
794
- */
795
- function tinv_wishlist_print_meta( $meta = array(), $flat = false ) {
796
- if ( ! is_array( $meta ) ) {
797
- $meta = array();
798
- }
799
- $product_id = $variation_id = 0;
800
- if ( array_key_exists( 'product_id', $meta ) ) {
801
- $product_id = $meta['product_id'];
802
- }
803
- if ( array_key_exists( 'variation_id', $meta ) ) {
804
- $variation_id = $meta['variation_id'];
805
- }
806
- foreach ( array( 'add-to-cart', 'product_id', 'variation_id', 'quantity' ) as $field ) {
807
- if ( array_key_exists( $field, $meta ) ) {
808
- unset( $meta[ $field ] );
809
- }
810
- }
811
- $meta = array_filter( $meta );
812
- if ( empty( $meta ) ) {
813
- return '';
814
- }
815
- $item_data = array();
816
- foreach ( $meta as $key => $value ) {
817
- if ( ! preg_match( '/^\_/', $key ) ) {
818
- $item_data[ $key ] = array(
819
- 'key' => $key,
820
- 'display' => $value,
821
- );
822
- }
823
- }
824
- $item_data = apply_filters( 'tinvwl_wishlist_item_meta_post', $item_data, $product_id, $variation_id );
825
- foreach ( $item_data as $key => $data ) {
826
- if ( is_object( $data['display'] ) || is_array( $data['display'] ) ) {
827
- $item_data[ $key ]['display'] = json_encode( $data['display'] );
828
- }
829
- }
830
- ob_start();
831
- if ( $flat ) {
832
- foreach ( $item_data as $data ) {
833
- echo esc_html( $data['key'] ) . ': ' . wp_kses_post( $data['display'] ) . '<br>';
834
- }
835
- } else {
836
- tinv_wishlist_template( 'ti-wishlist-item-data.php', array( 'item_data' => $item_data ) );
837
- }
838
-
839
- return apply_filters( 'tinvwl_wishlist_item_meta_wishlist', ob_get_clean() );
840
- }
841
- } // End if().
842
-
843
- if ( ! function_exists( 'tinv_wishlistmeta' ) ) {
844
-
845
- /**
846
- * Show new meta data
847
- *
848
- * @param string $meta Print meta.
849
- * @param array $wl_product Wishlist product.
850
- * @param \WC_Product $product Woocommerce product.
851
- *
852
- * @return string
853
- */
854
- function tinv_wishlistmeta( $meta = '', $wl_product, $product ) {
855
- if ( empty( $meta ) ) {
856
- if ( array_key_exists( 'meta', $wl_product ) ) {
857
- $meta = apply_filters( 'tinvwl_wishlist_item_meta_wishlist_output', tinv_wishlist_print_meta( $wl_product['meta'] ), $wl_product, $product );
858
- }
859
- }
860
-
861
- return $meta;
862
- }
863
-
864
- add_filter( 'tinvwl_wishlist_item_meta_data', 'tinv_wishlistmeta', 10, 3 );
865
- }
866
-
867
- if ( ! function_exists( 'tinvwl_add_to_cart_item_meta_post' ) ) {
868
-
869
- /**
870
- * Save post data to cart item
871
- *
872
- * @param array $cart_item_data Array with cart imet information.
873
- * @param string $cart_item_key Cart item key.
874
- *
875
- * @return array
876
- */
877
- function tinvwl_add_to_cart_item_meta_post( $cart_item_data, $cart_item_key ) {
878
- $postdata = $_POST; // @codingStandardsIgnoreLine WordPress.VIP.SuperGlobalInputUsage.AccessDetected
879
-
880
- $postdata = apply_filters( 'tinvwl_product_prepare_meta', $postdata );
881
- if ( array_key_exists( 'variation_id', $postdata ) && ! empty( $postdata['variation_id'] ) ) {
882
- foreach ( $postdata as $key => $field ) {
883
- if ( preg_match( '/^attribute\_/', $key ) ) {
884
- unset( $postdata[ $key ] );
885
- }
886
- }
887
- }
888
- foreach ( array( 'add-to-cart', 'product_id', 'variation_id', 'quantity' ) as $field ) {
889
- if ( array_key_exists( $field, $postdata ) ) {
890
- unset( $postdata[ $field ] );
891
- }
892
- }
893
- $postdata = array_filter( $postdata );
894
- if ( empty( $postdata ) ) {
895
- return $cart_item_data;
896
- }
897
- ksort( $postdata );
898
-
899
- $cart_item_data['tinvwl_formdata'] = $postdata;
900
-
901
- return $cart_item_data;
902
- }
903
-
904
- add_action( 'woocommerce_add_cart_item', 'tinvwl_add_to_cart_item_meta_post', 10, 2 );
905
- } // End if().
906
-
907
- if ( ! function_exists( 'tinvwl_rating_notice_template' ) ) {
908
-
909
- /**
910
- * Show admin notice.
911
- *
912
- * @param string $output String.
913
- * @param string $key Unique notification key.
914
- * @param string $message Text message.
915
- *
916
- * @return string
917
- */
918
- function tinvwl_rating_notice_template( $output, $key, $message ) {
919
-
920
- TInvWL_View::view( 'notice-rating', array(
921
- 'name' => 'rating',
922
- 'message' => $message,
923
- 'key' => $key,
924
- ) );
925
-
926
- return '';
927
- }
928
-
929
- add_filter( 'tinv_notice_rating', 'tinvwl_rating_notice_template', 10, 3 );
930
- }
931
-
932
- if ( ! function_exists( 'tinvwl_rating_notice_hide' ) ) {
933
-
934
- /**
935
- * Action for disable notice
936
- */
937
- function tinvwl_rating_notice_hide() {
938
- $data = filter_input( INPUT_GET, 'ti-redirect' );
939
- if ( $data ) {
940
- wp_redirect( 'https://wordpress.org/support/plugin/ti-woocommerce-wishlist/reviews/#new-post' );
941
- }
942
- }
943
-
944
- add_action( 'tinv_notice_hide_rating', 'tinvwl_rating_notice_hide' );
945
- }
946
-
947
- if ( ! function_exists( 'tinvwl_rating_notice_trigger_30' ) ) {
948
-
949
- /**
950
- * Trigger for reset notice
951
- *
952
- * @return boolean
953
- */
954
- function tinvwl_rating_notice_trigger_30() {
955
- $tw = new TInvWL_Wishlist();
956
- $wishlist = $tw->get( array(
957
- 'count' => 1,
958
- 'order_by' => 'date',
959
- ) );
960
- $wishlist = array_shift( $wishlist );
961
- if ( empty( $wishlist ) ) {
962
- return false;
963
- }
964
- $date = $wishlist['date'];
965
- $date = mysql2date( 'G', $date );
966
- $date = floor( ( time() - $date ) / DAY_IN_SECONDS );
967
- $step = floor( $date / 30 );
968
- if ( 0 >= $step ) {
969
- return false;
970
- }
971
-
972
- return $step;
973
- }
974
- }
975
-
976
- if ( ! function_exists( 'tinvwl_set_utm' ) ) {
977
-
978
- /**
979
- * Set UTM sources.
980
- */
981
- function tinvwl_set_utm() {
982
-
983
- // Set a source.
984
- $source = get_option( TINVWL_PREFIX . '_utm_source' );
985
- if ( ! $source ) {
986
- $source = defined( 'TINVWL_PARTNER' ) ? TINVWL_PARTNER : 'wordpress_org';
987
- update_option( TINVWL_PREFIX . '_utm_source', $source );
988
- }
989
-
990
- define( 'TINVWL_UTM_SOURCE', $source );
991
-
992
- // Set a medium.
993
- $medium = get_option( TINVWL_PREFIX . '_utm_medium' );
994
- if ( ! $medium ) {
995
- $medium = defined( 'TINVWL_PARTNER' ) ? 'integration' : 'organic';
996
- update_option( TINVWL_PREFIX . '_utm_medium', $medium );
997
- }
998
-
999
- define( 'TINVWL_UTM_MEDIUM', $medium );
1000
-
1001
- // Set a campaign.
1002
- $campaign = get_option( TINVWL_PREFIX . '_utm_campaign' );
1003
- if ( ! $campaign ) {
1004
- $campaign = defined( 'TINVWL_PARTNER' ) ? ( defined( 'TINVWL_CAMPAIGN' ) ? TINVWL_CAMPAIGN : TINVWL_PARTNER ) : 'organic';
1005
- update_option( TINVWL_PREFIX . '_utm_campaign', $campaign );
1006
- }
1007
-
1008
- define( 'TINVWL_UTM_CAMPAIGN', $campaign );
1009
- }
1010
- } // End if().
1
+ <?php
2
+ /**
3
+ * Basic function for plugin
4
+ *
5
+ * @since 1.0.0
6
+ * @package TInvWishlist
7
+ */
8
+
9
+ // If this file is called directly, abort.
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ die;
12
+ }
13
+
14
+ if ( function_exists( 'spl_autoload_register' ) ) {
15
+
16
+ /**
17
+ * Autoloader class. If no function spl_autoload_register, then all the files will be required
18
+ *
19
+ * @param string $_class Required class name.
20
+ *
21
+ * @return boolean
22
+ */
23
+ function autoload_tinv_wishlist( $_class ) {
24
+ $preffix = 'TInvWL';
25
+ $ext = '.php';
26
+ $class = explode( '_', $_class );
27
+ $object = array_shift( $class );
28
+ if ( $preffix !== $object ) {
29
+ return false;
30
+ }
31
+ if ( empty( $class ) ) {
32
+ $class = array( $preffix );
33
+ }
34
+ $basicclass = $class;
35
+ array_unshift( $class, 'includes' );
36
+ $classs = array(
37
+ TINVWL_PATH . strtolower( implode( DIRECTORY_SEPARATOR, $basicclass ) ),
38
+ TINVWL_PATH . strtolower( implode( DIRECTORY_SEPARATOR, $class ) ),
39
+ );
40
+ foreach ( $classs as $class ) {
41
+ foreach ( array( '.class', '.helper' ) as $suffix ) {
42
+ $filename = $class . $suffix . $ext;
43
+ if ( file_exists( $filename ) ) {
44
+ require_once $filename;
45
+
46
+ return true;
47
+ }
48
+ }
49
+ }
50
+
51
+ return false;
52
+ }
53
+
54
+ spl_autoload_register( 'autoload_tinv_wishlist' );
55
+ } // End if().
56
+
57
+ if ( ! function_exists( 'tinv_array_merge' ) ) {
58
+
59
+ /**
60
+ * Function to merge arrays with replacement options
61
+ *
62
+ * @param array $array1 Array.
63
+ * @param array $_ Array.
64
+ *
65
+ * @return array
66
+ */
67
+ function tinv_array_merge( $array1, $_ = null ) {
68
+ if ( ! is_array( $array1 ) ) {
69
+ return $array1;
70
+ }
71
+ $args = func_get_args();
72
+ array_shift( $args );
73
+ foreach ( $args as $array2 ) {
74
+ if ( is_array( $array2 ) ) {
75
+ foreach ( $array2 as $key => $value ) {
76
+ $array1[ $key ] = $value;
77
+ }
78
+ }
79
+ }
80
+
81
+ return $array1;
82
+ }
83
+ }
84
+
85
+ if ( ! function_exists( 'tinv_get_option_defaults' ) ) {
86
+
87
+ /**
88
+ * Extract default options from settings class
89
+ *
90
+ * @param string $category Name category settings.
91
+ *
92
+ * @return array
93
+ */
94
+ function tinv_get_option_defaults( $category ) {
95
+ $dir = TINVWL_PATH . 'admin/settings/';
96
+ if ( ! file_exists( $dir ) || ! is_dir( $dir ) ) {
97
+ return array();
98
+ }
99
+ $files = scandir( $dir );
100
+ foreach ( $files as $key => $value ) {
101
+ if ( preg_match( '/\.class\.php$/i', $value ) ) {
102
+ $files[ $key ] = preg_replace( '/\.class\.php$/i', '', $value );
103
+ } else {
104
+ unset( $files[ $key ] );
105
+ }
106
+ }
107
+ $defaults = array();
108
+ foreach ( $files as $file ) {
109
+ $class = 'TInvWL_Admin_Settings_' . ucfirst( $file );
110
+ $class = new $class( '', '' );
111
+ $class_methods = get_class_methods( $class );
112
+ foreach ( $class_methods as $method ) {
113
+ if ( preg_match( '/_data$/i', $method ) ) {
114
+ $settings = $class->get_defaults( $class->$method() );
115
+ $defaults = tinv_array_merge( $defaults, $settings );
116
+ }
117
+ }
118
+ }
119
+ if ( 'all' === $category ) {
120
+ return $defaults;
121
+ }
122
+ if ( array_key_exists( $category, $defaults ) ) {
123
+ return $defaults[ $category ];
124
+ }
125
+
126
+ return array();
127
+ }
128
+ } // End if().
129
+
130
+ if ( ! function_exists( 'tinv_get_option' ) ) {
131
+
132
+ /**
133
+ * Extract options from database or default array settings.
134
+ *
135
+ * @param string $category Name category settings.
136
+ * @param string $option Name paremetr. If is empty string, then function return array category settings.
137
+ *
138
+ * @return mixed
139
+ */
140
+ function tinv_get_option( $category, $option = '' ) {
141
+ $prefix = TINVWL_PREFIX . '-';
142
+ $values = get_option( $prefix . $category, array() );
143
+ if ( empty( $values ) ) {
144
+ $values = tinv_get_option_defaults( $category );
145
+ }
146
+ if ( empty( $option ) ) {
147
+ return $values;
148
+ } else {
149
+ if ( array_key_exists( $option, (array) $values ) ) {
150
+ return $values[ $option ];
151
+ } else {
152
+ $values = tinv_get_option_defaults( $category );
153
+ if ( array_key_exists( $option, (array) $values ) ) {
154
+ return $values[ $option ];
155
+ }
156
+ }
157
+ }
158
+
159
+ return null;
160
+ }
161
+ }
162
+
163
+ if ( ! function_exists( 'tinv_get_option_admin' ) ) {
164
+
165
+ /**
166
+ * Extract options from database or default array settings.
167
+ *
168
+ * @param string $category Name category settings.
169
+ * @param string $option Name paremetr. If is empty string, then function return array category settings.
170
+ *
171
+ * @return mixed
172
+ */
173
+ function tinv_get_option_admin( $category, $option = '' ) {
174
+ $prefix = TINVWL_PREFIX . '-';
175
+ $values = get_option( $prefix . $category, array() );
176
+ if ( empty( $values ) ) {
177
+ $values = array();
178
+ }
179
+ if ( empty( $option ) ) {
180
+ return $values;
181
+ } elseif ( array_key_exists( $option, $values ) ) {
182
+ return $values[ $option ];
183
+ }
184
+
185
+ return null;
186
+ }
187
+ }
188
+
189
+ if ( ! function_exists( 'tinv_style' ) ) {
190
+
191
+ /**
192
+ * Get style for custom style
193
+ *
194
+ * @param string $selector Selector style.
195
+ * @param string $element Attribute name.
196
+ *
197
+ * @return string
198
+ */
199
+ function tinv_style( $selector = '', $element = '' ) {
200
+ $key = md5( $selector . '||' . $element );
201
+ $values = get_option( TINVWL_PREFIX . '-style_options', array() );
202
+ if ( empty( $values ) ) {
203
+ return '';
204
+ }
205
+ if ( array_key_exists( $key, $values ) ) {
206
+ return $values[ $key ];
207
+ }
208
+
209
+ return '';
210
+ }
211
+ }
212
+
213
+ if ( ! function_exists( 'tinv_update_option' ) ) {
214
+
215
+ /**
216
+ * Update options in database.
217
+ *
218
+ * @param string $category Name category settings.
219
+ * @param string $option Name paremetr. If is empty string, then function update array category settings.
220
+ * @param mixed $value Value option.
221
+ *
222
+ * @return boolean
223
+ */
224
+ function tinv_update_option( $category, $option = '', $value = false ) {
225
+ $prefix = TINVWL_PREFIX . '-';
226
+ if ( empty( $option ) ) {
227
+ if ( is_array( $value ) ) {
228
+ update_option( $prefix . $category, $value );
229
+
230
+ return true;
231
+ }
232
+ } else {
233
+ $values = get_option( $prefix . $category, array() );
234
+
235
+ $values[ $option ] = $value;
236
+ update_option( $prefix . $category, $values );
237
+
238
+ return true;
239
+ }
240
+
241
+ return false;
242
+ }
243
+ }
244
+
245
+ if ( ! function_exists( 'tinv_wishlist_template' ) ) {
246
+
247
+ /**
248
+ * The function overwrites the method output templates woocommerce
249
+ *
250
+ * @param string $template_name Name file template.
251
+ * @param array $args Array variable in template.
252
+ * @param string $template_path Customization path.
253
+ */
254
+ function tinv_wishlist_template( $template_name, $args = array(), $template_path = '' ) {
255
+ if ( function_exists( 'wc_get_template' ) ) {
256
+ wc_get_template( $template_name, $args, $template_path );
257
+ } else {
258
+ woocommerce_get_template( $template_name, $args, $template_path );
259
+ }
260
+ }
261
+ }
262
+
263
+ if ( ! function_exists( 'tinv_wishlist_locate_template' ) ) {
264
+
265
+ /**
266
+ * Overwrites path for email and other template
267
+ *
268
+ * @param string $template_name Requered Template file.
269
+ * @param string $template_path Template path.
270
+ * @param string $default_path Template default path.
271
+ *
272
+ * @return string
273
+ */
274
+ function tinv_wishlist_locate_template( $template_name, $template_path = '', $default_path = '' ) {
275
+ if ( ! $template_path ) {
276
+ $template_path = WC()->template_path();
277
+ }
278
+
279
+ if ( ! $default_path ) {
280
+ $default_path = TINVWL_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
281
+ }
282
+
283
+ // Look within passed path within the theme - this is priority.
284
+ $template = locate_template( array(
285
+ trailingslashit( $template_path ) . $template_name,
286
+ $template_name,
287
+ ) );
288
+
289
+ // Get default template.
290
+ if ( ! $template && file_exists( $default_path . $template_name ) ) {
291
+ $template = $default_path . $template_name;
292
+ }
293
+
294
+ // Return what we found.
295
+ return apply_filters( 'tinvwl_locate_template', $template, $template_name, $template_path );
296
+ }
297
+ } // End if().
298
+
299
+ if ( ! function_exists( 'tinv_wishlist_template_html' ) ) {
300
+
301
+ /**
302
+ * The function overwrites the method return templates woocommerce
303
+ *
304
+ * @param string $template_name Name file template.
305
+ * @param array $args Array variable in template.
306
+ * @param string $template_path Customization path.
307
+ *
308
+ * @return string
309
+ */
310
+ function tinv_wishlist_template_html( $template_name, $args = array(), $template_path = '' ) {
311
+ ob_start();
312
+ tinv_wishlist_template( $template_name, $args, $template_path );
313
+
314
+ return ob_get_clean();
315
+ }
316
+ }
317
+
318
+ if ( ! function_exists( 'tinv_wishlist_get_item_data' ) ) {
319
+
320
+ /**
321
+ * Extract meta attributes for product
322
+ *
323
+ * @param object $product Object selected product.
324
+ * @param array $wl_product Wishlist selected product.
325
+ * @param boolean $flat Return text or template.
326
+ *
327
+ * @return string
328
+ */
329
+ function tinv_wishlist_get_item_data( $product, $wl_product = array(), $flat = false ) {
330
+ $item_data = array();
331
+ $variation_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 );
332
+ $variation_data = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_data : ( $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : array() );
333
+ if ( ! empty( $variation_id ) && is_array( $variation_data ) && is_array( $wl_product ) ) {
334
+ foreach ( $variation_data as $name => $value ) {
335
+ if ( '' === $value ) {
336
+ // Could be any value that saved to a custom meta.
337
+ if ( array_key_exists( 'meta', $wl_product ) && array_key_exists( $name, $wl_product['meta'] ) ) {
338
+ $value = $wl_product['meta'][ $name ];
339
+ } else {
340
+ continue;
341
+ }
342
+ }
343
+
344
+ $taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $name ) ) );
345
+
346
+ // If this is a term slug, get the term's nice name.
347
+ if ( taxonomy_exists( $taxonomy ) ) {
348
+ $term = get_term_by( 'slug', $value, $taxonomy ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.get_term_by
349
+ if ( ! is_wp_error( $term ) && $term && $term->name ) {
350
+ $value = $term->name;
351
+ }
352
+ $label = wc_attribute_label( $taxonomy );
353
+
354
+ // If this is a custom option slug, get the options name.
355
+ } else {
356
+ $value = apply_filters( 'woocommerce_variation_option_name', $value );
357
+ $product_attributes = $product->get_attributes();
358
+ $_name = str_replace( 'attribute_', '', $name );
359
+ if ( isset( $product_attributes[ $_name ] ) ) {
360
+ $_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_attributes[ $_name ]['name'] : $_name;
361
+ $label = wc_attribute_label( $_name, $product );
362
+ } else {
363
+ $label = $name;
364
+ }
365
+ }
366
+ if ( '' === $value ) {
367
+ continue;
368
+ }
369
+ $item_data[] = array(
370
+ 'key' => $label,
371
+ 'value' => $value,
372
+ );
373
+ } // End foreach().
374
+ } // End if().
375
+
376
+ // Filter item data to allow 3rd parties to add more to the array.
377
+ $item_data = apply_filters( 'tinv_wishlist_get_item_data', $item_data, $product );
378
+
379
+ // Format item data ready to display.
380
+ foreach ( $item_data as $key => $data ) {
381
+ // Set hidden to true to not display meta on cart.
382
+ if ( ! empty( $data['hidden'] ) ) {
383
+ unset( $item_data[ $key ] );
384
+ continue;
385
+ }
386
+ $item_data[ $key ]['key'] = ! empty( $data['key'] ) ? $data['key'] : $data['name'];
387
+ $item_data[ $key ]['display'] = ! empty( $data['display'] ) ? $data['display'] : $data['value'];
388
+ }
389
+
390
+ // Output flat or in list format.
391
+ if ( 0 < count( $item_data ) ) {
392
+ ob_start();
393
+ if ( $flat ) {
394
+ foreach ( $item_data as $data ) {
395
+ echo esc_html( $data['key'] ) . ': ' . wp_kses_post( $data['display'] ) . '<br>';
396
+ }
397
+ } else {
398
+ tinv_wishlist_template( 'ti-wishlist-item-data.php', array( 'item_data' => $item_data ) );
399
+ }
400
+
401
+ return ob_get_clean();
402
+ }
403
+
404
+ return '';
405
+ }
406
+ } // End if().
407
+
408
+ if ( ! function_exists( 'tinv_wishlist_get' ) ) {
409
+
410
+ /**
411
+ * Return Wishlist by id or share key
412
+ *
413
+ * @param mixed $id Integer wishlist ID, or Share Key wishlist.
414
+ * @param boolean $toend Switches to the extract the default or guest wishlist.
415
+ *
416
+ * @return array
417
+ */
418
+ function tinv_wishlist_get( $id = '', $toend = true ) {
419
+ $wl = new TInvWL_Wishlist();
420
+ $wishlist = null;
421
+ if ( empty( $id ) ) {
422
+ $id = get_query_var( 'tinvwlID', null );
423
+ }
424
+
425
+ if ( ! empty( $id ) ) {
426
+ if ( is_integer( $id ) ) {
427
+ $wishlist = $wl->get_by_id( $id );
428
+ }
429
+ if ( empty( $wishlist ) ) {
430
+ $wishlist = $wl->get_by_share_key( $id );
431
+ }
432
+
433
+ if ( is_array( $wishlist ) ) {
434
+ $wishlist['is_owner'] = false;
435
+ if ( is_user_logged_in() ) {
436
+ $wishlist['is_owner'] = get_current_user_id() == $wishlist['author']; // WPCS: loose comparison ok.
437
+ } else {
438
+ $wishlist['is_owner'] = $wl->get_sharekey() === $wishlist['share_key']; // WPCS: loose comparison ok.
439
+ }
440
+ }
441
+ } elseif ( is_user_logged_in() && $toend ) {
442
+ $wishlist = $wl->add_user_default();
443
+
444
+ $wishlist['is_owner'] = true;
445
+ } elseif ( $toend ) {
446
+ $wishlist = $wl->get_by_sharekey_default();
447
+ if ( ! empty( $wishlist ) ) {
448
+ $wishlist = array_shift( $wishlist );
449
+ $wishlist['is_owner'] = $wl->get_sharekey() === $wishlist['share_key'];
450
+ }
451
+ }
452
+
453
+ return $wishlist;
454
+ }
455
+ } // End if().
456
+
457
+ if ( ! function_exists( 'tinv_url_wishlist_default' ) ) {
458
+
459
+ /**
460
+ * Return the default wishlist url
461
+ *
462
+ * @return string
463
+ */
464
+ function tinv_url_wishlist_default() {
465
+ $page = apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true ); // @codingStandardsIgnoreLine WordPress.Variables.GlobalVariables.OverrideProhibited
466
+ if ( empty( $page ) ) {
467
+ return '';
468
+ }
469
+ $link = get_permalink( $page );
470
+
471
+ return $link;
472
+ }
473
+ }
474
+
475
+ if ( ! function_exists( 'tinv_url_wishlist_by_key' ) ) {
476
+
477
+ /**
478
+ * Return the wishlist url by share key
479
+ *
480
+ * @param string $share_key Share Key wishlist.
481
+ * @param integer $paged Page.
482
+ *
483
+ * @return string
484
+ */
485
+ function tinv_url_wishlist_by_key( $share_key, $paged = 1 ) {
486
+ $paged = absint( $paged );
487
+ $paged = 1 < $paged ? $paged : 1;
488
+ $link = tinv_url_wishlist_default();
489
+ if ( empty( $link ) || empty( $share_key ) ) {
490
+ return $link;
491
+ }
492
+
493
+ if ( get_option( 'permalink_structure' ) ) {
494
+ $suffix = '';
495
+ if ( preg_match( '/([^\?]+)\?*?(.*)/i', $link, $_link ) ) {
496
+ $link = $_link[1];
497
+ $suffix = $_link[2];
498
+ }
499
+ if ( ! preg_match( '/\/$/', $link ) ) {
500
+ $link .= '/';
501
+ }
502
+ $link .= $share_key . '/' . $suffix;
503
+ } else {
504
+ $link = add_query_arg( 'tinvwlID', $share_key, $link );
505
+ }
506
+
507
+ if ( 1 < $paged ) {
508
+ $link = add_query_arg( 'paged', $paged, $link );
509
+ }
510
+
511
+ return $link;
512
+ }
513
+ } // End if().
514
+
515
+ if ( ! function_exists( 'tinv_url_wishlist' ) ) {
516
+
517
+ /**
518
+ * Return the wishlist url by id or share key
519
+ *
520
+ * @param mixed $id Integer wishlist ID, or Share Key wishlist.
521
+ * @param integer $paged Page.
522
+ * @param boolean $full Return full url or shroted url for logged in user.
523
+ *
524
+ * @return string
525
+ */
526
+ function tinv_url_wishlist( $id = '', $paged = 1, $full = true ) {
527
+ $share_key = $id;
528
+ if ( ! ( is_string( $id ) && preg_match( '/^[A-Fa-f0-9]{6}$/', $id ) ) ) {
529
+ $wishlist = tinv_wishlist_get( $id, false );
530
+ $share_key = $wishlist['share_key'];
531
+ }
532
+
533
+ return tinv_url_wishlist_by_key( $share_key, $paged );
534
+ }
535
+ }
536
+
537
+ if ( ! function_exists( 'tinv_wishlist_status' ) ) {
538
+
539
+ /**
540
+ * Check status free or premium plugin and disable free
541
+ *
542
+ * @global string $status
543
+ * @global string $page
544
+ * @global string $s
545
+ *
546
+ * @param string $transient Plugin transient name.
547
+ *
548
+ * @return string
549
+ */
550
+ function tinv_wishlist_status( $transient ) {
551
+ if ( TINVWL_LOAD_FREE === $transient ) {
552
+ TInvWL_PluginExtend::deactivate_self( TINVWL_LOAD_FREE );
553
+
554
+ return 'plugins.php';
555
+ }
556
+ if ( TINVWL_LOAD_PREMIUM === $transient ) {
557
+ if ( is_plugin_active( TINVWL_LOAD_FREE ) ) {
558
+ TInvWL_PluginExtend::deactivate_self( TINVWL_LOAD_FREE );
559
+ if ( ! function_exists( 'wp_create_nonce' ) ) {
560
+ return 'plugins.php';
561
+ }
562
+
563
+ global $status, $page, $s;
564
+ $redirect = 'plugins.php?';
565
+ $redirect .= http_build_query( array(
566
+ 'action' => 'activate',
567
+ 'plugin' => $transient,
568
+ 'plugin_status' => $status,
569
+ 'paged' => $page,
570
+ 's' => $s,
571
+ ) );
572
+ $redirect = esc_url_raw( add_query_arg( '_wpnonce', wp_create_nonce( 'activate-plugin_' . $transient ), $redirect ) );
573
+
574
+ return $redirect;
575
+ }
576
+ }
577
+
578
+ return false;
579
+ }
580
+ } // End if().
581
+
582
+ if ( ! function_exists( 'tinvwl_body_classes' ) ) {
583
+
584
+ /**
585
+ * Add custom class
586
+ *
587
+ * @param array $classes Current classes.
588
+ *
589
+ * @return array
590
+ */
591
+ function tinvwl_body_classes( $classes ) {
592
+ if ( tinv_get_option( 'style', 'customstyle' ) ) {
593
+ $classes[] = 'tinvwl-theme-style';
594
+ } else {
595
+ $classes[] = 'tinvwl-custom-style';
596
+ }
597
+
598
+ return $classes;
599
+ }
600
+
601
+ add_filter( 'body_class', 'tinvwl_body_classes' );
602
+ }
603
+
604
+ if ( ! function_exists( 'tinvwl_shortcode_addtowishlist' ) ) {
605
+
606
+ /**
607
+ * Shortcode Add To Wishlist
608
+ *
609
+ * @param array $atts Array parameter from shortcode.
610
+ *
611
+ * @return string
612
+ */
613
+ function tinvwl_shortcode_addtowishlist( $atts = array() ) {
614
+ $class = TInvWL_Public_AddToWishlist::instance();
615
+
616
+ return $class->shortcode( $atts );
617
+ }
618
+
619
+ add_shortcode( 'ti_wishlists_addtowishlist', 'tinvwl_shortcode_addtowishlist' );
620
+ }
621
+
622
+ if ( ! function_exists( 'tinvwl_shortcode_view' ) ) {
623
+
624
+ /**
625
+ * Shortcode view Wishlist
626
+ *
627
+ * @param array $atts Array parameter from shortcode.
628
+ *
629
+ * @return string
630
+ */
631
+ function tinvwl_shortcode_view( $atts = array() ) {
632
+ $class = TInvWL_Public_Wishlist_View::instance();
633
+
634
+ return $class->shortcode( $atts );
635
+ }
636
+
637
+ add_shortcode( 'ti_wishlistsview', 'tinvwl_shortcode_view' );
638
+ }
639
+
640
+ if ( ! function_exists( 'tinvwl_shortcode_products_counter' ) ) {
641
+
642
+ /**
643
+ * Shortcode view Wishlist
644
+ *
645
+ * @param array $atts Array parameter from shortcode.
646
+ *
647
+ * @return string
648
+ */
649
+ function tinvwl_shortcode_products_counter( $atts = array() ) {
650
+ $class = TInvWL_Public_TopWishlist::instance();
651
+
652
+ return $class->shortcode( $atts );
653
+ }
654
+
655
+ add_shortcode( 'ti_wishlist_products_counter', 'tinvwl_shortcode_products_counter' );
656
+ }
657
+
658
+ if ( ! function_exists( 'tinvwl_view_addto_html' ) ) {
659
+
660
+ /**
661
+ * Show button Add to Wishlsit
662
+ */
663
+ function tinvwl_view_addto_html() {
664
+ $class = TInvWL_Public_AddToWishlist::instance();
665
+ $class->htmloutput();
666
+ }
667
+ }
668
+
669
+ if ( ! function_exists( 'tinvwl_view_addto_htmlout' ) ) {
670
+
671
+ /**
672
+ * Show button Add to Wishlsit, if product is not purchasable
673
+ */
674
+ function tinvwl_view_addto_htmlout() {
675
+ $class = TInvWL_Public_AddToWishlist::instance();
676
+ $class->htmloutput_out();
677
+ }
678
+ }
679
+
680
+ if ( ! function_exists( 'tinvwl_view_addto_htmlloop' ) ) {
681
+
682
+ /**
683
+ * Show button Add to Wishlsit, in loop
684
+ */
685
+ function tinvwl_view_addto_htmlloop() {
686
+ $class = TInvWL_Public_AddToWishlist::instance();
687
+ $class->htmloutput_loop();
688
+ }
689
+ }
690
+
691
+ if ( ! function_exists( 'tinvwl_clean_url' ) ) {
692
+
693
+ /**
694
+ * Clear esc_url to original
695
+ *
696
+ * @param string $good_protocol_url Cleared URL.
697
+ * @param string $original_url Original URL.
698
+ *
699
+ * @return string
700
+ */
701
+ function tinvwl_clean_url( $good_protocol_url, $original_url ) {
702
+ return $original_url;
703
+ }
704
+ }
705
+
706
+ if ( ! function_exists( 'tinvwl_add_to_cart_need_redirect' ) ) {
707
+
708
+ /**
709
+ * Check if the product is third-party, or has another link added to the cart then redirect to the product page.
710
+ *
711
+ * @param boolean $redirect Default value to redirect.
712
+ * @param \WC_Product $product Product data.
713
+ * @param string $redirect_url Current url for redirect.
714
+ *
715
+ * @return boolean
716
+ */
717
+ function tinvwl_add_to_cart_need_redirect( $redirect, $product, $redirect_url ) {
718
+ if ( $redirect ) {
719
+ return true;
720
+ }
721
+ if ( 'external' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
722
+ return true;
723
+ }
724
+
725
+ $need_url_data = array_filter( array_merge( array(
726
+ 'variation_id' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 ) ),
727
+ 'add-to-cart' => ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->get_id() : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ),
728
+ ), array_map( 'urlencode', ( version_compare( WC_VERSION, '3.0.0', '<' ) ? ( is_array( $product->variation_data ) ? $product->variation_data : array() ) : array() ) ) ) );
729
+ $need_url = apply_filters( 'woocommerce_product_add_to_cart_url', remove_query_arg( 'added-to-cart', add_query_arg( $need_url_data ) ), $product );
730
+ $need_url_full = apply_filters( 'woocommerce_product_add_to_cart_url', remove_query_arg( 'added-to-cart', add_query_arg( $need_url_data, $product->get_permalink() ) ), $product );
731
+ add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
732
+ $_redirect_url = apply_filters( 'tinvwl_product_add_to_cart_redirect_url', $product->add_to_cart_url(), $product );
733
+ remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
734
+ if ( $_redirect_url !== $need_url && $_redirect_url !== $need_url_full ) {
735
+ return true;
736
+ }
737
+
738
+ return $redirect;
739
+ }
740
+
741
+ add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'tinvwl_add_to_cart_need_redirect', 10, 3 );
742
+ } // End if().
743
+
744
+ if ( ! function_exists( 'tinvwl_meta_validate_cart_add' ) ) {
745
+
746
+ /**
747
+ * Checks the ability to add a product
748
+ *
749
+ * @param boolean $redirect Default value to redirect.
750
+ * @param \WC_Product $product Product data.
751
+ * @param string $redirect_url Current url for redirect.
752
+ * @param array $wl_product Wishlist Product.
753
+ *
754
+ * @return boolean
755
+ */
756
+ function tinvwl_meta_validate_cart_add( $redirect, $product, $redirect_url, $wl_product ) {
757
+ if ( $redirect && array_key_exists( 'meta', $wl_product ) && ! empty( $wl_product['meta'] ) ) {
758
+
759
+ TInvWL_Public_Cart::prepare_post( $wl_product );
760
+
761
+ $wl_product = apply_filters( 'tinvwl_addproduct_tocart', $wl_product );
762
+ $product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $wl_product['product_id'] ) );
763
+ $quantity = empty( $wl_quantity ) ? 1 : wc_stock_amount( $wl_quantity );
764
+ $variation_id = $wl_product['variation_id'];
765
+ $variations = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_data : ( $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : array() ) );
766
+ $passed_validation = $product->is_purchasable() && ( $product->is_in_stock() || $product->backorders_allowed() ) && 'external' !== ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() );
767
+ ob_start();
768
+ wc_clear_notices();
769
+ $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', $passed_validation, $product_id, $quantity, $variation_id, $variations );
770
+ $wc_errors = wc_get_notices( 'error' );
771
+ $wc_output = ob_get_clean();
772
+ if ( $passed_validation && empty( $wc_errors ) && empty( $wc_output ) ) {
773
+ $redirect = false;
774
+ }
775
+
776
+ TInvWL_Public_Cart::unprepare_post();
777
+ }
778
+
779
+ return $redirect;
780
+ }
781
+
782
+ add_filter( 'tinvwl_product_add_to_cart_need_redirect', 'tinvwl_meta_validate_cart_add', 90, 4 );
783
+ } // End if().
784
+
785
+ if ( ! function_exists( 'tinv_wishlist_print_meta' ) ) {
786
+
787
+ /**
788
+ * Print meta data for wishlist form
789
+ *
790
+ * @param array $meta Meta Array.
791
+ * @param boolean $flat Return text or template.
792
+ *
793
+ * @return string
794
+ */
795
+ function tinv_wishlist_print_meta( $meta = array(), $flat = false ) {
796
+ if ( ! is_array( $meta ) ) {
797
+ $meta = array();
798
+ }
799
+ $product_id = $variation_id = 0;
800
+ if ( array_key_exists( 'product_id', $meta ) ) {
801
+ $product_id = $meta['product_id'];
802
+ }
803
+ if ( array_key_exists( 'variation_id', $meta ) ) {
804
+ $variation_id = $meta['variation_id'];
805
+ }
806
+ foreach ( array( 'add-to-cart', 'product_id', 'variation_id', 'quantity' ) as $field ) {
807
+ if ( array_key_exists( $field, $meta ) ) {
808
+ unset( $meta[ $field ] );
809
+ }
810
+ }
811
+ $meta = array_filter( $meta );
812
+ if ( empty( $meta ) ) {
813
+ return '';
814
+ }
815
+ $item_data = array();
816
+ foreach ( $meta as $key => $value ) {
817
+ if ( ! preg_match( '/^\_/', $key ) ) {
818
+ $item_data[ $key ] = array(
819
+ 'key' => $key,
820
+ 'display' => $value,
821
+ );
822
+ }
823
+ }
824
+ $item_data = apply_filters( 'tinvwl_wishlist_item_meta_post', $item_data, $product_id, $variation_id );
825
+ foreach ( $item_data as $key => $data ) {
826
+ if ( is_object( $data['display'] ) || is_array( $data['display'] ) ) {
827
+ $item_data[ $key ]['display'] = json_encode( $data['display'] );
828
+ }
829
+ }
830
+ ob_start();
831
+ if ( $flat ) {
832
+ foreach ( $item_data as $data ) {
833
+ echo esc_html( $data['key'] ) . ': ' . wp_kses_post( $data['display'] ) . '<br>';
834
+ }
835
+ } else {
836
+ tinv_wishlist_template( 'ti-wishlist-item-data.php', array( 'item_data' => $item_data ) );
837
+ }
838
+
839
+ return apply_filters( 'tinvwl_wishlist_item_meta_wishlist', ob_get_clean() );
840
+ }
841
+ } // End if().
842
+
843
+ if ( ! function_exists( 'tinv_wishlistmeta' ) ) {
844
+
845
+ /**
846
+ * Show new meta data
847
+ *
848
+ * @param string $meta Print meta.
849
+ * @param array $wl_product Wishlist product.
850
+ * @param \WC_Product $product Woocommerce product.
851
+ *
852
+ * @return string
853
+ */
854
+ function tinv_wishlistmeta( $meta = '', $wl_product, $product ) {
855
+ if ( empty( $meta ) ) {
856
+ if ( array_key_exists( 'meta', $wl_product ) ) {
857
+ $meta = apply_filters( 'tinvwl_wishlist_item_meta_wishlist_output', tinv_wishlist_print_meta( $wl_product['meta'] ), $wl_product, $product );
858
+ }
859
+ }
860
+
861
+ return $meta;
862
+ }
863
+
864
+ add_filter( 'tinvwl_wishlist_item_meta_data', 'tinv_wishlistmeta', 10, 3 );
865
+ }
866
+
867
+ if ( ! function_exists( 'tinvwl_add_to_cart_item_meta_post' ) ) {
868
+
869
+ /**
870
+ * Save post data to cart item
871
+ *
872
+ * @param array $cart_item_data Array with cart imet information.
873
+ * @param string $cart_item_key Cart item key.
874
+ *
875
+ * @return array
876
+ */
877
+ function tinvwl_add_to_cart_item_meta_post( $cart_item_data, $cart_item_key ) {
878
+ $postdata = $_POST; // @codingStandardsIgnoreLine WordPress.VIP.SuperGlobalInputUsage.AccessDetected
879
+
880
+ $postdata = apply_filters( 'tinvwl_product_prepare_meta', $postdata );
881
+ if ( array_key_exists( 'variation_id', $postdata ) && ! empty( $postdata['variation_id'] ) ) {
882
+ foreach ( $postdata as $key => $field ) {
883
+ if ( preg_match( '/^attribute\_/', $key ) ) {
884
+ unset( $postdata[ $key ] );
885
+ }
886
+ }
887
+ }
888
+ foreach ( array( 'add-to-cart', 'product_id', 'variation_id', 'quantity' ) as $field ) {
889
+ if ( array_key_exists( $field, $postdata ) ) {
890
+ unset( $postdata[ $field ] );
891
+ }
892
+ }
893
+ $postdata = array_filter( $postdata );
894
+ if ( empty( $postdata ) ) {
895
+ return $cart_item_data;
896
+ }
897
+ ksort( $postdata );
898
+
899
+ $cart_item_data['tinvwl_formdata'] = $postdata;
900
+
901
+ return $cart_item_data;
902
+ }
903
+
904
+ add_action( 'woocommerce_add_cart_item', 'tinvwl_add_to_cart_item_meta_post', 10, 2 );
905
+ } // End if().
906
+
907
+ if ( ! function_exists( 'tinvwl_rating_notice_template' ) ) {
908
+
909
+ /**
910
+ * Show admin notice.
911
+ *
912
+ * @param string $output String.
913
+ * @param string $key Unique notification key.
914
+ * @param string $message Text message.
915
+ *
916
+ * @return string
917
+ */
918
+ function tinvwl_rating_notice_template( $output, $key, $message ) {
919
+
920
+ TInvWL_View::view( 'notice-rating', array(
921
+ 'name' => 'rating',
922
+ 'message' => $message,
923
+ 'key' => $key,
924
+ ) );
925
+
926
+ return '';
927
+ }
928
+
929
+ add_filter( 'tinv_notice_rating', 'tinvwl_rating_notice_template', 10, 3 );
930
+ }
931
+
932
+ if ( ! function_exists( 'tinvwl_rating_notice_hide' ) ) {
933
+
934
+ /**
935
+ * Action for disable notice
936
+ */
937
+ function tinvwl_rating_notice_hide() {
938
+ $data = filter_input( INPUT_GET, 'ti-redirect' );
939
+ if ( $data ) {
940
+ wp_redirect( 'https://wordpress.org/support/plugin/ti-woocommerce-wishlist/reviews/#new-post' );
941
+ }
942
+ }
943
+
944
+ add_action( 'tinv_notice_hide_rating', 'tinvwl_rating_notice_hide' );
945
+ }
946
+
947
+ if ( ! function_exists( 'tinvwl_rating_notice_trigger_30' ) ) {
948
+
949
+ /**
950
+ * Trigger for reset notice
951
+ *
952
+ * @return boolean
953
+ */
954
+ function tinvwl_rating_notice_trigger_30() {
955
+ $tw = new TInvWL_Wishlist();
956
+ $wishlist = $tw->get( array(
957
+ 'count' => 1,
958
+ 'order_by' => 'date',
959
+ ) );
960
+ $wishlist = array_shift( $wishlist );
961
+ if ( empty( $wishlist ) ) {
962
+ return false;
963
+ }
964
+ $date = $wishlist['date'];
965
+ $date = mysql2date( 'G', $date );
966
+ $date = floor( ( time() - $date ) / DAY_IN_SECONDS );
967
+ $step = floor( $date / 30 );
968
+ if ( 0 >= $step ) {
969
+ return false;
970
+ }
971
+
972
+ return $step;
973
+ }
974
+ }
975
+
976
+ if ( ! function_exists( 'tinvwl_set_utm' ) ) {
977
+
978
+ /**
979
+ * Set UTM sources.
980
+ */
981
+ function tinvwl_set_utm() {
982
+
983
+ // Set a source.
984
+ $source = get_option( TINVWL_PREFIX . '_utm_source' );
985
+ if ( ! $source ) {
986
+ $source = defined( 'TINVWL_PARTNER' ) ? TINVWL_PARTNER : 'wordpress_org';
987
+ update_option( TINVWL_PREFIX . '_utm_source', $source );
988
+ }
989
+
990
+ define( 'TINVWL_UTM_SOURCE', $source );
991
+
992
+ // Set a medium.
993
+ $medium = get_option( TINVWL_PREFIX . '_utm_medium' );
994
+ if ( ! $medium ) {
995
+ $medium = defined( 'TINVWL_PARTNER' ) ? 'integration' : 'organic';
996
+ update_option( TINVWL_PREFIX . '_utm_medium', $medium );
997
+ }
998
+
999
+ define( 'TINVWL_UTM_MEDIUM', $medium );
1000
+
1001
+ // Set a campaign.
1002
+ $campaign = get_option( TINVWL_PREFIX . '_utm_campaign' );
1003
+ if ( ! $campaign ) {
1004
+ $campaign = defined( 'TINVWL_PARTNER' ) ? ( defined( 'TINVWL_CAMPAIGN' ) ? TINVWL_CAMPAIGN : TINVWL_PARTNER ) : 'organic';
1005
+ update_option( TINVWL_PREFIX . '_utm_campaign', $campaign );
1006
+ }
1007
+
1008
+ define( 'TINVWL_UTM_CAMPAIGN', $campaign );
1009
+ }
1010
+ } // End if().
views/section-infoblock.php CHANGED
@@ -1,26 +1,26 @@
1
- <?php
2
- /**
3
- * The Template for displaying admin section info block this plugin.
4
- *
5
- * @since 1.0.0
6
- * @package TInvWishlist\Admin\Template
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit; // Exit if accessed directly.
11
- }
12
-
13
- ?>
14
- <div class="tinvwl-info-wrap tinvwl-in-section">
15
- <div class="tinvwl-table">
16
- <span class="tinvwl-info-sign tinvwl-cell">
17
- <span>
18
- <i class="fa fa-info"></i>
19
- </span>
20
- <a class="tinvwl-help" href="javascript:void(0)" data-container="body" data-toggle="popover" data-trigger="manual" data-placement="left" data-html="true">
21
- <i class="fa fa-info"></i>
22
- </a>
23
- </span>
24
- <span class="tinvwl-info-desc tinvwl-cell"><?php echo $desc; // WPCS: xss ok. ?></span>
25
- </div>
26
- </div>
1
+ <?php
2
+ /**
3
+ * The Template for displaying admin section info block this plugin.
4
+ *
5
+ * @since 1.0.0
6
+ * @package TInvWishlist\Admin\Template
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ ?>
14
+ <div class="tinvwl-info-wrap tinvwl-in-section">
15
+ <div class="tinvwl-table">
16
+ <span class="tinvwl-info-sign tinvwl-cell">
17
+ <span>
18
+ <i class="fa fa-info"></i>
19
+ </span>
20
+ <a class="tinvwl-help" href="javascript:void(0)" data-container="body" data-toggle="popover" data-trigger="manual" data-placement="left" data-html="true" rel="nofollow">
21
+ <i class="fa fa-info"></i>
22
+ </a>
23
+ </span>
24
+ <span class="tinvwl-info-desc tinvwl-cell"><?php echo $desc; // WPCS: xss ok. ?></span>
25
+ </div>
26
+ </div>
views/wizard/finish.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * The Template for displaying wizard finish step.
4
  *
5
- * @since 1.0.0
6
  * @package TInvWishlist\Wizard\Template
7
  */
8
 
@@ -22,10 +22,11 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  </div>
23
  <a class="tinvwl-btn grey w-icon xl-icon round"
24
  href="<?php echo 'https://templateinvaders.com/documentation/ti-woocommerce-wishlist/?utm_source=' . TINVWL_UTM_SOURCE . '&utm_campaign=' . TINVWL_UTM_CAMPAIGN . '&utm_medium=' . TINVWL_UTM_MEDIUM . '&utm_content=wizard_documentation&partner=' . TINVWL_UTM_SOURCE; // WPCS: xss ok.
25
- ?>"><i class="fa fa-graduation-cap"></i><?php esc_html_e( 'Documentation', 'ti-woocommerce-wishlist' ); ?></a>
26
  <a class="tinvwl-btn grey w-icon xl-icon round" href="<?php echo esc_url( self::admin_url( '' ) ); ?>"><i
27
  class="fa fa-wrench"></i><?php esc_html_e( 'Wishlist Settings', 'ti-woocommerce-wishlist' ); ?></a>
28
- <div class="tinv-wishlist-clear"></div>
29
- <a class="tinvwl-more"
30
- href="https://templateinvaders.com/?utm_source=<?php echo TINVWL_UTM_SOURCE; // WPCS: xss ok. ?>&utm_campaign=<?php echo TINVWL_UTM_CAMPAIGN; // WPCS: xss ok. ?>&utm_medium=<?php echo TINVWL_UTM_MEDIUM; // WPCS: xss ok. ?>&utm_content=wizard_more_product&partner=<?php echo TINVWL_UTM_SOURCE; // WPCS: xss ok. ?>"><?php esc_html_e( 'Visit TemplateInvaders website for more products.', 'ti-woocommerce-wishlist' ); ?></a>
 
31
  </div>
2
  /**
3
  * The Template for displaying wizard finish step.
4
  *
5
+ * @version 1.6.1
6
  * @package TInvWishlist\Wizard\Template
7
  */
8
 
22
  </div>
23
  <a class="tinvwl-btn grey w-icon xl-icon round"
24
  href="<?php echo 'https://templateinvaders.com/documentation/ti-woocommerce-wishlist/?utm_source=' . TINVWL_UTM_SOURCE . '&utm_campaign=' . TINVWL_UTM_CAMPAIGN . '&utm_medium=' . TINVWL_UTM_MEDIUM . '&utm_content=wizard_documentation&partner=' . TINVWL_UTM_SOURCE; // WPCS: xss ok.
25
+ ?>"><i class="fa fa-graduation-cap"></i><?php esc_html_e( 'Documentation', 'ti-woocommerce-wishlist' ); ?></a>
26
  <a class="tinvwl-btn grey w-icon xl-icon round" href="<?php echo esc_url( self::admin_url( '' ) ); ?>"><i
27
  class="fa fa-wrench"></i><?php esc_html_e( 'Wishlist Settings', 'ti-woocommerce-wishlist' ); ?></a>
28
+ <div class="tinv-wishlist-clear" style="padding: 20px 0"></div>
29
+ <a class="tinvwl-btn red w-icon smaller-txt"
30
+ href="https://templateinvaders.com/?utm_source=<?php echo TINVWL_UTM_SOURCE; // WPCS: xss ok. ?>&utm_campaign=<?php echo TINVWL_UTM_CAMPAIGN; // WPCS: xss ok. ?>&utm_medium=<?php echo TINVWL_UTM_MEDIUM; // WPCS: xss ok. ?>&utm_content=wizard_upgrade&partner=<?php echo TINVWL_UTM_SOURCE; // WPCS: xss ok. ?>"><i
31
+ class="fa fa-star"></i><?php esc_html_e( 'Upgrade to Premium', 'ti-woocommerce-wishlist' ); ?></a>
32
  </div>
wpm-config.json CHANGED
@@ -1,41 +1,35 @@
1
- {
2
- "admin_pages": [
3
- "toplevel_page_tinvwl"
4
- ],
5
- "options": {
6
- "tinvwl-general": {
7
- "default_title": {},
8
- "text_browse": {},
9
- "text_added_to": {},
10
- "text_already_in": {},
11
- "text_text_removed_from": {}
12
- },
13
-
14
- "tinvwl-add_to_wishlist": {
15
- "text": {},
16
- "text_remove": {}
17
- },
18
-
19
- "tinvwl-add_to_wishlist_catalog": {
20
- "text": {},
21
- "text_remove": {}
22
- },
23
-
24
- "tinvwl-product_table": {
25
- "text_add_to_cart": {}
26
- },
27
-
28
- "tinvwl-table": {
29
- "text_add_select_to_cart": {},
30
- "text_add_all_to_cart": {}
31
- },
32
-
33
- "tinvwl-social": {
34
- "share_on": {}
35
- },
36
-
37
- "tinvwl-topline": {
38
- "text": {}
39
- }
40
- }
41
- }
1
+ {
2
+ "admin_pages": [
3
+ "toplevel_page_tinvwl"
4
+ ],
5
+ "options": {
6
+ "tinvwl-general": {
7
+ "default_title": {},
8
+ "text_browse": {},
9
+ "text_added_to": {},
10
+ "text_already_in": {},
11
+ "text_removed_from": {}
12
+ },
13
+ "tinvwl-add_to_wishlist": {
14
+ "text": {},
15
+ "text_remove": {}
16
+ },
17
+ "tinvwl-add_to_wishlist_catalog": {
18
+ "text": {},
19
+ "text_remove": {}
20
+ },
21
+ "tinvwl-product_table": {
22
+ "text_add_to_cart": {}
23
+ },
24
+ "tinvwl-table": {
25
+ "text_add_select_to_cart": {},
26
+ "text_add_all_to_cart": {}
27
+ },
28
+ "tinvwl-social": {
29
+ "share_on": {}
30
+ },
31
+ "tinvwl-topline": {
32
+ "text": {}
33
+ }
34
+ }
35
+ }