PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / trunk
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution vtrunk
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / modules / comparison / comparison.php
shopengine / modules / comparison Last commit date
assets 7 months ago comparison-cookie.php 2 years ago comparison-field-value.php 9 months ago comparison-helper.php 3 years ago comparison-share.php 3 years ago comparison.php 3 years ago group-meta.php 3 years ago route.php 3 years ago
comparison.php
175 lines
1 <?php
2
3 namespace ShopEngine\Modules\Comparison;
4
5 use ShopEngine\Core\Register\Module_List;
6 use ShopEngine\Traits\Singleton;
7 use ShopEngine\Utils\Helper;
8
9 class Comparison {
10 const COOKIE_KEY = 'shopengine_comparison_id_list';
11 const ONCLICK_SELECTOR_CLS = 'shopengine_comparison_add_to_list_action';
12 const COOKIE_TIME_IN_DAYS = 1;
13
14 use Singleton;
15
16 public function init() {
17
18 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just checking current page
19 if(!empty($_REQUEST['shopengine_quickview'])) {
20 // In quickview modal we will not show anything
21 return;
22 }
23
24 new Route();
25
26 $sett = Module_List::instance()->get_settings('comparison');
27 $is_show_in_single = isset($sett['show_on_single_page']['value']) ? ($sett['show_on_single_page']['value'] === 'yes') : true;
28
29 if($is_show_in_single === true) {
30
31 if($this->get_where_to($sett) == 'after') {
32
33 add_action('woocommerce_after_add_to_cart_button', [$this, 'print_the_button_in_single_page']);
34
35 } else {
36
37 add_action('woocommerce_before_add_to_cart_button', [$this, 'print_the_button_in_single_page']);
38 }
39 }
40
41 $is_show = isset($sett['show_on_archive_page']['value']) ? ($sett['show_on_archive_page']['value'] === 'yes') : true;
42
43 $show_in_archive = apply_filters('shopengine/module/wishlist/show_icon_in_shop_page', $is_show);
44
45 if($show_in_archive === true) {
46
47 add_filter('woocommerce_loop_add_to_cart_link', [$this, 'print_button_in_shop'], 10, 3);
48 }
49
50
51 add_action('wp_enqueue_scripts', [$this, 'enqueue']);
52
53 // Modal Wrapper
54 add_action( 'wp_footer', [$this, 'qc_modal_wrapper'] );
55
56
57 add_action( 'woocommerce_admin_process_product_object', [new Group_Meta(), 'index'], 10, 1 );
58 }
59
60
61 public function qc_modal_wrapper() {
62 ?>
63 <div class="shopengine-comparison-modal se-modal-wrapper">
64 <div class="se-modal-inner"></div>
65 </div>
66 <?php
67 }
68
69 public function enqueue() {
70 // Comparison Styles
71 wp_enqueue_style('shopengine-comparison', \ShopEngine::module_url() . 'comparison/assets/css/comparison.css', ['shopengine-modal-styles']);
72
73 // Comparison Scripts
74 wp_enqueue_script(
75 'shopengine-comparison',
76 \ShopEngine::module_url() . 'comparison/assets/js/comparison.js',
77 ['jquery', 'shopengine-modal-script'],
78 \ShopEngine::version(),
79 true
80 );
81
82
83 wp_localize_script('shopengine-comparison', 'shopEngineComparison', [
84 'product_id' => get_the_ID(),
85 'resturl' => get_rest_url(),
86 'rest_nonce' => wp_create_nonce('wp_rest'),
87 ]);
88 }
89
90
91 public function get_where_to($settings = []) {
92
93 $position = !empty($settings['show_icon_where_to']['value']) ? $settings['show_icon_where_to']['value'] : 'after';
94
95 return apply_filters('shopengine/module/comparison/put_icon_in_side', $position);
96 }
97
98
99 private function is_exists_in_list($idd) {
100
101 if(empty($_COOKIE[Comparison::COOKIE_KEY])) {
102 return false;
103 }
104
105 $content = explode(',', sanitize_text_field( wp_unslash( $_COOKIE[Comparison::COOKIE_KEY] ) ) );
106
107 return in_array($idd, $content);
108 }
109
110
111 public function add_to_menu($menu_links) {
112
113 $logout = $menu_links['customer-logout'];
114
115 unset($menu_links['customer-logout']);
116
117 $menu_links['wishlist'] = 'Wishlist';
118 $menu_links['customer-logout'] = $logout;
119
120 return $menu_links;
121 }
122
123
124 public function print_the_button_in_single_page() {
125
126 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
127 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
128
129 $pid = get_the_ID();
130 $exist = $this->is_exists_in_list($pid);
131 $cls = $exist ? 'active' : 'inactive';
132 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
133
134 echo wp_kses($left_text, Helper::get_kses_array()); ?>
135
136 <a
137 data-payload='{"pid":<?php echo intval($pid) ?>}'
138 class="<?php echo esc_attr(self::ONCLICK_SELECTOR_CLS) ?> shopengine-comparison badge <?php echo esc_attr($cls) ?>"
139 > <?php echo wp_kses($compare_icon, Helper::get_kses_array()) ?> </a><?php
140
141 echo wp_kses($right_text, Helper::get_kses_array());
142 }
143
144
145 function print_button_in_shop($add_to_cart_html, $product, $args = []) {
146
147 $sett = Module_List::instance()->get_settings('comparison');
148
149 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
150 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
151
152 $pid = $product->get_id();
153 $exist = $this->is_exists_in_list($pid);
154 $cls = $exist ? 'active' : 'inactive';
155 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
156
157 $btn = $left_text .
158 '<a data-payload=\'{"pid":' . $product->get_id() . '}\'' .
159 ' class="' . self::ONCLICK_SELECTOR_CLS . ' shopengine-comparison badge se-btn ' . esc_attr($cls) . '"> ' . $compare_icon . ' </a>' .
160 $right_text;
161
162
163 if($this->get_where_to() == 'after') {
164 $before = '';
165 $after = $btn;
166 } else {
167
168 $before = $btn;
169 $after = '';
170 }
171
172 return $before . $add_to_cart_html . $after;
173 }
174 }
175