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