Version Description
Release Date - 20 September 2017
- Fixed an issue with transferring products between guest and customer wishlists after signing in or logout.
- Fixed an issue when it's not possible to remove products from wishlist as a guest
- Fixed an issue with adding a product variations to wishlist
- Improved WooCommerce Product Bundles plugin support:
- Fixed an issue with displaying product custom meta attributes
- Improved WPML plugin compatibility:
- Fixed an issue with "Remove/Add" button text when switching languages
Download this release
Release Info
Developer | templateinvaders |
Plugin | WooCommerce Wishlist Plugin |
Version | 1.5.6 |
Comparing to | |
See all releases |
Code changes from version 1.5.5 to 1.5.6
- includes/product.helper.php +23 -11
- languages/ti-woocommerce-wishlist.pot +32 -28
- public/addtowishlist.class.php +2 -1
- public/tinvwl.class.php +575 -560
- public/widget/topwishlist.class.php +1 -1
- public/wishlist/buttons.class.php +451 -447
- public/wishlist/view.class.php +1 -1
- readme.txt +12 -1
- ti-woocommerce-wishlist.php +2 -2
- tinv-wishlists-function-integration.php +105 -3
includes/product.helper.php
CHANGED
@@ -279,7 +279,14 @@ class TInvWL_Product {
|
|
279 |
$where = '1';
|
280 |
if ( ! empty( $data ) && is_array( $data ) ) {
|
281 |
if ( array_key_exists( 'meta', $data ) ) {
|
282 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
unset( $data['meta'] );
|
284 |
}
|
285 |
foreach ( $data as $f => $v ) {
|
@@ -342,6 +349,9 @@ class TInvWL_Product {
|
|
342 |
if ( $product_data ) {
|
343 |
$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() ) );
|
344 |
$product['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
|
|
|
|
|
|
|
345 |
}
|
346 |
$product['data'] = $product_data;
|
347 |
}
|
@@ -531,16 +541,18 @@ class TInvWL_Product {
|
|
531 |
}
|
532 |
$meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
|
533 |
if ( ! empty( $variation_id ) ) {
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
|
|
|
|
544 |
}
|
545 |
}
|
546 |
}
|
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 ) {
|
349 |
if ( $product_data ) {
|
350 |
$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() ) );
|
351 |
$product['variation_id'] = ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product_data->variation_id : ( $product_data->is_type( 'variation' ) ? $product_data->get_id() : 0 ) );
|
352 |
+
} else {
|
353 |
+
unset( $products[ $k ] );
|
354 |
+
continue;
|
355 |
}
|
356 |
$product['data'] = $product_data;
|
357 |
}
|
541 |
}
|
542 |
$meta = apply_filters( 'tinvwl_product_prepare_meta', $meta, $product_id, $variation_id );
|
543 |
if ( ! empty( $variation_id ) ) {
|
544 |
+
$product_data = $this->product_data( $product_id, $variation_id );
|
545 |
+
if ( is_object( $product_data ) ) {
|
546 |
+
$attributes = array_keys( (array) $product_data->get_variation_attributes() );
|
547 |
+
foreach ( $attributes as $attribute ) {
|
548 |
+
if ( array_key_exists( $attribute, $meta ) ) {
|
549 |
+
unset( $meta[ $attribute ] );
|
550 |
+
continue;
|
551 |
+
}
|
552 |
+
$attribute = 'attribute_' . sanitize_title( $attribute );
|
553 |
+
if ( array_key_exists( $attribute, $meta ) ) {
|
554 |
+
unset( $meta[ $attribute ] );
|
555 |
+
}
|
556 |
}
|
557 |
}
|
558 |
}
|
languages/ti-woocommerce-wishlist.pot
CHANGED
@@ -3,7 +3,7 @@ msgid ""
|
|
3 |
msgstr ""
|
4 |
"Project-Id-Version: WooCommerce Wishlist Plugin\n"
|
5 |
"Report-Msgid-Bugs-To: \n"
|
6 |
-
"POT-Creation-Date: 2017-09-
|
7 |
"POT-Revision-Date: Sun Apr 10 2016 12:21:06 GMT+0200 (Västeuropa, "
|
8 |
"sommartid)\n"
|
9 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
@@ -136,7 +136,7 @@ msgid "Wishlist Page Options"
|
|
136 |
msgstr ""
|
137 |
|
138 |
#: admin/settings/general.class.php:160 admin/settings/general.class.php:177
|
139 |
-
#: public/tinvwl.class.php:
|
140 |
msgid "Coming soon"
|
141 |
msgstr ""
|
142 |
|
@@ -392,7 +392,7 @@ msgstr ""
|
|
392 |
msgid "\"Share on\" Text"
|
393 |
msgstr ""
|
394 |
|
395 |
-
#: admin/settings/general.class.php:546
|
396 |
msgid "Wishlist Products Counter"
|
397 |
msgstr ""
|
398 |
|
@@ -926,7 +926,7 @@ msgid "Page Setup"
|
|
926 |
msgstr ""
|
927 |
|
928 |
#: includes/wizard.class.php:282 includes/wizard.class.php:312
|
929 |
-
#: public/tinvwl.class.php:
|
930 |
msgid "Wishlist"
|
931 |
msgstr ""
|
932 |
|
@@ -958,16 +958,16 @@ msgstr ""
|
|
958 |
msgid "Ready!"
|
959 |
msgstr ""
|
960 |
|
961 |
-
#: public/tinvwl.class.php:
|
962 |
#, php-format
|
963 |
msgid "%1$s of %2$s"
|
964 |
msgstr ""
|
965 |
|
966 |
-
#: public/tinvwl.class.php:
|
967 |
msgid "Create New"
|
968 |
msgstr ""
|
969 |
|
970 |
-
#: public/tinvwl.class.php:
|
971 |
msgid ""
|
972 |
"Please select some product options before adding this product to your "
|
973 |
"wishlist."
|
@@ -977,6 +977,10 @@ msgstr ""
|
|
977 |
msgid "Displays the number of products in the wishlist on your site."
|
978 |
msgstr ""
|
979 |
|
|
|
|
|
|
|
|
|
980 |
#: public/widget/topwishlist.class.php:31
|
981 |
msgid "Show counter icon"
|
982 |
msgstr ""
|
@@ -990,13 +994,13 @@ msgstr ""
|
|
990 |
msgid "Action"
|
991 |
msgstr ""
|
992 |
|
993 |
-
#: public/wishlist/buttons.class.php:
|
994 |
#, php-format
|
995 |
msgctxt "Item name in quotes"
|
996 |
msgid "“%s”"
|
997 |
msgstr ""
|
998 |
|
999 |
-
#: public/wishlist/buttons.class.php:
|
1000 |
#, php-format
|
1001 |
msgid ""
|
1002 |
"Product %s could not be added to cart because some options are not "
|
@@ -1009,20 +1013,20 @@ msgid_plural ""
|
|
1009 |
msgstr[0] ""
|
1010 |
msgstr[1] ""
|
1011 |
|
1012 |
-
#: public/wishlist/buttons.class.php:
|
1013 |
msgid "Actions"
|
1014 |
msgstr ""
|
1015 |
|
1016 |
-
#: public/wishlist/buttons.class.php:
|
1017 |
msgid "Remove"
|
1018 |
msgstr ""
|
1019 |
|
1020 |
-
#: public/wishlist/buttons.class.php:
|
1021 |
#, php-format
|
1022 |
msgid "“%s”"
|
1023 |
msgstr ""
|
1024 |
|
1025 |
-
#: public/wishlist/buttons.class.php:
|
1026 |
#, php-format
|
1027 |
msgid "%s has been successfully removed from wishlist."
|
1028 |
msgid_plural "%s have been successfully removed from wishlist."
|
@@ -1096,10 +1100,10 @@ msgid "Stock Status"
|
|
1096 |
msgstr ""
|
1097 |
|
1098 |
#: templates/ti-wishlist-user.php:110 templates/ti-wishlist.php:114
|
1099 |
-
#: tinv-wishlists-function-integration.php:
|
1100 |
-
#: tinv-wishlists-function-integration.php:
|
1101 |
-
#: tinv-wishlists-function-integration.php:
|
1102 |
-
#: tinv-wishlists-function-integration.php:
|
1103 |
msgid "In stock"
|
1104 |
msgstr ""
|
1105 |
|
@@ -1107,35 +1111,35 @@ msgstr ""
|
|
1107 |
msgid "Select options"
|
1108 |
msgstr ""
|
1109 |
|
1110 |
-
#: tinv-wishlists-function-integration.php:
|
1111 |
msgid "Note"
|
1112 |
msgstr ""
|
1113 |
|
1114 |
-
#: tinv-wishlists-function-integration.php:
|
1115 |
msgid "To"
|
1116 |
msgstr ""
|
1117 |
|
1118 |
-
#: tinv-wishlists-function-integration.php:
|
1119 |
msgid "To Email"
|
1120 |
msgstr ""
|
1121 |
|
1122 |
-
#: tinv-wishlists-function-integration.php:
|
1123 |
msgid "Address"
|
1124 |
msgstr ""
|
1125 |
|
1126 |
-
#: tinv-wishlists-function-integration.php:
|
1127 |
msgid "Reload existing Gift Card"
|
1128 |
msgstr ""
|
1129 |
|
1130 |
-
#: tinv-wishlists-function-integration.php:
|
1131 |
msgid "Out of stock"
|
1132 |
msgstr ""
|
1133 |
|
1134 |
-
#: tinv-wishlists-function-integration.php:
|
1135 |
msgid "Photos imported - "
|
1136 |
msgstr ""
|
1137 |
|
1138 |
-
#: tinv-wishlists-function-integration.php:
|
1139 |
#, php-format
|
1140 |
msgid ""
|
1141 |
"Please help us improve %2$s! If you opt-in, some data about your usage of "
|
@@ -1143,18 +1147,18 @@ msgid ""
|
|
1143 |
"work just fine."
|
1144 |
msgstr ""
|
1145 |
|
1146 |
-
#: tinv-wishlists-function-integration.php:
|
1147 |
#, php-format
|
1148 |
msgid ""
|
1149 |
"Allow %6$s to collect some usage data with %5$s to make the plugin even more "
|
1150 |
"awesome. If you skip this, that's okay! %2$s will still work just fine."
|
1151 |
msgstr ""
|
1152 |
|
1153 |
-
#: tinv-wishlists-function-integration.php:
|
1154 |
msgid "WooCommerce Wishlist Plugin"
|
1155 |
msgstr ""
|
1156 |
|
1157 |
-
#: tinv-wishlists-function-integration.php:
|
1158 |
msgid "TemplateInvaders"
|
1159 |
msgstr ""
|
1160 |
|
3 |
msgstr ""
|
4 |
"Project-Id-Version: WooCommerce Wishlist Plugin\n"
|
5 |
"Report-Msgid-Bugs-To: \n"
|
6 |
+
"POT-Creation-Date: 2017-09-21 01:26+0700\n"
|
7 |
"POT-Revision-Date: Sun Apr 10 2016 12:21:06 GMT+0200 (Västeuropa, "
|
8 |
"sommartid)\n"
|
9 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
136 |
msgstr ""
|
137 |
|
138 |
#: admin/settings/general.class.php:160 admin/settings/general.class.php:177
|
139 |
+
#: public/tinvwl.class.php:271
|
140 |
msgid "Coming soon"
|
141 |
msgstr ""
|
142 |
|
392 |
msgid "\"Share on\" Text"
|
393 |
msgstr ""
|
394 |
|
395 |
+
#: admin/settings/general.class.php:546
|
396 |
msgid "Wishlist Products Counter"
|
397 |
msgstr ""
|
398 |
|
926 |
msgstr ""
|
927 |
|
928 |
#: includes/wizard.class.php:282 includes/wizard.class.php:312
|
929 |
+
#: public/tinvwl.class.php:507
|
930 |
msgid "Wishlist"
|
931 |
msgstr ""
|
932 |
|
958 |
msgid "Ready!"
|
959 |
msgstr ""
|
960 |
|
961 |
+
#: public/tinvwl.class.php:270
|
962 |
#, php-format
|
963 |
msgid "%1$s of %2$s"
|
964 |
msgstr ""
|
965 |
|
966 |
+
#: public/tinvwl.class.php:414
|
967 |
msgid "Create New"
|
968 |
msgstr ""
|
969 |
|
970 |
+
#: public/tinvwl.class.php:416
|
971 |
msgid ""
|
972 |
"Please select some product options before adding this product to your "
|
973 |
"wishlist."
|
977 |
msgid "Displays the number of products in the wishlist on your site."
|
978 |
msgstr ""
|
979 |
|
980 |
+
#: public/widget/topwishlist.class.php:26
|
981 |
+
msgid "TInv Wishlist Products Counter"
|
982 |
+
msgstr ""
|
983 |
+
|
984 |
#: public/widget/topwishlist.class.php:31
|
985 |
msgid "Show counter icon"
|
986 |
msgstr ""
|
994 |
msgid "Action"
|
995 |
msgstr ""
|
996 |
|
997 |
+
#: public/wishlist/buttons.class.php:256 public/wishlist/buttons.class.php:351
|
998 |
#, php-format
|
999 |
msgctxt "Item name in quotes"
|
1000 |
msgid "“%s”"
|
1001 |
msgstr ""
|
1002 |
|
1003 |
+
#: public/wishlist/buttons.class.php:259 public/wishlist/buttons.class.php:354
|
1004 |
#, php-format
|
1005 |
msgid ""
|
1006 |
"Product %s could not be added to cart because some options are not "
|
1013 |
msgstr[0] ""
|
1014 |
msgstr[1] ""
|
1015 |
|
1016 |
+
#: public/wishlist/buttons.class.php:275
|
1017 |
msgid "Actions"
|
1018 |
msgstr ""
|
1019 |
|
1020 |
+
#: public/wishlist/buttons.class.php:280
|
1021 |
msgid "Remove"
|
1022 |
msgstr ""
|
1023 |
|
1024 |
+
#: public/wishlist/buttons.class.php:395 public/wishlist/view.class.php:252
|
1025 |
#, php-format
|
1026 |
msgid "“%s”"
|
1027 |
msgstr ""
|
1028 |
|
1029 |
+
#: public/wishlist/buttons.class.php:400
|
1030 |
#, php-format
|
1031 |
msgid "%s has been successfully removed from wishlist."
|
1032 |
msgid_plural "%s have been successfully removed from wishlist."
|
1100 |
msgstr ""
|
1101 |
|
1102 |
#: templates/ti-wishlist-user.php:110 templates/ti-wishlist.php:114
|
1103 |
+
#: tinv-wishlists-function-integration.php:771
|
1104 |
+
#: tinv-wishlists-function-integration.php:920
|
1105 |
+
#: tinv-wishlists-function-integration.php:1067
|
1106 |
+
#: tinv-wishlists-function-integration.php:1280
|
1107 |
msgid "In stock"
|
1108 |
msgstr ""
|
1109 |
|
1111 |
msgid "Select options"
|
1112 |
msgstr ""
|
1113 |
|
1114 |
+
#: tinv-wishlists-function-integration.php:496
|
1115 |
msgid "Note"
|
1116 |
msgstr ""
|
1117 |
|
1118 |
+
#: tinv-wishlists-function-integration.php:499
|
1119 |
msgid "To"
|
1120 |
msgstr ""
|
1121 |
|
1122 |
+
#: tinv-wishlists-function-integration.php:502
|
1123 |
msgid "To Email"
|
1124 |
msgstr ""
|
1125 |
|
1126 |
+
#: tinv-wishlists-function-integration.php:505
|
1127 |
msgid "Address"
|
1128 |
msgstr ""
|
1129 |
|
1130 |
+
#: tinv-wishlists-function-integration.php:508
|
1131 |
msgid "Reload existing Gift Card"
|
1132 |
msgstr ""
|
1133 |
|
1134 |
+
#: tinv-wishlists-function-integration.php:1219
|
1135 |
msgid "Out of stock"
|
1136 |
msgstr ""
|
1137 |
|
1138 |
+
#: tinv-wishlists-function-integration.php:1410
|
1139 |
msgid "Photos imported - "
|
1140 |
msgstr ""
|
1141 |
|
1142 |
+
#: tinv-wishlists-function-integration.php:1517
|
1143 |
#, php-format
|
1144 |
msgid ""
|
1145 |
"Please help us improve %2$s! If you opt-in, some data about your usage of "
|
1147 |
"work just fine."
|
1148 |
msgstr ""
|
1149 |
|
1150 |
+
#: tinv-wishlists-function-integration.php:1531
|
1151 |
#, php-format
|
1152 |
msgid ""
|
1153 |
"Allow %6$s to collect some usage data with %5$s to make the plugin even more "
|
1154 |
"awesome. If you skip this, that's okay! %2$s will still work just fine."
|
1155 |
msgstr ""
|
1156 |
|
1157 |
+
#: tinv-wishlists-function-integration.php:1531
|
1158 |
msgid "WooCommerce Wishlist Plugin"
|
1159 |
msgstr ""
|
1160 |
|
1161 |
+
#: tinv-wishlists-function-integration.php:1531
|
1162 |
msgid "TemplateInvaders"
|
1163 |
msgstr ""
|
1164 |
|
public/addtowishlist.class.php
CHANGED
@@ -430,7 +430,8 @@ class TInvWL_Public_AddToWishlist {
|
|
430 |
function htmloutput( $attr = array(), $is_shortcode = false ) {
|
431 |
global $product;
|
432 |
|
433 |
-
$
|
|
|
434 |
$position = tinv_get_option( 'add_to_wishlist', 'position' );
|
435 |
if ( $is_shortcode ) {
|
436 |
$position = 'shortcode';
|
430 |
function htmloutput( $attr = array(), $is_shortcode = false ) {
|
431 |
global $product;
|
432 |
|
433 |
+
$attr = apply_filters( 'tinvwl_addtowishlist_out_prepare_attr', $attr );
|
434 |
+
$this->product = apply_filters( 'tinvwl_addtowishlist_out_prepare_product', $product );
|
435 |
$position = tinv_get_option( 'add_to_wishlist', 'position' );
|
436 |
if ( $is_shortcode ) {
|
437 |
$position = 'shortcode';
|
public/tinvwl.class.php
CHANGED
@@ -1,560 +1,575 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Public pages class
|
4 |
-
*
|
5 |
-
* @since 1.0.0
|
6 |
-
* @package TInvWishlist\Public
|
7 |
-
*/
|
8 |
-
|
9 |
-
// If this file is called directly, abort.
|
10 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
11 |
-
die;
|
12 |
-
}
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Public pages class
|
16 |
-
*/
|
17 |
-
class TInvWL_Public_TInvWL {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Plugin name
|
21 |
-
*
|
22 |
-
* @var string
|
23 |
-
*/
|
24 |
-
public $_n;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Plugin version
|
28 |
-
*
|
29 |
-
* @var string
|
30 |
-
*/
|
31 |
-
public $_v;
|
32 |
-
/**
|
33 |
-
* This class
|
34 |
-
*
|
35 |
-
* @var \TInvWL_Public_TInvWL
|
36 |
-
*/
|
37 |
-
protected static $_instance = null;
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Get this class object
|
41 |
-
*
|
42 |
-
* @param string $plugin_name Plugin name.
|
43 |
-
* @param string $version Plugin version.
|
44 |
-
*
|
45 |
-
* @return \TInvWL_Public_TInvWL
|
46 |
-
*/
|
47 |
-
public static function instance( $plugin_name = TINVWL_PREFIX, $version = TINVWL_VERSION ) {
|
48 |
-
if ( is_null( self::$_instance ) ) {
|
49 |
-
self::$_instance = new self( $plugin_name, $version );
|
50 |
-
}
|
51 |
-
|
52 |
-
return self::$_instance;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Constructor
|
57 |
-
*
|
58 |
-
* @param string $plugin_name Plugin name.
|
59 |
-
* @param string $version Plugin version.
|
60 |
-
*/
|
61 |
-
function __construct( $plugin_name, $version ) {
|
62 |
-
$this->_n = $plugin_name;
|
63 |
-
$this->_v = $version;
|
64 |
-
$this->pre_load_function();
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Create all object and shortcode
|
69 |
-
*/
|
70 |
-
function pre_load_function() {
|
71 |
-
add_action( 'init', array( $this, 'apply_rewrite_rules' ), 0 );
|
72 |
-
add_action( 'init', array( $this, 'add_rewrite_rules' ), 0 );
|
73 |
-
add_filter( 'query_vars', array( $this, 'add_query_var' ) );
|
74 |
-
add_action( 'deleted_user', array( $this, 'delete_user_wishlist' ) );
|
75 |
-
|
76 |
-
add_action( 'wp_ajax_nopriv_' . $this->_n . '_css', array( $this, 'dynaminc_css' ) );
|
77 |
-
add_action( 'wp_ajax_' . $this->_n . '_css', array( $this, 'dynaminc_css' ) );
|
78 |
-
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
79 |
-
|
80 |
-
add_filter( 'woocommerce_locate_core_template', array( $this, 'locate_template' ), 10, 3 );
|
81 |
-
add_filter( 'woocommerce_locate_template', array( $this, 'locate_template' ), 10, 3 );
|
82 |
-
|
83 |
-
$this->addto = TInvWL_Public_AddToWishlist::instance( $this->_n );
|
84 |
-
$this->view = TInvWL_Public_Wishlist_View::instance( $this->_n );
|
85 |
-
$this->cart = TInvWL_Public_Cart::instance( $this->_n );
|
86 |
-
$this->topwishlist = TInvWL_Public_TopWishlist::instance( $this->_n );
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Define hooks
|
91 |
-
*/
|
92 |
-
function define_hooks() {
|
93 |
-
if ( tinv_get_option( 'social', 'facebook' ) || tinv_get_option( 'social', 'google' ) ) {
|
94 |
-
add_filter( 'language_attributes', array( $this, 'add_ogp' ) );
|
95 |
-
add_action( 'wp_head', array( $this, 'add_meta_tags' ), 0 );
|
96 |
-
}
|
97 |
-
|
98 |
-
if ( tinv_get_option( 'general', 'link_in_myaccount' ) ) {
|
99 |
-
add_filter( 'woocommerce_account_menu_items', array( $this, 'account_menu_items' ) );
|
100 |
-
add_filter( 'woocommerce_get_endpoint_url', array( $this, 'account_menu_endpoint' ), 4, 10 );
|
101 |
-
}
|
102 |
-
|
103 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_header' ) );
|
104 |
-
add_action( 'wp_login', array( $this, 'transfert_local_to_user' ), 10, 2 );
|
105 |
-
add_action( 'user_register', array( $this, 'transfert_local_to_user_register' ) );
|
106 |
-
add_action( 'init', array( $this, 'legacy_transfer' ), 90 );
|
107 |
-
|
108 |
-
|
109 |
-
add_action( $this->_n . '_after_wishlist_table', array( $this, '
|
110 |
-
add_action( $this->_n . '_after_wishlist_table', array( $this, '
|
111 |
-
add_action( $this->_n . '_after_wishlist_table', array( $this, '
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
*
|
149 |
-
*
|
150 |
-
* @param string $
|
151 |
-
* @param string $
|
152 |
-
*
|
153 |
-
*
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
$
|
188 |
-
$
|
189 |
-
$
|
190 |
-
|
191 |
-
'
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
$
|
197 |
-
|
198 |
-
|
199 |
-
$
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
$
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
add_rewrite_rule( '^(' . $language_codes . ')/(([^/]+/)*' . $page_slug . ')/([A-Fa-f0-9]{6})?/{0,1}$', 'index.php?pagename=$matches[2]&tinvwlID=$matches[4]&paged=$matches[5]&lang=$matches[1]', 'top' );
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
add_rewrite_rule( '(([^/]+/)*' . $page_slug . ')/([A-Fa-f0-9]{6})?/{0,1}$', 'index.php?pagename=$matches[1]&tinvwlID=$matches[3]', 'top' );
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
*
|
222 |
-
*
|
223 |
-
*
|
224 |
-
*
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
$public_var[] = '
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
$
|
245 |
-
|
246 |
-
|
247 |
-
$
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
$
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
$
|
256 |
-
|
257 |
-
'
|
258 |
-
'
|
259 |
-
|
260 |
-
|
261 |
-
$
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
'
|
269 |
-
'
|
270 |
-
'
|
271 |
-
'
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
*
|
296 |
-
*
|
297 |
-
*
|
298 |
-
*
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
*
|
311 |
-
*
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
$pages =
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
$this->
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
*
|
353 |
-
*
|
354 |
-
*
|
355 |
-
*
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
$css = preg_replace( '
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
$
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
$
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
$
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
'
|
415 |
-
'
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
*
|
430 |
-
*
|
431 |
-
* @param
|
432 |
-
*
|
433 |
-
*
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
*
|
442 |
-
*
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
$
|
447 |
-
|
448 |
-
|
449 |
-
$
|
450 |
-
$
|
451 |
-
$
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
$
|
457 |
-
$
|
458 |
-
|
459 |
-
|
460 |
-
$
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
$
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
*
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
$
|
489 |
-
$
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
*
|
520 |
-
*
|
521 |
-
* @param
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
$
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Public pages class
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
* @package TInvWishlist\Public
|
7 |
+
*/
|
8 |
+
|
9 |
+
// If this file is called directly, abort.
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
11 |
+
die;
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Public pages class
|
16 |
+
*/
|
17 |
+
class TInvWL_Public_TInvWL {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Plugin name
|
21 |
+
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
public $_n;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Plugin version
|
28 |
+
*
|
29 |
+
* @var string
|
30 |
+
*/
|
31 |
+
public $_v;
|
32 |
+
/**
|
33 |
+
* This class
|
34 |
+
*
|
35 |
+
* @var \TInvWL_Public_TInvWL
|
36 |
+
*/
|
37 |
+
protected static $_instance = null;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Get this class object
|
41 |
+
*
|
42 |
+
* @param string $plugin_name Plugin name.
|
43 |
+
* @param string $version Plugin version.
|
44 |
+
*
|
45 |
+
* @return \TInvWL_Public_TInvWL
|
46 |
+
*/
|
47 |
+
public static function instance( $plugin_name = TINVWL_PREFIX, $version = TINVWL_VERSION ) {
|
48 |
+
if ( is_null( self::$_instance ) ) {
|
49 |
+
self::$_instance = new self( $plugin_name, $version );
|
50 |
+
}
|
51 |
+
|
52 |
+
return self::$_instance;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Constructor
|
57 |
+
*
|
58 |
+
* @param string $plugin_name Plugin name.
|
59 |
+
* @param string $version Plugin version.
|
60 |
+
*/
|
61 |
+
function __construct( $plugin_name, $version ) {
|
62 |
+
$this->_n = $plugin_name;
|
63 |
+
$this->_v = $version;
|
64 |
+
$this->pre_load_function();
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Create all object and shortcode
|
69 |
+
*/
|
70 |
+
function pre_load_function() {
|
71 |
+
add_action( 'init', array( $this, 'apply_rewrite_rules' ), 0 );
|
72 |
+
add_action( 'init', array( $this, 'add_rewrite_rules' ), 0 );
|
73 |
+
add_filter( 'query_vars', array( $this, 'add_query_var' ) );
|
74 |
+
add_action( 'deleted_user', array( $this, 'delete_user_wishlist' ) );
|
75 |
+
|
76 |
+
add_action( 'wp_ajax_nopriv_' . $this->_n . '_css', array( $this, 'dynaminc_css' ) );
|
77 |
+
add_action( 'wp_ajax_' . $this->_n . '_css', array( $this, 'dynaminc_css' ) );
|
78 |
+
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
79 |
+
|
80 |
+
add_filter( 'woocommerce_locate_core_template', array( $this, 'locate_template' ), 10, 3 );
|
81 |
+
add_filter( 'woocommerce_locate_template', array( $this, 'locate_template' ), 10, 3 );
|
82 |
+
|
83 |
+
$this->addto = TInvWL_Public_AddToWishlist::instance( $this->_n );
|
84 |
+
$this->view = TInvWL_Public_Wishlist_View::instance( $this->_n );
|
85 |
+
$this->cart = TInvWL_Public_Cart::instance( $this->_n );
|
86 |
+
$this->topwishlist = TInvWL_Public_TopWishlist::instance( $this->_n );
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Define hooks
|
91 |
+
*/
|
92 |
+
function define_hooks() {
|
93 |
+
if ( tinv_get_option( 'social', 'facebook' ) || tinv_get_option( 'social', 'google' ) ) {
|
94 |
+
add_filter( 'language_attributes', array( $this, 'add_ogp' ) );
|
95 |
+
add_action( 'wp_head', array( $this, 'add_meta_tags' ), 0 );
|
96 |
+
}
|
97 |
+
|
98 |
+
if ( tinv_get_option( 'general', 'link_in_myaccount' ) ) {
|
99 |
+
add_filter( 'woocommerce_account_menu_items', array( $this, 'account_menu_items' ) );
|
100 |
+
add_filter( 'woocommerce_get_endpoint_url', array( $this, 'account_menu_endpoint' ), 4, 10 );
|
101 |
+
}
|
102 |
+
|
103 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_header' ) );
|
104 |
+
add_action( 'wp_login', array( $this, 'transfert_local_to_user' ), 10, 2 );
|
105 |
+
add_action( 'user_register', array( $this, 'transfert_local_to_user_register' ) );
|
106 |
+
add_action( 'init', array( $this, 'legacy_transfer' ), 90 );
|
107 |
+
add_action( 'clear_auth_cookie', array( $this, 'set_user_sharekey' ) );
|
108 |
+
|
109 |
+
add_action( $this->_n . '_after_wishlist_table', array( $this, 'wishlist_button_action_before' ), 0 );
|
110 |
+
add_action( $this->_n . '_after_wishlist_table', array( $this, 'wishlist_button_action_after' ), 15 );
|
111 |
+
add_action( $this->_n . '_after_wishlist_table', array( $this, 'wishlist_button_updcart_before' ), 15 );
|
112 |
+
add_action( $this->_n . '_after_wishlist_table', array( $this, 'wishlist_button_action_after' ), 100 );
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Left class button
|
117 |
+
*/
|
118 |
+
function wishlist_button_action_before() {
|
119 |
+
echo '<div class="tinvwl-to-left look_in">';
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Right class button
|
124 |
+
*/
|
125 |
+
function wishlist_button_updcart_before() {
|
126 |
+
echo '<div class="tinvwl-to-right look_in">';
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Close class button
|
131 |
+
*/
|
132 |
+
function wishlist_button_action_after() {
|
133 |
+
echo '</div>';
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Register Widgets
|
138 |
+
*/
|
139 |
+
function register_widgets() {
|
140 |
+
$paths = glob( TINVWL_PATH . 'public' . DIRECTORY_SEPARATOR . 'widget' . DIRECTORY_SEPARATOR . '*.class.php' );
|
141 |
+
foreach ( $paths as $path ) {
|
142 |
+
$path = ucfirst( str_replace( '.class.php', '', basename( $path ) ) );
|
143 |
+
register_widget( 'TInvWL_Public_Widget_' . $path );
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Overwrites path for email and other template
|
149 |
+
*
|
150 |
+
* @param string $core_file Absolute path.
|
151 |
+
* @param string $template Requered Template file.
|
152 |
+
* @param string $template_base Template path.
|
153 |
+
*
|
154 |
+
* @return string
|
155 |
+
*/
|
156 |
+
function locate_template( $core_file, $template, $template_base ) {
|
157 |
+
$_core_file = tinv_wishlist_locate_template( $template );
|
158 |
+
if ( empty( $_core_file ) ) {
|
159 |
+
return $core_file;
|
160 |
+
}
|
161 |
+
|
162 |
+
return $_core_file;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Update rewrite url for wishlist
|
167 |
+
*/
|
168 |
+
public static function update_rewrite_rules() {
|
169 |
+
set_transient( '_tinvwl_rewrite_rules', 1, 30 );
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Apply rewrite url for wishlist
|
174 |
+
*/
|
175 |
+
function apply_rewrite_rules() {
|
176 |
+
if ( ! get_transient( '_tinvwl_rewrite_rules' ) ) {
|
177 |
+
return;
|
178 |
+
}
|
179 |
+
delete_transient( '_tinvwl_rewrite_rules' );
|
180 |
+
flush_rewrite_rules();
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Create rewrite url for wishlist
|
185 |
+
*/
|
186 |
+
function add_rewrite_rules() {
|
187 |
+
$id = tinv_get_option( 'page', 'wishlist' );
|
188 |
+
$pages = array( $id );
|
189 |
+
$language_codes = array();
|
190 |
+
$languages = apply_filters( 'wpml_active_languages', array(), array(
|
191 |
+
'skip_missing' => 0,
|
192 |
+
'orderby' => 'code',
|
193 |
+
) );
|
194 |
+
if ( ! empty( $languages ) ) {
|
195 |
+
foreach ( $languages as $l ) {
|
196 |
+
$pages[] = apply_filters( 'wpml_object_id', $id, 'page', true, $l['language_code'] );
|
197 |
+
$language_codes[] = $l['language_code'];
|
198 |
+
}
|
199 |
+
$pages = array_unique( $pages );
|
200 |
+
$language_codes = implode( '|', array_unique( $language_codes ) );
|
201 |
+
}
|
202 |
+
|
203 |
+
$pages = array_filter( $pages );
|
204 |
+
if ( ! empty( $pages ) ) {
|
205 |
+
foreach ( $pages as $page ) {
|
206 |
+
$page = get_post( $page );
|
207 |
+
$page_slug = $page->post_name;
|
208 |
+
|
209 |
+
if ( $language_codes && defined( 'POLYLANG_VERSION' ) ) {
|
210 |
+
add_rewrite_rule( '^(' . $language_codes . ')/(([^/]+/)*' . $page_slug . ')/([A-Fa-f0-9]{6})?/page/([0-9]{1,})/{0,1}$', 'index.php?pagename=$matches[2]&tinvwlID=$matches[4]&paged=$matches[5]&lang=$matches[1]', 'top' );
|
211 |
+
add_rewrite_rule( '^(' . $language_codes . ')/(([^/]+/)*' . $page_slug . ')/([A-Fa-f0-9]{6})?/{0,1}$', 'index.php?pagename=$matches[2]&tinvwlID=$matches[4]&paged=$matches[5]&lang=$matches[1]', 'top' );
|
212 |
+
}
|
213 |
+
|
214 |
+
add_rewrite_rule( '(([^/]+/)*' . $page_slug . ')/([A-Fa-f0-9]{6})?/page/([0-9]{1,})/{0,1}$', 'index.php?pagename=$matches[1]&tinvwlID=$matches[3]&paged=$matches[4]', 'top' );
|
215 |
+
add_rewrite_rule( '(([^/]+/)*' . $page_slug . ')/([A-Fa-f0-9]{6})?/{0,1}$', 'index.php?pagename=$matches[1]&tinvwlID=$matches[3]', 'top' );
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Add new POST variable
|
222 |
+
*
|
223 |
+
* @param array $public_var WordPress Public variable.
|
224 |
+
*
|
225 |
+
* @return array
|
226 |
+
*/
|
227 |
+
function add_query_var( $public_var ) {
|
228 |
+
$public_var[] = 'tinvwlID';
|
229 |
+
$public_var[] = 'tiws';
|
230 |
+
|
231 |
+
return $public_var;
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Create social meta tags
|
236 |
+
*/
|
237 |
+
function add_meta_tags() {
|
238 |
+
if ( is_page( apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true ) ) && ( tinv_get_option( 'social', 'facebook' ) || tinv_get_option( 'social', 'google' ) ) ) {
|
239 |
+
$wishlist = tinv_wishlist_get();
|
240 |
+
if ( 0 < $wishlist['ID'] && 'private' !== $wishlist['status'] ) {
|
241 |
+
if ( is_user_logged_in() ) {
|
242 |
+
$user = get_user_by( 'id', $wishlist['author'] );
|
243 |
+
if ( $user ) {
|
244 |
+
$user_name = trim( sprintf( '%s %s', $user->user_firstname, $user->user_lastname ) );
|
245 |
+
$user = @$user->display_name; // @codingStandardsIgnoreLine Generic.PHP.NoSilencedErrors.Discouraged
|
246 |
+
} else {
|
247 |
+
$user_name = '';
|
248 |
+
$user = '';
|
249 |
+
}
|
250 |
+
} else {
|
251 |
+
$user_name = '';
|
252 |
+
$user = '';
|
253 |
+
}
|
254 |
+
|
255 |
+
$wlp = new TInvWL_Product( $wishlist );
|
256 |
+
$products = $wlp->get_wishlist( array(
|
257 |
+
'count' => 1,
|
258 |
+
'order_by' => 'date',
|
259 |
+
'order' => 'DESC',
|
260 |
+
) );
|
261 |
+
$product = array_shift( $products );
|
262 |
+
$image = '';
|
263 |
+
if ( ! empty( $product ) && ! empty( $product['data'] ) ) {
|
264 |
+
list( $image, $width, $height, $is_intermediate ) = wp_get_attachment_image_src( $product['data']->get_image_id(), 'full' );
|
265 |
+
}
|
266 |
+
|
267 |
+
$meta = array(
|
268 |
+
'url' => tinv_url_wishlist( $wishlist['share_key'] ),
|
269 |
+
'type' => 'product.group',
|
270 |
+
'title' => sprintf( __( '%1$s of %2$s', 'ti-woocommerce-wishlist' ), $wishlist['title'], ( empty( $user_name ) ? $user : $user_name ) ),
|
271 |
+
'description' => __( 'Coming soon', 'ti-woocommerce-wishlist' ),
|
272 |
+
'image' => $image,
|
273 |
+
);
|
274 |
+
if ( tinv_get_option( 'social', 'facebook' ) ) {
|
275 |
+
foreach ( $meta as $name => $content ) {
|
276 |
+
echo sprintf( '<meta property="og:%s" content="%s" />', esc_attr( $name ), esc_attr( $content ) );
|
277 |
+
}
|
278 |
+
echo "\n";
|
279 |
+
}
|
280 |
+
if ( tinv_get_option( 'social', 'google' ) ) {
|
281 |
+
unset( $meta['url'], $meta['type'] );
|
282 |
+
foreach ( $meta as $name => $content ) {
|
283 |
+
if ( 'title' === $name ) {
|
284 |
+
$name = 'name';
|
285 |
+
}
|
286 |
+
echo sprintf( '<meta itemprop="%s" content="%s">', esc_attr( $name ), esc_attr( $content ) );
|
287 |
+
}
|
288 |
+
echo "\n";
|
289 |
+
}
|
290 |
+
} // End if().
|
291 |
+
} // End if().
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Create ogp namespace
|
296 |
+
*
|
297 |
+
* @param string $text A space-separated list of language attributes.
|
298 |
+
*
|
299 |
+
* @return string
|
300 |
+
*/
|
301 |
+
function add_ogp( $text ) {
|
302 |
+
if ( is_page( apply_filters( 'wpml_object_id', tinv_get_option( 'page', 'wishlist' ), 'page', true ) ) && tinv_get_option( 'social', 'facebook' ) ) {
|
303 |
+
$text = 'prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# product: http://ogp.me/ns/product#" itemscope itemtype="http://schema.org/Offer" ' . $text;
|
304 |
+
}
|
305 |
+
|
306 |
+
return $text;
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Check if is plugin page
|
311 |
+
*
|
312 |
+
* @return boolean
|
313 |
+
*/
|
314 |
+
function is_pluginpage() {
|
315 |
+
$pages = tinv_get_option( 'page' );
|
316 |
+
$pages = array_filter( $pages );
|
317 |
+
foreach ( $pages as $page ) {
|
318 |
+
if ( is_page( apply_filters( 'wpml_object_id', $page, 'page', true ) ) ) {
|
319 |
+
return true;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
return false;
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Load style and javascript
|
328 |
+
*/
|
329 |
+
function enqueue_header() {
|
330 |
+
if ( $this->is_pluginpage() ) {
|
331 |
+
$this->enqueue_wc_styles();
|
332 |
+
}
|
333 |
+
$this->enqueue_scripts();
|
334 |
+
$this->enqueue_styles();
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Load style
|
339 |
+
*/
|
340 |
+
function enqueue_styles() {
|
341 |
+
wp_enqueue_style( $this->_n, TINVWL_URL . 'asset/css/public.min.css', array(), $this->_v, 'all' );
|
342 |
+
if ( ! tinv_get_option( 'style', 'customstyle' ) ) {
|
343 |
+
wp_enqueue_style( $this->_n . '-theme', TINVWL_URL . 'asset/css/theme.min.css', array(), $this->_v, 'all' );
|
344 |
+
}
|
345 |
+
if ( ! tinv_get_option( 'style', 'customstyle' ) || tinv_get_option( 'style_plain', 'allow' ) ) {
|
346 |
+
wp_enqueue_style( $this->_n . '-dynaminc', admin_url( 'admin-ajax.php' ) . '?action=' . $this->_n . '_css', array( $this->_n ), $this->_v, 'all' );
|
347 |
+
}
|
348 |
+
wp_enqueue_style( $this->_n . '-font-awesome', TINVWL_URL . 'asset/css/font-awesome.min.css', array(), $this->_v, 'all' );
|
349 |
+
}
|
350 |
+
|
351 |
+
/**
|
352 |
+
* Compress CSS
|
353 |
+
*
|
354 |
+
* @param string $css CSS Content.
|
355 |
+
*
|
356 |
+
* @return string
|
357 |
+
*/
|
358 |
+
function compress_css( $css ) {
|
359 |
+
$css = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', ' ', $css );
|
360 |
+
$css = preg_replace( '/(\r|\n|\t| {2,})/', ' ', $css );
|
361 |
+
|
362 |
+
return $css;
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Generate dynaminc css
|
367 |
+
*/
|
368 |
+
function dynaminc_css() {
|
369 |
+
header( 'Content-type: text/css; charset=' . get_option( 'blog_charset' ) );
|
370 |
+
$css = get_transient( TINVWL_PREFIX . '_dynamic_' );
|
371 |
+
if ( ! $css ) {
|
372 |
+
$css = '';
|
373 |
+
if ( ! tinv_get_option( 'style', 'customstyle' ) ) {
|
374 |
+
$newcss = tinv_get_option( 'style_options', 'css' );
|
375 |
+
if ( $newcss ) {
|
376 |
+
$newcss = $this->compress_css( $newcss );
|
377 |
+
$css .= $newcss;
|
378 |
+
}
|
379 |
+
}
|
380 |
+
if ( tinv_get_option( 'style_plain', 'allow' ) ) {
|
381 |
+
$newcss = tinv_get_option( 'style_plain', 'css' );
|
382 |
+
if ( $newcss ) {
|
383 |
+
$newcss = $this->compress_css( $newcss );
|
384 |
+
$css .= $newcss;
|
385 |
+
}
|
386 |
+
}
|
387 |
+
$image_url = TINVWL_URL . 'asset/img/';
|
388 |
+
$css = str_replace( '../img/', $image_url, $css );
|
389 |
+
set_transient( TINVWL_PREFIX . '_dynamic_', $css, DAY_IN_SECONDS );
|
390 |
+
}
|
391 |
+
echo $css; // WPCS: xss ok.
|
392 |
+
die();
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Add woocommerce style
|
397 |
+
*/
|
398 |
+
function enqueue_wc_styles() {
|
399 |
+
if ( $enqueue_styles = WC_Frontend_Scripts::get_styles() ) {
|
400 |
+
foreach ( $enqueue_styles as $handle => $args ) {
|
401 |
+
wp_register_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'] );
|
402 |
+
wp_enqueue_style( $handle );
|
403 |
+
}
|
404 |
+
}
|
405 |
+
}
|
406 |
+
|
407 |
+
/**
|
408 |
+
* Load javascript
|
409 |
+
*/
|
410 |
+
function enqueue_scripts() {
|
411 |
+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
412 |
+
wp_register_script( $this->_n, TINVWL_URL . 'asset/js/public' . $suffix . '.js', array( 'jquery' ), $this->_v, true );
|
413 |
+
wp_localize_script( $this->_n, 'tinvwl_add_to_wishlist', array(
|
414 |
+
'text_create' => __( 'Create New', 'ti-woocommerce-wishlist' ),
|
415 |
+
'text_already_in' => tinv_get_option( 'general', 'text_already_in' ),
|
416 |
+
'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your wishlist.', 'ti-woocommerce-wishlist' ),
|
417 |
+
) );
|
418 |
+
wp_enqueue_script( $this->_n );
|
419 |
+
}
|
420 |
+
|
421 |
+
/**
|
422 |
+
* Load function
|
423 |
+
*/
|
424 |
+
function load_function() {
|
425 |
+
$this->define_hooks();
|
426 |
+
}
|
427 |
+
|
428 |
+
/**
|
429 |
+
* Transfer Cookie Wishlist when login user
|
430 |
+
*
|
431 |
+
* @param string $user_login Not used.
|
432 |
+
* @param object $user User object.
|
433 |
+
*
|
434 |
+
* @return boolean
|
435 |
+
*/
|
436 |
+
function transfert_local_to_user( $user_login, $user ) {
|
437 |
+
return $this->transfert_local_to_user_register( $user->ID );
|
438 |
+
}
|
439 |
+
|
440 |
+
/**
|
441 |
+
* Transfer Cookie Wishlist when register user
|
442 |
+
*
|
443 |
+
* @param integer $user_id New user id.
|
444 |
+
*/
|
445 |
+
function transfert_local_to_user_register( $user_id ) {
|
446 |
+
$wl = new TInvWL_Wishlist( $this->_n );
|
447 |
+
$wishlist = $wl->get_by_sharekey_default();
|
448 |
+
if ( ! empty( $wishlist ) ) {
|
449 |
+
$wishlist = array_shift( $wishlist );
|
450 |
+
$wlpl = new TInvWL_Product( $wishlist );
|
451 |
+
$wl->user = $user_id;
|
452 |
+
$_wishlist = $wl->get_by_user_default( $user_id );
|
453 |
+
if ( empty( $_wishlist ) ) {
|
454 |
+
$wishlist['author'] = $user_id;
|
455 |
+
unset( $wishlist['title'] );
|
456 |
+
$wl->update( $wishlist['ID'], $wishlist );
|
457 |
+
$wlp = new TInvWL_Product( $wishlist, $this->_n );
|
458 |
+
$products = $wlp->get_wishlist( array( 'external' => false ) );
|
459 |
+
foreach ( $products as $product ) {
|
460 |
+
$product['author'] = $user_id;
|
461 |
+
$wlp->update( $product );
|
462 |
+
}
|
463 |
+
} else {
|
464 |
+
$_wishlist = array_shift( $_wishlist );
|
465 |
+
if ( $wishlist['ID'] != $_wishlist['ID'] ) {
|
466 |
+
$wlp = new TInvWL_Product( $_wishlist, $this->_n );
|
467 |
+
$products = $wlpl->get_wishlist( array( 'external' => false ) );
|
468 |
+
$added = true;
|
469 |
+
foreach ( $products as $product ) {
|
470 |
+
unset( $product['author'] );
|
471 |
+
unset( $product['wishlist_id'] );
|
472 |
+
$added = $added && $wlp->add_product( $product );
|
473 |
+
}
|
474 |
+
if ( $added ) {
|
475 |
+
$wlpl->remove_product_from_wl();
|
476 |
+
}
|
477 |
+
}
|
478 |
+
$wl->set_sharekey( $_wishlist['share_key'] );
|
479 |
+
}
|
480 |
+
}
|
481 |
+
}
|
482 |
+
|
483 |
+
/**
|
484 |
+
* Set the default wishlist key if the user loguot
|
485 |
+
*/
|
486 |
+
public function set_user_sharekey() {
|
487 |
+
$wl = new TInvWL_Wishlist( $this->_n );
|
488 |
+
$wishlist = $wl->get_by_user_default();
|
489 |
+
if ( ! empty( $wishlist ) ) {
|
490 |
+
$wishlist = array_shift( $wishlist );
|
491 |
+
$wl->set_sharekey( $wishlist['share_key'] );
|
492 |
+
}
|
493 |
+
}
|
494 |
+
|
495 |
+
/**
|
496 |
+
* Add link to wishlist in WooCommerce My Account page.
|
497 |
+
*
|
498 |
+
* @param array $items Menu items links in my accounts.
|
499 |
+
*
|
500 |
+
* @return array
|
501 |
+
*/
|
502 |
+
function account_menu_items( $items ) {
|
503 |
+
$index_position = apply_filters( $this->_n . '_myaccount_position_wishlist', - 1, $items );
|
504 |
+
$items = array_merge(
|
505 |
+
array_slice( $items, 0, $index_position, true ),
|
506 |
+
array(
|
507 |
+
'tinv_wishlist' => __( 'Wishlist', 'ti-woocommerce-wishlist' ),
|
508 |
+
),
|
509 |
+
array_slice( $items, $index_position, null, true )
|
510 |
+
);
|
511 |
+
|
512 |
+
return $items;
|
513 |
+
}
|
514 |
+
|
515 |
+
/**
|
516 |
+
* Create end point for wishlist url
|
517 |
+
*
|
518 |
+
* @param string $url URL from wishlist.
|
519 |
+
* @param string $endpoint End point name.
|
520 |
+
* @param string $value Not used.
|
521 |
+
* @param string $permalink Not used.
|
522 |
+
*
|
523 |
+
* @return string
|
524 |
+
*/
|
525 |
+
function account_menu_endpoint( $url, $endpoint, $value, $permalink ) {
|
526 |
+
if ( 'tinv_wishlist' === $endpoint ) {
|
527 |
+
$url = tinv_url_wishlist_default();
|
528 |
+
}
|
529 |
+
|
530 |
+
return $url;
|
531 |
+
}
|
532 |
+
|
533 |
+
/**
|
534 |
+
* Remove Wishlist a user when the user is deleted
|
535 |
+
*
|
536 |
+
* @param integer $id Removed userid.
|
537 |
+
*/
|
538 |
+
function delete_user_wishlist( $id ) {
|
539 |
+
$wl = new TInvWL_Wishlist( $this->_n );
|
540 |
+
$wishlists = $wl->get( array(
|
541 |
+
'author' => $id,
|
542 |
+
'count' => 9999999,
|
543 |
+
) );
|
544 |
+
if ( ! empty( $wishlists ) ) {
|
545 |
+
foreach ( $wishlists as $wishlist ) {
|
546 |
+
$wl->remove( $wishlist['ID'] );
|
547 |
+
}
|
548 |
+
}
|
549 |
+
}
|
550 |
+
|
551 |
+
/**
|
552 |
+
* Export cookies wishlist to database
|
553 |
+
*/
|
554 |
+
function legacy_transfer() {
|
555 |
+
$wlpl = TInvWL_Product_Legacy::instance( $this->_n );
|
556 |
+
$products = $wlpl->get_wishlist( array( 'external' => false ) );
|
557 |
+
if ( ! empty( $products ) && is_array( $products ) ) {
|
558 |
+
$wl = new TInvWL_Wishlist( $this->_n );
|
559 |
+
$wishlist = $wl->add_user_default();
|
560 |
+
|
561 |
+
$wlp = new TInvWL_Product( $wishlist, $this->_n );
|
562 |
+
|
563 |
+
$added = true;
|
564 |
+
foreach ( $products as $product ) {
|
565 |
+
unset( $product['author'] );
|
566 |
+
if ( ! $wlp->add_product( $product ) ) {
|
567 |
+
$added = false;
|
568 |
+
}
|
569 |
+
}
|
570 |
+
if ( $added ) {
|
571 |
+
$wlpl->remove_product_from_wl();
|
572 |
+
}
|
573 |
+
}
|
574 |
+
}
|
575 |
+
}
|
public/widget/topwishlist.class.php
CHANGED
@@ -23,7 +23,7 @@ class TInvWL_Public_Widget_Topwishlist extends WC_Widget {
|
|
23 |
$this->widget_cssclass = 'tinvwl widget_wishlist_products_counter';
|
24 |
$this->widget_description = __( 'Displays the number of products in the wishlist on your site.', 'ti-woocommerce-wishlist' );
|
25 |
$this->widget_id = 'widget_top_wishlist';
|
26 |
-
$this->widget_name = __( 'Wishlist Products Counter', 'ti-woocommerce-wishlist' );
|
27 |
$this->settings = array(
|
28 |
'show_icon' => array(
|
29 |
'type' => 'checkbox',
|
23 |
$this->widget_cssclass = 'tinvwl widget_wishlist_products_counter';
|
24 |
$this->widget_description = __( 'Displays the number of products in the wishlist on your site.', 'ti-woocommerce-wishlist' );
|
25 |
$this->widget_id = 'widget_top_wishlist';
|
26 |
+
$this->widget_name = __( 'TInv Wishlist Products Counter', 'ti-woocommerce-wishlist' );
|
27 |
$this->settings = array(
|
28 |
'show_icon' => array(
|
29 |
'type' => 'checkbox',
|
public/wishlist/buttons.class.php
CHANGED
@@ -1,447 +1,451 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Action buttons for Wishlist
|
4 |
-
*
|
5 |
-
* @since 1.0.0
|
6 |
-
* @package TInvWishlist\Public
|
7 |
-
*/
|
8 |
-
|
9 |
-
// If this file is called directly, abort.
|
10 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
11 |
-
die;
|
12 |
-
}
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Action buttons for Wishlist
|
16 |
-
*/
|
17 |
-
class TInvWL_Public_Wishlist_Buttons {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Plugin name
|
21 |
-
*
|
22 |
-
* @var string
|
23 |
-
*/
|
24 |
-
static $_n;
|
25 |
-
/**
|
26 |
-
* Basic event
|
27 |
-
*
|
28 |
-
* @var string
|
29 |
-
*/
|
30 |
-
static $event;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* First run function
|
34 |
-
*
|
35 |
-
* @param string $plugin_name Plugin name.
|
36 |
-
*/
|
37 |
-
public static function init( $plugin_name = TINVWL_PREFIX ) {
|
38 |
-
self::$_n = $plugin_name;
|
39 |
-
self::$event = 'tinvwl_after_wishlist_table';
|
40 |
-
self::htmloutput();
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Defined buttons
|
45 |
-
*
|
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(
|
52 |
-
'name' => 'product_apply',
|
53 |
-
'title' => sprintf( __( 'Apply %s', 'ti-woocommerce-wishlist' ), "<span class='tinvwl-mobile'>" . __( 'Action', 'ti-woocommerce-wishlist' ) . '</span>' ),
|
54 |
-
'method' => array( __CLASS__, 'apply_action' ),
|
55 |
-
'before' => array( __CLASS__, 'apply_action_before' ),
|
56 |
-
'priority' => 10,
|
57 |
-
'condition' => '$a["is_owner"]',
|
58 |
-
);
|
59 |
-
add_filter( self::$_n . '_prepare_attr__button_product_apply', array( __CLASS__, 'add_break_class_input' ) );
|
60 |
-
add_filter( self::$_n . '_prepare_attr__button_product_apply', array( __CLASS__, 'add_break_class_checkbox' ) );
|
61 |
-
}
|
62 |
-
if ( tinv_get_option( 'table', 'colm_checkbox' ) && tinv_get_option( 'table', 'add_select_to_cart' ) ) {
|
63 |
-
$buttons[] = array(
|
64 |
-
'name' => 'product_selected',
|
65 |
-
'title' => tinv_get_option( 'table', 'text_add_select_to_cart' ),
|
66 |
-
'method' => array( __CLASS__, 'apply_action_add_selected' ),
|
67 |
-
'priority' => 25,
|
68 |
-
);
|
69 |
-
add_filter( self::$_n . '_prepare_attr__button_product_selected', array( __CLASS__, 'add_break_class_checkbox' ) );
|
70 |
-
}
|
71 |
-
if ( tinv_get_option( 'table', 'add_all_to_cart' ) ) {
|
72 |
-
$buttons[] = array(
|
73 |
-
'name' => 'product_all',
|
74 |
-
'title' => tinv_get_option( 'table', 'text_add_all_to_cart' ),
|
75 |
-
'method' => array( __CLASS__, 'add_all' ),
|
76 |
-
'priority' => 30,
|
77 |
-
);
|
78 |
-
add_filter( self::$_n . '_prepare_attr__button_product_selected', array( __CLASS__, 'class_action' ) );
|
79 |
-
add_filter( self::$_n . '_prepare_attr__button_product_all', array( __CLASS__, 'class_action' ) );
|
80 |
-
}
|
81 |
-
$buttons = apply_filters( 'tinvwl_manage_buttons_create', $buttons );
|
82 |
-
return $buttons;
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Output buttons
|
87 |
-
*/
|
88 |
-
public static function htmloutput() {
|
89 |
-
$buttons = self::prepare();
|
90 |
-
foreach ( $buttons as $button ) {
|
91 |
-
self::addbutton( $button );
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Add break class
|
97 |
-
*
|
98 |
-
* @param array $attr Attributes.
|
99 |
-
* @return array
|
100 |
-
*/
|
101 |
-
public static function add_break_class_input( $attr ) {
|
102 |
-
if ( array_key_exists( 'class', $attr ) ) {
|
103 |
-
$attr['class'] .= ' tinvwl-break-input';
|
104 |
-
} else {
|
105 |
-
$attr['class'] = 'tinvwl-break-input';
|
106 |
-
}
|
107 |
-
return $attr;
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Add break class
|
112 |
-
*
|
113 |
-
* @param array $attr Attributes.
|
114 |
-
* @return array
|
115 |
-
*/
|
116 |
-
public static function add_break_class_checkbox( $attr ) {
|
117 |
-
if ( array_key_exists( 'class', $attr ) ) {
|
118 |
-
$attr['class'] .= ' tinvwl-break-checkbox';
|
119 |
-
} else {
|
120 |
-
$attr['class'] = 'tinvwl-break-checkbox';
|
121 |
-
}
|
122 |
-
return $attr;
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Create button and action
|
127 |
-
*
|
128 |
-
* @param array $button Structure for button.
|
129 |
-
* @return boolean
|
130 |
-
*/
|
131 |
-
public static function addbutton( $button ) {
|
132 |
-
if ( ! array_key_exists( 'name', $button ) ) {
|
133 |
-
return false;
|
134 |
-
}
|
135 |
-
if ( ! array_key_exists( 'priority', $button ) ) {
|
136 |
-
$button['priority'] = 10;
|
137 |
-
}
|
138 |
-
if ( ! array_key_exists( 'method', $button ) ) {
|
139 |
-
$button['method'] = array( __CLASS__, 'null_action' );
|
140 |
-
}
|
141 |
-
if ( ! array_key_exists( 'event', $button ) ) {
|
142 |
-
$button['event'] = self::$event;
|
143 |
-
}
|
144 |
-
if ( ! array_key_exists( 'condition', $button ) ) {
|
145 |
-
$button['condition'] = 'true';
|
146 |
-
}
|
147 |
-
if ( array_key_exists( 'submit', $button ) ) {
|
148 |
-
$button['submit'] = $button['submit'] ? 'submit' : 'button';
|
149 |
-
} else {
|
150 |
-
$button['submit'] = 'submit';
|
151 |
-
}
|
152 |
-
|
153 |
-
if ( array_key_exists( 'before', $button ) ) {
|
154 |
-
add_filter( self::$_n . '_before__button_' . $button['name'], $button['before'] );
|
155 |
-
}
|
156 |
-
if ( array_key_exists( 'after', $button ) ) {
|
157 |
-
add_filter( self::$_n . '_after__button_' . $button['name'], $button['after'] );
|
158 |
-
}
|
159 |
-
|
160 |
-
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
|
161 |
-
add_action( 'tinvwl_action_' . $button['name'], $button['method'], 10, 4 );
|
162 |
-
}
|
163 |
-
|
164 |
-
/**
|
165 |
-
* Create html button
|
166 |
-
*
|
167 |
-
* @param string $value Vaule for tinvwl-action.
|
168 |
-
* @param string $title HTML title for button.
|
169 |
-
* @param string $submit Type button.
|
170 |
-
* @param boolean $echo Retun or echo.
|
171 |
-
* @return string
|
172 |
-
*/
|
173 |
-
public static function button( $value, $title, $submit, $echo = true ) {
|
174 |
-
$html = apply_filters( self::$_n . '_before__button_' . $value, '' );
|
175 |
-
$attr = array(
|
176 |
-
'type' => $submit,
|
177 |
-
'class' => 'button',
|
178 |
-
'name' => 'tinvwl-action',
|
179 |
-
'value' => $value,
|
180 |
-
);
|
181 |
-
$attr = apply_filters( self::$_n . '_prepare_attr__button_' . $value, $attr );
|
182 |
-
foreach ( $attr as $key => &$value ) {
|
183 |
-
$value = sprintf( '%s="%s"', $key, esc_attr( $value ) );
|
184 |
-
}
|
185 |
-
$attr = implode( ' ', $attr );
|
186 |
-
|
187 |
-
$html .= apply_filters( self::$_n . '__button_' . $value, sprintf( '<button %s>%s</button>', $attr, $title ) );
|
188 |
-
$html .= apply_filters( self::$_n . '_after__button_' . $value, '' );
|
189 |
-
|
190 |
-
if ( $echo ) {
|
191 |
-
echo $html; // WPCS: xss ok.
|
192 |
-
} else {
|
193 |
-
return $html;
|
194 |
-
}
|
195 |
-
}
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Default action for button
|
199 |
-
*
|
200 |
-
* @return boolean
|
201 |
-
*/
|
202 |
-
public static function null_action() {
|
203 |
-
return false;
|
204 |
-
}
|
205 |
-
|
206 |
-
/**
|
207 |
-
* Add class 'alt' to button
|
208 |
-
*
|
209 |
-
* @param array $attr Attributes for button.
|
210 |
-
* @return array
|
211 |
-
*/
|
212 |
-
public static function class_action( $attr ) {
|
213 |
-
if ( array_key_exists( 'class', $attr ) ) {
|
214 |
-
$attr['class'] .= ' alt';
|
215 |
-
} else {
|
216 |
-
$attr['class'] = 'alt';
|
217 |
-
}
|
218 |
-
return $attr;
|
219 |
-
}
|
220 |
-
|
221 |
-
/**
|
222 |
-
* Apply action for product_all
|
223 |
-
*
|
224 |
-
* @param array $wishlist Wishlist object.
|
225 |
-
* @param array $selected Not used.
|
226 |
-
* @param array $_quantity Not used.
|
227 |
-
* @param boolean $owner Owner this wishlist.
|
228 |
-
* @return boolean
|
229 |
-
*/
|
230 |
-
public static function add_all( $wishlist, $selected = array(), $_quantity = array(), $owner = false ) {
|
231 |
-
$products = self::get_current_products( $wishlist );
|
232 |
-
$result = $errors = array();
|
233 |
-
foreach ( $products as $product ) {
|
234 |
-
$product_data = wc_get_product( $product['variation_id'] ? $product['variation_id'] : $product['product_id'] );
|
235 |
-
|
236 |
-
add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
|
237 |
-
$redirect_url = $product_data->add_to_cart_url();
|
238 |
-
remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
|
239 |
-
|
240 |
-
if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $product_data, $redirect_url, $product ) ) {
|
241 |
-
$errors[] = $product['product_id'];
|
242 |
-
continue;
|
243 |
-
}
|
244 |
-
$product = $product['ID'];
|
245 |
-
$quantity = array_key_exists( $product, (array) $_quantity ) ? $_quantity[ $product ] : 1;
|
246 |
-
$add = TInvWL_Public_Cart::add( $wishlist, $product, $quantity );
|
247 |
-
if ( $add ) {
|
248 |
-
$result = tinv_array_merge( $result, $add );
|
249 |
-
}
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
*
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
*
|
287 |
-
*
|
288 |
-
* @param array $
|
289 |
-
* @param
|
290 |
-
* @
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
*
|
311 |
-
*
|
312 |
-
* @param array $
|
313 |
-
* @param
|
314 |
-
* @
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
$wlp =
|
325 |
-
}
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
$titles =
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
}
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
*
|
366 |
-
*
|
367 |
-
* @
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
if (
|
375 |
-
|
376 |
-
}
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
}
|
398 |
-
|
399 |
-
if ( !
|
400 |
-
|
401 |
-
}
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
if (
|
418 |
-
|
419 |
-
}
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Action buttons for Wishlist
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
* @package TInvWishlist\Public
|
7 |
+
*/
|
8 |
+
|
9 |
+
// If this file is called directly, abort.
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
11 |
+
die;
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Action buttons for Wishlist
|
16 |
+
*/
|
17 |
+
class TInvWL_Public_Wishlist_Buttons {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Plugin name
|
21 |
+
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
static $_n;
|
25 |
+
/**
|
26 |
+
* Basic event
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
static $event;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* First run function
|
34 |
+
*
|
35 |
+
* @param string $plugin_name Plugin name.
|
36 |
+
*/
|
37 |
+
public static function init( $plugin_name = TINVWL_PREFIX ) {
|
38 |
+
self::$_n = $plugin_name;
|
39 |
+
self::$event = 'tinvwl_after_wishlist_table';
|
40 |
+
self::htmloutput();
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Defined buttons
|
45 |
+
*
|
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(
|
52 |
+
'name' => 'product_apply',
|
53 |
+
'title' => sprintf( __( 'Apply %s', 'ti-woocommerce-wishlist' ), "<span class='tinvwl-mobile'>" . __( 'Action', 'ti-woocommerce-wishlist' ) . '</span>' ),
|
54 |
+
'method' => array( __CLASS__, 'apply_action' ),
|
55 |
+
'before' => array( __CLASS__, 'apply_action_before' ),
|
56 |
+
'priority' => 10,
|
57 |
+
'condition' => '$a["is_owner"]',
|
58 |
+
);
|
59 |
+
add_filter( self::$_n . '_prepare_attr__button_product_apply', array( __CLASS__, 'add_break_class_input' ) );
|
60 |
+
add_filter( self::$_n . '_prepare_attr__button_product_apply', array( __CLASS__, 'add_break_class_checkbox' ) );
|
61 |
+
}
|
62 |
+
if ( tinv_get_option( 'table', 'colm_checkbox' ) && tinv_get_option( 'table', 'add_select_to_cart' ) ) {
|
63 |
+
$buttons[] = array(
|
64 |
+
'name' => 'product_selected',
|
65 |
+
'title' => tinv_get_option( 'table', 'text_add_select_to_cart' ),
|
66 |
+
'method' => array( __CLASS__, 'apply_action_add_selected' ),
|
67 |
+
'priority' => 25,
|
68 |
+
);
|
69 |
+
add_filter( self::$_n . '_prepare_attr__button_product_selected', array( __CLASS__, 'add_break_class_checkbox' ) );
|
70 |
+
}
|
71 |
+
if ( tinv_get_option( 'table', 'add_all_to_cart' ) ) {
|
72 |
+
$buttons[] = array(
|
73 |
+
'name' => 'product_all',
|
74 |
+
'title' => tinv_get_option( 'table', 'text_add_all_to_cart' ),
|
75 |
+
'method' => array( __CLASS__, 'add_all' ),
|
76 |
+
'priority' => 30,
|
77 |
+
);
|
78 |
+
add_filter( self::$_n . '_prepare_attr__button_product_selected', array( __CLASS__, 'class_action' ) );
|
79 |
+
add_filter( self::$_n . '_prepare_attr__button_product_all', array( __CLASS__, 'class_action' ) );
|
80 |
+
}
|
81 |
+
$buttons = apply_filters( 'tinvwl_manage_buttons_create', $buttons );
|
82 |
+
return $buttons;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Output buttons
|
87 |
+
*/
|
88 |
+
public static function htmloutput() {
|
89 |
+
$buttons = self::prepare();
|
90 |
+
foreach ( $buttons as $button ) {
|
91 |
+
self::addbutton( $button );
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Add break class
|
97 |
+
*
|
98 |
+
* @param array $attr Attributes.
|
99 |
+
* @return array
|
100 |
+
*/
|
101 |
+
public static function add_break_class_input( $attr ) {
|
102 |
+
if ( array_key_exists( 'class', $attr ) ) {
|
103 |
+
$attr['class'] .= ' tinvwl-break-input';
|
104 |
+
} else {
|
105 |
+
$attr['class'] = 'tinvwl-break-input';
|
106 |
+
}
|
107 |
+
return $attr;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Add break class
|
112 |
+
*
|
113 |
+
* @param array $attr Attributes.
|
114 |
+
* @return array
|
115 |
+
*/
|
116 |
+
public static function add_break_class_checkbox( $attr ) {
|
117 |
+
if ( array_key_exists( 'class', $attr ) ) {
|
118 |
+
$attr['class'] .= ' tinvwl-break-checkbox';
|
119 |
+
} else {
|
120 |
+
$attr['class'] = 'tinvwl-break-checkbox';
|
121 |
+
}
|
122 |
+
return $attr;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Create button and action
|
127 |
+
*
|
128 |
+
* @param array $button Structure for button.
|
129 |
+
* @return boolean
|
130 |
+
*/
|
131 |
+
public static function addbutton( $button ) {
|
132 |
+
if ( ! array_key_exists( 'name', $button ) ) {
|
133 |
+
return false;
|
134 |
+
}
|
135 |
+
if ( ! array_key_exists( 'priority', $button ) ) {
|
136 |
+
$button['priority'] = 10;
|
137 |
+
}
|
138 |
+
if ( ! array_key_exists( 'method', $button ) ) {
|
139 |
+
$button['method'] = array( __CLASS__, 'null_action' );
|
140 |
+
}
|
141 |
+
if ( ! array_key_exists( 'event', $button ) ) {
|
142 |
+
$button['event'] = self::$event;
|
143 |
+
}
|
144 |
+
if ( ! array_key_exists( 'condition', $button ) ) {
|
145 |
+
$button['condition'] = 'true';
|
146 |
+
}
|
147 |
+
if ( array_key_exists( 'submit', $button ) ) {
|
148 |
+
$button['submit'] = $button['submit'] ? 'submit' : 'button';
|
149 |
+
} else {
|
150 |
+
$button['submit'] = 'submit';
|
151 |
+
}
|
152 |
+
|
153 |
+
if ( array_key_exists( 'before', $button ) ) {
|
154 |
+
add_filter( self::$_n . '_before__button_' . $button['name'], $button['before'] );
|
155 |
+
}
|
156 |
+
if ( array_key_exists( 'after', $button ) ) {
|
157 |
+
add_filter( self::$_n . '_after__button_' . $button['name'], $button['after'] );
|
158 |
+
}
|
159 |
+
|
160 |
+
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
|
161 |
+
add_action( 'tinvwl_action_' . $button['name'], $button['method'], 10, 4 );
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Create html button
|
166 |
+
*
|
167 |
+
* @param string $value Vaule for tinvwl-action.
|
168 |
+
* @param string $title HTML title for button.
|
169 |
+
* @param string $submit Type button.
|
170 |
+
* @param boolean $echo Retun or echo.
|
171 |
+
* @return string
|
172 |
+
*/
|
173 |
+
public static function button( $value, $title, $submit, $echo = true ) {
|
174 |
+
$html = apply_filters( self::$_n . '_before__button_' . $value, '' );
|
175 |
+
$attr = array(
|
176 |
+
'type' => $submit,
|
177 |
+
'class' => 'button',
|
178 |
+
'name' => 'tinvwl-action',
|
179 |
+
'value' => $value,
|
180 |
+
);
|
181 |
+
$attr = apply_filters( self::$_n . '_prepare_attr__button_' . $value, $attr );
|
182 |
+
foreach ( $attr as $key => &$value ) {
|
183 |
+
$value = sprintf( '%s="%s"', $key, esc_attr( $value ) );
|
184 |
+
}
|
185 |
+
$attr = implode( ' ', $attr );
|
186 |
+
|
187 |
+
$html .= apply_filters( self::$_n . '__button_' . $value, sprintf( '<button %s>%s</button>', $attr, $title ) );
|
188 |
+
$html .= apply_filters( self::$_n . '_after__button_' . $value, '' );
|
189 |
+
|
190 |
+
if ( $echo ) {
|
191 |
+
echo $html; // WPCS: xss ok.
|
192 |
+
} else {
|
193 |
+
return $html;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Default action for button
|
199 |
+
*
|
200 |
+
* @return boolean
|
201 |
+
*/
|
202 |
+
public static function null_action() {
|
203 |
+
return false;
|
204 |
+
}
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Add class 'alt' to button
|
208 |
+
*
|
209 |
+
* @param array $attr Attributes for button.
|
210 |
+
* @return array
|
211 |
+
*/
|
212 |
+
public static function class_action( $attr ) {
|
213 |
+
if ( array_key_exists( 'class', $attr ) ) {
|
214 |
+
$attr['class'] .= ' alt';
|
215 |
+
} else {
|
216 |
+
$attr['class'] = 'alt';
|
217 |
+
}
|
218 |
+
return $attr;
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Apply action for product_all
|
223 |
+
*
|
224 |
+
* @param array $wishlist Wishlist object.
|
225 |
+
* @param array $selected Not used.
|
226 |
+
* @param array $_quantity Not used.
|
227 |
+
* @param boolean $owner Owner this wishlist.
|
228 |
+
* @return boolean
|
229 |
+
*/
|
230 |
+
public static function add_all( $wishlist, $selected = array(), $_quantity = array(), $owner = false ) {
|
231 |
+
$products = self::get_current_products( $wishlist );
|
232 |
+
$result = $errors = array();
|
233 |
+
foreach ( $products as $product ) {
|
234 |
+
$product_data = wc_get_product( $product['variation_id'] ? $product['variation_id'] : $product['product_id'] );
|
235 |
+
|
236 |
+
add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
|
237 |
+
$redirect_url = $product_data->add_to_cart_url();
|
238 |
+
remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
|
239 |
+
|
240 |
+
if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $product_data, $redirect_url, $product ) ) {
|
241 |
+
$errors[] = $product['product_id'];
|
242 |
+
continue;
|
243 |
+
}
|
244 |
+
$product = $product['ID'];
|
245 |
+
$quantity = array_key_exists( $product, (array) $_quantity ) ? $_quantity[ $product ] : 1;
|
246 |
+
$add = TInvWL_Public_Cart::add( $wishlist, $product, $quantity );
|
247 |
+
if ( $add ) {
|
248 |
+
$result = tinv_array_merge( $result, $add );
|
249 |
+
} else {
|
250 |
+
$errors[] = $product['product_id'];
|
251 |
+
}
|
252 |
+
}
|
253 |
+
if ( ! empty( $errors ) ) {
|
254 |
+
$titles = array();
|
255 |
+
foreach ( $errors as $product_id ) {
|
256 |
+
$titles[] = sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) );
|
257 |
+
}
|
258 |
+
$titles = array_filter( $titles );
|
259 |
+
wc_add_notice( sprintf( _n( 'Product %s could not be added to cart because some options are not specified. Please, select some product options before adding the products to your cart.', 'Products: %s could not be added to cart because some options are not specified. Please, select some product options before adding the products to your cart.', count( $titles ), 'ti-woocommerce-wishlist' ), wc_format_list_of_items( $titles ) ), 'error' );
|
260 |
+
}
|
261 |
+
if ( ! empty( $result ) ) {
|
262 |
+
wc_add_to_cart_message( $result, true );
|
263 |
+
return true;
|
264 |
+
}
|
265 |
+
return false;
|
266 |
+
}
|
267 |
+
|
268 |
+
/**
|
269 |
+
* Create select for custom action
|
270 |
+
*
|
271 |
+
* @return string
|
272 |
+
*/
|
273 |
+
public static function apply_action_before() {
|
274 |
+
$options = array(
|
275 |
+
'' => __( 'Actions', 'ti-woocommerce-wishlist' ),
|
276 |
+
'add_selected' => tinv_get_option( 'product_table', 'text_add_to_cart' ),
|
277 |
+
);
|
278 |
+
$wishlist_curent = tinv_wishlist_get();
|
279 |
+
if ( $wishlist_curent['is_owner'] ) {
|
280 |
+
$options['remove'] = __( 'Remove', 'ti-woocommerce-wishlist' );
|
281 |
+
}
|
282 |
+
return TInvWL_Form::_select( 'product_actions', '', array( 'class' => 'tinvwl-break-input-filed' ), $options );
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Apply action for product_actions
|
287 |
+
*
|
288 |
+
* @param array $wishlist Wishlist object.
|
289 |
+
* @param array $selected Array selected products.
|
290 |
+
* @param array $_quantity Array quantity products.
|
291 |
+
* @param boolean $owner Owner this wishlist.
|
292 |
+
* @return boolean
|
293 |
+
*/
|
294 |
+
public static function apply_action( $wishlist, $selected = array(), $_quantity = array(), $owner = false ) {
|
295 |
+
if ( empty( $selected ) || ! is_array( $selected ) ) {
|
296 |
+
return false;
|
297 |
+
}
|
298 |
+
$action = filter_input( INPUT_POST, 'product_actions', FILTER_SANITIZE_STRING );
|
299 |
+
switch ( $action ) {
|
300 |
+
case 'add_selected':
|
301 |
+
self::apply_action_add_selected( $wishlist, $selected, $_quantity, $owner );
|
302 |
+
break;
|
303 |
+
case 'remove':
|
304 |
+
self::apply_action_remove( $wishlist, $selected, $_quantity, $owner );
|
305 |
+
break;
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Apply action for product_actions add_selected
|
311 |
+
*
|
312 |
+
* @param array $wishlist Wishlist object.
|
313 |
+
* @param array $selected Array selected products.
|
314 |
+
* @param array $_quantity Array quantity products.
|
315 |
+
* @param boolean $owner Owner this wishlist.
|
316 |
+
* @return boolean
|
317 |
+
*/
|
318 |
+
public static function apply_action_add_selected( $wishlist, $selected = array(), $_quantity = array(), $owner = false ) {
|
319 |
+
if ( ! empty( $selected ) ) {
|
320 |
+
$result = $errors = array();
|
321 |
+
foreach ( $selected as $product ) {
|
322 |
+
$wlp = null;
|
323 |
+
if ( 0 === $wishlist['ID'] ) {
|
324 |
+
$wlp = TInvWL_Product_Local::instance();
|
325 |
+
} else {
|
326 |
+
$wlp = new TInvWL_Product( $wishlist );
|
327 |
+
}
|
328 |
+
$_product = $wlp->get_wishlist( array( 'ID' => $product ) );
|
329 |
+
$_product = array_shift( $_product );
|
330 |
+
if ( ! empty( $_product ) && ! empty( $_product['data'] ) ) {
|
331 |
+
add_filter( 'clean_url', 'tinvwl_clean_url', 10, 2 );
|
332 |
+
$redirect_url = $_product['data']->add_to_cart_url();
|
333 |
+
remove_filter( 'clean_url', 'tinvwl_clean_url', 10 );
|
334 |
+
|
335 |
+
if ( apply_filters( 'tinvwl_product_add_to_cart_need_redirect', false, $_product['data'], $redirect_url, $_product ) ) {
|
336 |
+
$errors[] = $_product['product_id'];
|
337 |
+
continue;
|
338 |
+
}
|
339 |
+
}
|
340 |
+
$quantity = array_key_exists( $product, (array) $_quantity ) ? $_quantity[ $product ] : 1;
|
341 |
+
$add = TInvWL_Public_Cart::add( $wishlist, $product, $quantity );
|
342 |
+
if ( $add ) {
|
343 |
+
$result = tinv_array_merge( $result, $add );
|
344 |
+
} else {
|
345 |
+
$errors[] = $product['product_id'];
|
346 |
+
}
|
347 |
+
}
|
348 |
+
if ( ! empty( $errors ) ) {
|
349 |
+
$titles = array();
|
350 |
+
foreach ( $errors as $product_id ) {
|
351 |
+
$titles[] = sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) );
|
352 |
+
}
|
353 |
+
$titles = array_filter( $titles );
|
354 |
+
wc_add_notice( sprintf( _n( 'Product %s could not be added to cart because some options are not specified. Please, select some product options before adding the products to your cart.', 'Products: %s could not be added to cart because some options are not specified. Please, select some product options before adding the products to your cart.', count( $titles ), 'ti-woocommerce-wishlist' ), wc_format_list_of_items( $titles ) ), 'error' );
|
355 |
+
}
|
356 |
+
if ( ! empty( $result ) ) {
|
357 |
+
wc_add_to_cart_message( $result, true );
|
358 |
+
return true;
|
359 |
+
}
|
360 |
+
} // End if().
|
361 |
+
return false;
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* Apply action for product_actions remove
|
366 |
+
*
|
367 |
+
* @param array $wishlist Wishlist object.
|
368 |
+
* @param array $selected Array selected products.
|
369 |
+
* @param array $_quantity Not used.
|
370 |
+
* @param boolean $owner Owner this wishlist.
|
371 |
+
* @return boolean
|
372 |
+
*/
|
373 |
+
public static function apply_action_remove( $wishlist, $selected = array(), $_quantity = array(), $owner = false ) {
|
374 |
+
if ( ! $owner ) {
|
375 |
+
return false;
|
376 |
+
}
|
377 |
+
$wlp = null;
|
378 |
+
if ( 0 === $wishlist['ID'] ) {
|
379 |
+
$wlp = TInvWL_Product_Local::instance( self::$_n );
|
380 |
+
} else {
|
381 |
+
$wlp = new TInvWL_Product( $wishlist, self::$_n );
|
382 |
+
}
|
383 |
+
if ( empty( $wlp ) ) {
|
384 |
+
return false;
|
385 |
+
}
|
386 |
+
|
387 |
+
$products = $wlp->get_wishlist( array(
|
388 |
+
'ID' => $selected,
|
389 |
+
'count' => 100,
|
390 |
+
) );
|
391 |
+
|
392 |
+
$titles = array();
|
393 |
+
foreach ( $products as $product ) {
|
394 |
+
if ( $wlp->remove_product_from_wl( $product['wishlist_id'], $product['product_id'], $product['variation_id'], $product['meta'] ) ) {
|
395 |
+
$titles[] = sprintf( __( '“%s”', 'ti-woocommerce-wishlist' ), $product['data']->get_title() );
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
if ( ! empty( $titles ) ) {
|
400 |
+
wc_add_notice( sprintf( _n( '%s has been successfully removed from wishlist.', '%s have been successfully removed from wishlist.', count( $titles ), 'ti-woocommerce-wishlist' ), wc_format_list_of_items( $titles ) ) );
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( ! is_user_logged_in() && ! empty( $titles2 ) ) {
|
404 |
+
wp_safe_redirect( tinv_url_wishlist() );
|
405 |
+
}
|
406 |
+
|
407 |
+
return true;
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Get product bu wishlist
|
412 |
+
*
|
413 |
+
* @param array $wishlist Wishlist object.
|
414 |
+
* @return array
|
415 |
+
*/
|
416 |
+
public static function get_current_products( $wishlist = null ) {
|
417 |
+
if ( empty( $wishlist ) ) {
|
418 |
+
return array();
|
419 |
+
}
|
420 |
+
$wlp = null;
|
421 |
+
if ( 0 === $wishlist['ID'] ) {
|
422 |
+
$wlp = TInvWL_Product_Local::instance();
|
423 |
+
} else {
|
424 |
+
$wlp = new TInvWL_Product( $wishlist );
|
425 |
+
}
|
426 |
+
if ( empty( $wlp ) ) {
|
427 |
+
return array();
|
428 |
+
}
|
429 |
+
|
430 |
+
$paged = get_query_var( 'paged', 1 );
|
431 |
+
$paged = 1 < $paged ? $paged : 1;
|
432 |
+
$per_page = apply_filters( 'tinvwl_wishlist_buttons_per_page', filter_input( INPUT_POST, 'lists_per_page', FILTER_VALIDATE_INT, array(
|
433 |
+
'options' => array(
|
434 |
+
'default' => 10,
|
435 |
+
'min_range' => 1,
|
436 |
+
),
|
437 |
+
) ) );
|
438 |
+
|
439 |
+
$product_data = array(
|
440 |
+
'count' => $per_page,
|
441 |
+
'offset' => $per_page * ($paged - 1),
|
442 |
+
'external' => false,
|
443 |
+
);
|
444 |
+
|
445 |
+
$product_data = apply_filters( 'tinvwl_before_get_current_product', $product_data );
|
446 |
+
$products = $wlp->get_wishlist( $product_data );
|
447 |
+
$products = apply_filters( 'tinvwl_after_get_current_product', $products );
|
448 |
+
|
449 |
+
return $products;
|
450 |
+
}
|
451 |
+
}
|
public/wishlist/view.class.php
CHANGED
@@ -188,7 +188,7 @@ class TInvWL_Public_Wishlist_View {
|
|
188 |
return false;
|
189 |
}
|
190 |
|
191 |
-
$is_owner = get_current_user_id() === $wishlist['author'];
|
192 |
$nonce = filter_input( INPUT_POST, 'wishlist_nonce' );
|
193 |
if ( $nonce && wp_verify_nonce( $nonce, 'tinvwl_wishlist_owner' ) && $is_owner ) {
|
194 |
do_action( 'tinvwl_before_action_owner', $wishlist );
|
188 |
return false;
|
189 |
}
|
190 |
|
191 |
+
$is_owner = is_user_logged_in() ? ( get_current_user_id() === $wishlist['author'] ) : $wishlist['is_owner'];
|
192 |
$nonce = filter_input( INPUT_POST, 'wishlist_nonce' );
|
193 |
if ( $nonce && wp_verify_nonce( $nonce, 'tinvwl_wishlist_owner' ) && $is_owner ) {
|
194 |
do_action( 'tinvwl_before_action_owner', $wishlist );
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://templateinvaders.com/?utm_source=wordpressorg&utm_content=d
|
|
4 |
Tags: wishlist, woocommerce, products, e-commerce, shop, ecommerce wishlist, woocommerce wishlist, woocommerce , shop wishlist, wishlist for Woocommerce
|
5 |
Requires at least: 4.5
|
6 |
Tested up to: 4.8
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GPLv3
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -129,6 +129,17 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
|
|
129 |
|
130 |
== Changelog ==
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
= 1.5.5 =
|
133 |
*Release Date - 11 September 2017*
|
134 |
|
4 |
Tags: wishlist, woocommerce, products, e-commerce, shop, ecommerce wishlist, woocommerce wishlist, woocommerce , shop wishlist, wishlist for Woocommerce
|
5 |
Requires at least: 4.5
|
6 |
Tested up to: 4.8
|
7 |
+
Stable tag: 1.5.6
|
8 |
License: GPLv3
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
129 |
|
130 |
== Changelog ==
|
131 |
|
132 |
+
= 1.5.6 =
|
133 |
+
*Release Date - 20 September 2017*
|
134 |
+
|
135 |
+
* Fixed an issue with transferring products between guest and customer wishlists after signing in or logout.
|
136 |
+
* Fixed an issue when it's not possible to remove products from wishlist as a guest
|
137 |
+
* Fixed an issue with adding a product variations to wishlist
|
138 |
+
* Improved WooCommerce Product Bundles plugin support:
|
139 |
+
* Fixed an issue with displaying product custom meta attributes
|
140 |
+
* Improved WPML plugin compatibility:
|
141 |
+
* Fixed an issue with "Remove/Add" button text when switching languages
|
142 |
+
|
143 |
= 1.5.5 =
|
144 |
*Release Date - 11 September 2017*
|
145 |
|
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.5.
|
8 |
* Author: TemplateInvaders
|
9 |
* Author URI: https://templateinvaders.com/
|
10 |
* License: GPL-2.0+
|
@@ -37,7 +37,7 @@ if ( ! defined( 'TINVWL_DOMAIN' ) ) {
|
|
37 |
}
|
38 |
|
39 |
if ( ! defined( 'TINVWL_FVERSION' ) ) {
|
40 |
-
define( 'TINVWL_FVERSION', '1.5.
|
41 |
}
|
42 |
|
43 |
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.5.6
|
8 |
* Author: TemplateInvaders
|
9 |
* Author URI: https://templateinvaders.com/
|
10 |
* License: GPL-2.0+
|
37 |
}
|
38 |
|
39 |
if ( ! defined( 'TINVWL_FVERSION' ) ) {
|
40 |
+
define( 'TINVWL_FVERSION', '1.5.6' );
|
41 |
}
|
42 |
|
43 |
if ( ! defined( 'TINVWL_LOAD_FREE' ) ) {
|
tinv-wishlists-function-integration.php
CHANGED
@@ -302,6 +302,66 @@ if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare' ) ) {
|
|
302 |
add_filter( 'tinvwl_addtowishlist_prepare', 'tinvwl_wpml_addtowishlist_prepare' );
|
303 |
}
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare_form' ) ) {
|
306 |
|
307 |
/**
|
@@ -734,6 +794,49 @@ if ( ! function_exists( 'tinvwl_row_woocommerce_composite_products' ) ) {
|
|
734 |
add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_composite_products', 10, 2 );
|
735 |
} // End if().
|
736 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
737 |
if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_bundles' ) ) {
|
738 |
|
739 |
/**
|
@@ -745,9 +848,8 @@ if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_bundles'
|
|
745 |
* @return array
|
746 |
*/
|
747 |
function tinv_wishlist_metasupport_woocommerce_product_bundles( $meta, $product_id ) {
|
748 |
-
$
|
749 |
-
|
750 |
-
if ( array_key_exists( $bundled_item_quantity_request_key, $meta ) ) {
|
751 |
$meta = array();
|
752 |
}
|
753 |
|
302 |
add_filter( 'tinvwl_addtowishlist_prepare', 'tinvwl_wpml_addtowishlist_prepare' );
|
303 |
}
|
304 |
|
305 |
+
if ( ! function_exists( 'tinvwl_wpml_addtowishlist_out_prepare' ) ) {
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Change product data if product need translate in WooCommerce Multilingual
|
309 |
+
*
|
310 |
+
* @param array $attr Data for wishlist.
|
311 |
+
*
|
312 |
+
* @return array
|
313 |
+
*/
|
314 |
+
function tinvwl_wpml_addtowishlist_out_prepare( $attr ) {
|
315 |
+
if ( class_exists( 'woocommerce_wpml' ) ) {
|
316 |
+
$woo_wpml = woocommerce_wpml::instance();
|
317 |
+
if ( array_key_exists( 'product_id', $attr ) && ! empty( $attr['product_id'] ) ) {
|
318 |
+
$attr['product_id'] = $woo_wpml->products->get_original_product_id( $attr['product_id'] );
|
319 |
+
}
|
320 |
+
if ( array_key_exists( 'product_id', $attr ) && ! empty( $attr['product_id'] ) && array_key_exists( 'variation_id', $attr ) && ! empty( $attr['variation_id'] ) ) {
|
321 |
+
$original_product_language = $woo_wpml->products->get_original_product_language( $attr['product_id'] );
|
322 |
+
$attr['variation_id'] = apply_filters( 'translate_object_id', $attr['variation_id'], 'product_variation', true, $original_product_language );
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
+
return $attr;
|
327 |
+
}
|
328 |
+
|
329 |
+
add_filter( 'tinvwl_addtowishlist_out_prepare_attr', 'tinvwl_wpml_addtowishlist_out_prepare' );
|
330 |
+
}
|
331 |
+
|
332 |
+
if ( ! function_exists( 'tinvwl_wpml_addtowishlist_out_prepare_product' ) ) {
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Change product if product need translate in WooCommerce Multilingual
|
336 |
+
*
|
337 |
+
* @param \WC_Product $product WooCommerce Product.
|
338 |
+
*
|
339 |
+
* @return \WC_Product
|
340 |
+
*/
|
341 |
+
function tinvwl_wpml_addtowishlist_out_prepare_product( $product ) {
|
342 |
+
if ( class_exists( 'woocommerce_wpml' ) && is_object( $product ) ) {
|
343 |
+
$woo_wpml = woocommerce_wpml::instance();
|
344 |
+
$product_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->id : ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() );
|
345 |
+
$variation_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->variation_id : ( $product->is_type( 'variation' ) ? $product->get_id() : 0 );
|
346 |
+
|
347 |
+
if ( ! empty( $product_id ) ) {
|
348 |
+
$product_id = $woo_wpml->products->get_original_product_id( $product_id );
|
349 |
+
}
|
350 |
+
if ( ! empty( $product_id ) && ! empty( $variation_id ) ) {
|
351 |
+
$original_product_language = $woo_wpml->products->get_original_product_language( $product_id );
|
352 |
+
$variation_id = apply_filters( 'translate_object_id', $variation_id, 'product_variation', true, $original_product_language );
|
353 |
+
}
|
354 |
+
if ( ! empty( $product_id ) ) {
|
355 |
+
$product = wc_get_product( $variation_id ? $variation_id : $product_id );
|
356 |
+
}
|
357 |
+
}
|
358 |
+
|
359 |
+
return $product;
|
360 |
+
}
|
361 |
+
|
362 |
+
add_filter( 'tinvwl_addtowishlist_out_prepare_product', 'tinvwl_wpml_addtowishlist_out_prepare_product' );
|
363 |
+
}
|
364 |
+
|
365 |
if ( ! function_exists( 'tinvwl_wpml_addtowishlist_prepare_form' ) ) {
|
366 |
|
367 |
/**
|
794 |
add_action( 'tinvwl_wishlist_row_after', 'tinvwl_row_woocommerce_composite_products', 10, 2 );
|
795 |
} // End if().
|
796 |
|
797 |
+
if ( ! function_exists( 'tinvwl_item_price_woocommerce_composite_products' ) ) {
|
798 |
+
|
799 |
+
/**
|
800 |
+
* Modify price for WooCommerce Composite Products
|
801 |
+
*
|
802 |
+
* @param string $price Returned price.
|
803 |
+
* @param array $wl_product Wishlist Product.
|
804 |
+
* @param \WC_Product $product Woocommerce Product.
|
805 |
+
*
|
806 |
+
* @return string
|
807 |
+
*/
|
808 |
+
function tinvwl_item_price_woocommerce_composite_products( $price, $wl_product, $product ) {
|
809 |
+
if ( is_object( $product ) && $product->is_type( 'composite' ) && array_key_exists( 'wccp_component_selection', $wl_product['meta'] ) ) {
|
810 |
+
$components = $product->get_components();
|
811 |
+
$_price = $product->get_price();
|
812 |
+
$regular_price = $product->get_regular_price();
|
813 |
+
foreach ( $components as $component_id => $component ) {
|
814 |
+
$composited_product_id = ! empty( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) ? absint( $wl_product['meta']['wccp_component_selection'][ $component_id ] ) : '';
|
815 |
+
$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' );
|
816 |
+
|
817 |
+
$composited_variation_id = isset( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) ? wc_clean( $wl_product['meta']['wccp_variation_id'][ $component_id ] ) : '';
|
818 |
+
|
819 |
+
if ( $composited_product_id ) {
|
820 |
+
$composited_product_wrapper = $component->get_option( $composited_variation_id ? $composited_variation_id : $composited_product_id );
|
821 |
+
if ( $component->is_priced_individually() ) {
|
822 |
+
$_price += $composited_product_wrapper->get_price() * $composited_product_quantity;
|
823 |
+
$regular_price += $composited_product_wrapper->get_regular_price() * $composited_product_quantity;
|
824 |
+
}
|
825 |
+
}
|
826 |
+
}
|
827 |
+
if ( $_price == $regular_price ) {
|
828 |
+
$price = wc_price( $_price ) . $product->get_price_suffix();
|
829 |
+
} else {
|
830 |
+
$price = wc_format_sale_price( $regular_price, $_price ) . $product->get_price_suffix();
|
831 |
+
}
|
832 |
+
}
|
833 |
+
|
834 |
+
return $price;
|
835 |
+
}
|
836 |
+
|
837 |
+
add_filter( 'tinvwl_wishlist_item_price', 'tinvwl_item_price_woocommerce_composite_products', 10, 3 );
|
838 |
+
} // End if().
|
839 |
+
|
840 |
if ( ! function_exists( 'tinv_wishlist_metasupport_woocommerce_product_bundles' ) ) {
|
841 |
|
842 |
/**
|
848 |
* @return array
|
849 |
*/
|
850 |
function tinv_wishlist_metasupport_woocommerce_product_bundles( $meta, $product_id ) {
|
851 |
+
$product = wc_get_product( $product_id );
|
852 |
+
if ( is_object( $product ) && $product->is_type( 'bundle' ) ) {
|
|
|
853 |
$meta = array();
|
854 |
}
|
855 |
|