PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.2.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.2.1
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
172 lines
1 <?php
2
3 namespace ShopEngine\Modules\Comparison;
4
5 use ShopEngine\Core\Register\Module_List;
6 use ShopEngine\Traits\Singleton;
7
8 class Comparison {
9 const COOKIE_KEY = 'shopengine_comparison_id_list';
10 const ONCLICK_SELECTOR_CLS = 'shopengine_comparison_add_to_list_action';
11 const COOKIE_TIME_IN_DAYS = 1;
12
13 use Singleton;
14
15 public function init() {
16
17 if(!empty($_REQUEST['shopengine_quickview'])) {
18
19 // In quickview modal we will not show anything
20 return;
21 }
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 public function qc_modal_wrapper() {
58 ?>
59 <div class="shopengine-comparison-modal se-modal-wrapper">
60 <div class="se-modal-inner"></div>
61 </div>
62 <?php
63 }
64
65 public function enqueue() {
66 // Comparison Styles
67 wp_enqueue_style('shopengine-comparison', \ShopEngine::module_url() . 'comparison/assets/css/comparison.css', ['shopengine-modal-styles']);
68
69 // Comparison Scripts
70 wp_enqueue_script(
71 'shopengine-comparison',
72 \ShopEngine::module_url() . 'comparison/assets/js/comparison.js',
73 ['jquery', 'shopengine-modal-script'],
74 \ShopEngine::version(),
75 true
76 );
77
78
79 wp_localize_script('shopengine-comparison', 'shopEngineComparison', [
80 'product_id' => get_the_ID(),
81 'resturl' => get_rest_url(),
82 'rest_nonce' => wp_create_nonce('wp_rest'),
83 ]);
84 }
85
86
87 public function get_where_to($settings = []) {
88
89 $position = !empty($settings['show_icon_where_to']['value']) ? $settings['show_icon_where_to']['value'] : 'after';
90
91 return apply_filters('shopengine/module/comparison/put_icon_in_side', $position);
92 }
93
94
95 private function is_exists_in_list($idd) {
96
97 if(empty($_COOKIE[Comparison::COOKIE_KEY])) {
98 return false;
99 }
100
101 $content = explode(',', $_COOKIE[Comparison::COOKIE_KEY]);
102
103
104 return in_array($idd, $content);
105 }
106
107
108 public function add_to_menu($menu_links) {
109
110 $logout = $menu_links['customer-logout'];
111
112 unset($menu_links['customer-logout']);
113
114 $menu_links['wishlist'] = 'Wishlist';
115 $menu_links['customer-logout'] = $logout;
116
117 return $menu_links;
118 }
119
120
121 public function print_the_button_in_single_page() {
122
123 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
124 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
125
126 $pid = get_the_ID();
127 $exist = $this->is_exists_in_list($pid);
128 $cls = $exist ? 'active' : 'inactive';
129 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
130
131 echo $left_text; ?>
132
133 <a
134 data-payload='{"pid":<?php echo intval($pid) ?>}'
135 class="<?php echo self::ONCLICK_SELECTOR_CLS ?> shopengine-comparison badge <?php echo esc_attr($cls) ?>"
136 > <?php echo $compare_icon ?> </a><?php
137
138 echo $right_text;
139 }
140
141
142 function print_button_in_shop($add_to_cart_html, $product, $args = []) {
143
144 $sett = Module_List::instance()->get_settings('comparison');
145
146 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
147 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
148
149 $pid = $product->get_id();
150 $exist = $this->is_exists_in_list($pid);
151 $cls = $exist ? 'active' : 'inactive';
152 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
153
154 $btn = $left_text .
155 '<a data-payload=\'{"pid":' . $product->get_id() . '}\'' .
156 ' class="' . self::ONCLICK_SELECTOR_CLS . ' shopengine-comparison badge se-btn ' . esc_attr($cls) . '"> ' . $compare_icon . ' </a>' .
157 $right_text;
158
159
160 if($this->get_where_to() == 'after') {
161 $before = '';
162 $after = $btn;
163 } else {
164
165 $before = $btn;
166 $after = '';
167 }
168
169 return $before . $add_to_cart_html . $after;
170 }
171 }
172