PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 1.1.2
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v1.1.2
4.9.5 4.9.4 4.9.3 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 5 years ago comparison.php 5 years ago route.php 5 years ago
comparison.php
140 lines
1 <?php
2
3 namespace ShopEngine\Modules\Comparison;
4
5 use ShopEngine\Traits\Singleton;
6
7 class Comparison
8 {
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 new Route();
18
19 if($this->get_where_to() == 'after') {
20
21 add_action('woocommerce_after_add_to_cart_button', [$this, 'print_the_button_in_single_page']);
22
23 } else {
24
25 add_action('woocommerce_before_add_to_cart_button', [$this, 'print_the_button_in_single_page']);
26 }
27
28 $show_in_archive = apply_filters('shopengine/module/comparison/show_icon_in_shop_page', true);
29
30 if($show_in_archive === true) {
31
32 add_filter('woocommerce_loop_add_to_cart_link', [$this, 'print_button_in_shop'], 10, 3);
33 }
34
35
36 add_action('wp_enqueue_scripts', [$this, 'enqueue']);
37 }
38
39
40 public function enqueue() {
41
42 wp_enqueue_style('shopengine-comparison', plugin_dir_url(__FILE__) . '/assets/css/comparison.css');
43
44 wp_enqueue_script(
45 'shopengine-comparison',
46 plugin_dir_url(__FILE__) . '/assets/js/comparison.js',
47 ['jquery']
48 );
49
50 wp_localize_script('shopengine-comparison', 'shopEngineComparison', [
51 'product_id' => get_the_ID(),
52 'resturl' => get_rest_url(),
53 'rest_nonce' => wp_create_nonce('wp_rest'),
54 ]);
55 }
56
57
58 public function get_where_to() {
59
60 return apply_filters('shopengine/module/comparison/put_icon_in_side', 'after');
61 //return apply_filters('shopengine/module/comparison/put_icon_in_side', 'before');
62 }
63
64
65 private function is_exists_in_list($idd) {
66
67 if(empty($_COOKIE[Comparison::COOKIE_KEY])) {
68 return false;
69 }
70
71 $content = explode(',', $_COOKIE[Comparison::COOKIE_KEY]);
72
73
74 return in_array($idd, $content);
75 }
76
77
78 public function add_to_menu($menu_links) {
79
80 $logout = $menu_links['customer-logout'];
81
82 unset($menu_links['customer-logout']);
83
84 $menu_links['wishlist'] = 'Wishlist';
85 $menu_links['customer-logout'] = $logout;
86
87 return $menu_links;
88 }
89
90
91 public function print_the_button_in_single_page() {
92
93 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
94 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
95
96 $pid = get_the_ID();
97 $exist = $this->is_exists_in_list($pid);
98 $cls = $exist ? 'active' : 'inactive';
99 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
100
101 echo $left_text; ?>
102
103 <a
104 data-payload='{"pid":<?php echo intval($pid) ?>}'
105 class="<?php echo self::ONCLICK_SELECTOR_CLS ?> shopengine-comparison badge <?php echo esc_attr($cls) ?>"
106 > <?php echo $compare_icon ?> </a><?php
107
108 echo $right_text;
109 }
110
111
112 function print_button_in_shop($add_to_cart_html, $product, $args = []) {
113
114 $left_text = apply_filters('shopengine/module/wishlist/optional_text_left', '');
115 $right_text = apply_filters('shopengine/module/wishlist/optional_text_right', '');
116
117 $pid = $product->get_id();
118 $exist = $this->is_exists_in_list($pid);
119 $cls = $exist ? 'active' : 'inactive';
120 $compare_icon = '<i class="shopengine-icon-product_compare_1"></i>';
121
122 $btn = $left_text .
123 '<a data-payload=\'{"pid":' . $product->get_id() . '}\''.
124 ' class="' . self::ONCLICK_SELECTOR_CLS . ' shopengine-comparison badge se-btn ' . esc_attr($cls) . '"> '. $compare_icon .' </a>' .
125 $right_text;
126
127
128 if($this->get_where_to() == 'after') {
129 $before = '';
130 $after = $btn;
131 } else {
132
133 $before = $btn;
134 $after = '';
135 }
136
137 return $before . $add_to_cart_html . $after;
138 }
139 }
140