PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.5.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.5.1
4.9.2 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 4 years ago comparison.php 4 years ago route.php 4 years ago
comparison.php
173 lines
1 <?php
2
3 namespace ShopEngine\Modules\Comparison;
4
5 use ShopEngine\Core\Register\Module_List;
6 use ShopEngine\Utils\Helper;
7 use ShopEngine\Traits\Singleton;
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 if(!empty($_REQUEST['shopengine_quickview'])) {
19
20 // In quickview modal we will not show anything
21 return;
22 }
23
24
25 new Route();
26
27 $sett = Module_List::instance()->get_settings('comparison');
28 $is_show_in_single = isset($sett['show_on_single_page']['value']) ? ($sett['show_on_single_page']['value'] === 'yes') : true;
29
30 if($is_show_in_single === true) {
31
32 if($this->get_where_to($sett) == 'after') {
33
34 add_action('woocommerce_after_add_to_cart_button', [$this, 'print_the_button_in_single_page']);
35
36 } else {
37
38 add_action('woocommerce_before_add_to_cart_button', [$this, 'print_the_button_in_single_page']);
39 }
40 }
41
42 $is_show = isset($sett['show_on_archive_page']['value']) ? ($sett['show_on_archive_page']['value'] === 'yes') : true;
43
44 $show_in_archive = apply_filters('shopengine/module/wishlist/show_icon_in_shop_page', $is_show);
45
46 if($show_in_archive === true) {
47
48 add_filter('woocommerce_loop_add_to_cart_link', [$this, 'print_button_in_shop'], 10, 3);
49 }
50
51
52 add_action('wp_enqueue_scripts', [$this, 'enqueue']);
53
54 // Modal Wrapper
55 add_action( 'wp_footer', [$this, 'qc_modal_wrapper'] );
56 }
57
58 public function qc_modal_wrapper() {
59 ?>
60 <div class="shopengine-comparison-modal se-modal-wrapper">
61 <div class="se-modal-inner"></div>
62 </div>
63 <?php
64 }
65
66 public function enqueue() {
67 // Comparison Styles
68 wp_enqueue_style('shopengine-comparison', \ShopEngine::module_url() . 'comparison/assets/css/comparison.css', ['shopengine-modal-styles']);
69
70 // Comparison Scripts
71 wp_enqueue_script(
72 'shopengine-comparison',
73 \ShopEngine::module_url() . 'comparison/assets/js/comparison.js',
74 ['jquery', 'shopengine-modal-script'],
75 \ShopEngine::version(),
76 true
77 );
78
79
80 wp_localize_script('shopengine-comparison', 'shopEngineComparison', [
81 'product_id' => get_the_ID(),
82 'resturl' => get_rest_url(),
83 'rest_nonce' => wp_create_nonce('wp_rest'),
84 ]);
85 }
86
87
88 public function get_where_to($settings = []) {
89
90 $position = !empty($settings['show_icon_where_to']['value']) ? $settings['show_icon_where_to']['value'] : 'after';
91
92 return apply_filters('shopengine/module/comparison/put_icon_in_side', $position);
93 }
94
95
96 private function is_exists_in_list($idd) {
97
98 if(empty($_COOKIE[Comparison::COOKIE_KEY])) {
99 return false;
100 }
101
102 $content = explode(',', $_COOKIE[Comparison::COOKIE_KEY]);
103
104
105 return in_array($idd, $content);
106 }
107
108
109 public function add_to_menu($menu_links) {
110
111 $logout = $menu_links['customer-logout'];
112
113 unset($menu_links['customer-logout']);
114
115 $menu_links['wishlist'] = 'Wishlist';
116 $menu_links['customer-logout'] = $logout;
117
118 return $menu_links;
119 }
120
121
122 public function print_the_button_in_single_page() {
123
124 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
125 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
126
127 $pid = get_the_ID();
128 $exist = $this->is_exists_in_list($pid);
129 $cls = $exist ? 'active' : 'inactive';
130 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
131
132 echo Helper::kses($left_text); ?>
133
134 <a
135 data-payload='{"pid":<?php echo intval($pid) ?>}'
136 class="<?php echo self::ONCLICK_SELECTOR_CLS ?> shopengine-comparison badge <?php echo esc_attr($cls) ?>"
137 > <?php echo Helper::kses($compare_icon) ?> </a><?php
138
139 echo Helper::kses($right_text);
140 }
141
142
143 function print_button_in_shop($add_to_cart_html, $product, $args = []) {
144
145 $sett = Module_List::instance()->get_settings('comparison');
146
147 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
148 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
149
150 $pid = $product->get_id();
151 $exist = $this->is_exists_in_list($pid);
152 $cls = $exist ? 'active' : 'inactive';
153 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
154
155 $btn = $left_text .
156 '<a data-payload=\'{"pid":' . $product->get_id() . '}\'' .
157 ' class="' . self::ONCLICK_SELECTOR_CLS . ' shopengine-comparison badge se-btn ' . esc_attr($cls) . '"> ' . $compare_icon . ' </a>' .
158 $right_text;
159
160
161 if($this->get_where_to() == 'after') {
162 $before = '';
163 $after = $btn;
164 } else {
165
166 $before = $btn;
167 $after = '';
168 }
169
170 return $before . $add_to_cart_html . $after;
171 }
172 }
173