PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 3.6.2.5
Products Compare for WooCommerce v3.6.2.5
3.6.2.8 3.6.2.7 trunk 1.0.1 1.0.10 1.0.10.1 1.0.11 1.0.11.1 1.0.12 1.0.13 1.0.13.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 3.5 3.5.0.1 3.5.0.2 3.5.1 3.5.1.1 3.5.1.2 3.5.1.3 3.5.1.4 3.5.1.5 3.5.1.6 3.5.1.7 3.5.2 3.5.2.1 3.5.2.2 3.5.2.3 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.7.1 3.5.7.2 3.5.7.3 3.5.7.4 3.5.7.5 3.5.7.6 3.5.7.7 3.5.7.8 3.5.7.9 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.2.1 3.6.2.2 3.6.2.3 3.6.2.4 3.6.2.5 3.6.2.6
products-compare-for-woocommerce / main.php
products-compare-for-woocommerce Last commit date
berocket 2 months ago css 2 months ago divi 2 months ago includes 2 months ago js 2 months ago languages 2 months ago style_templates 2 months ago templates 2 months ago loco.xml 2 months ago main.php 2 months ago products-compare.php 2 months ago readme.txt 2 months ago wpml-config.xml 2 months ago
main.php
1333 lines
1 <?php
2 define( "BeRocket_Compare_Products_domain", 'products-compare-for-woocommerce');
3 define( "Compare_Products_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" );
4 load_plugin_textdomain('products-compare-for-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
5 require_once(plugin_dir_path( __FILE__ ).'berocket/framework.php');
6 foreach (glob(__DIR__ . "/includes/*.php") as $filename)
7 {
8 include_once($filename);
9 }
10 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
11 include_once(plugin_dir_path( __FILE__ ) . "includes/admin/funnels.php");
12 foreach (glob(plugin_dir_path( __FILE__ ) . "includes/compatibility/*.php") as $filename)
13 {
14 include_once($filename);
15 }
16
17 class BeRocket_Compare_Products extends BeRocket_Framework {
18 public $theme_template;
19 public static $settings_name = 'br-compare-products-options';
20 protected static $instance;
21 protected $plugin_version_capability = 15;
22 protected $disable_settings_for_admin = array(
23 array('javascript_settings', 'before_load'),
24 array('javascript_settings', 'after_load'),
25 array('javascript_settings', 'before_remove'),
26 array('javascript_settings', 'after_remove'),
27 );
28 protected $check_init_array = array(
29 array(
30 'check' => 'woocommerce_version',
31 'data' => array(
32 'version' => '3.0',
33 'operator' => '>=',
34 'notice' => 'Plugin Products Compare for WooCommerce required WooCommerce version 3.0 or higher'
35 )
36 ),
37 array(
38 'check' => 'framework_version',
39 'data' => array(
40 'version' => '2.1',
41 'operator' => '>=',
42 'notice' => 'Please update all BeRocket plugins to the most recent version. Products Compare for WooCommerce is not working correctly with older versions.'
43 )
44 ),
45 );
46 function __construct () {
47 $this->info = array(
48 'id' => 4,
49 'lic_id' => 53,
50 'version' => BeRocket_Compare_Products_version,
51 'plugin' => '',
52 'slug' => '',
53 'key' => '',
54 'name' => '',
55 'plugin_name' => 'compare_products',
56 'full_name' => 'Products Compare for WooCommerce',
57 'norm_name' => 'Products Compare',
58 'price' => '',
59 'domain' => 'products-compare-for-woocommerce',
60 'templates' => Compare_Products_TEMPLATE_PATH,
61 'plugin_file' => BeRocket_Compare_Products_file,
62 'plugin_dir' => __DIR__,
63 );
64 $this->defaults = array(
65 'template' => '',
66 'apply_filters' => '',
67 'general_settings' => array(
68 'fast_compare' => '0',
69 'hide_same_button' => '1',
70 'hide_same_default' => '0',
71 'remove_all_compare' => '',
72 'addthisID' => '',
73 'compare_page' => '',
74 'remove_compare_table' => '',
75 'attributes' => array(),
76 'use_full_screen' => '',
77 'compare_template' => 'new-compare',
78 'button_position' => 'after_add_to_cart',
79 ),
80 'button_position_product' => 'after_add_to_cart',
81 'style_settings' => array(
82 'button' => array(
83 'bcolor' => '999999',
84 'bwidth' => '0',
85 'bradius' => '0',
86 'fontsize' => '16',
87 'fcolor' => '333333',
88 'backcolor' => '9999ff',
89 ),
90 'toolbutton' => array(
91 'bcolor' => '999999',
92 'bwidth' => '0',
93 'bradius' => '0',
94 'fontsize' => '16',
95 'fcolor' => '333333',
96 'backcolor' => '9999ff',
97 ),
98 'table' => array(
99 'colwidth' => '200',
100 'imgwidth' => '',
101 'toppadding' => '0',
102 'backcolor' => 'ffffff',
103 'backcolorsame' => '',
104 'margintop' => '',
105 'marginbottom' => '',
106 'marginleft' => '',
107 'marginright' => '',
108 'paddingtop' => '',
109 'paddingbottom' => '',
110 'paddingleft' => '',
111 'paddingright' => '',
112 'top' => '',
113 'bottom' => '',
114 'left' => '',
115 'right' => '',
116 'bordercolor' => '',
117 'samecolor' => '',
118 'samecolorhover' => '',
119 ),
120 'fulltable' => array(
121 'closesize' => '34',
122 'closecolor' => '',
123 'closetop' => '0',
124 'closebottom' => '',
125 'closeleft' => '',
126 'closeright' => '0',
127 'backcolor' => '000000',
128 'backopacity' => '0.5',
129 ),
130 'dif_button' => array(
131 'fontsize' => '',
132 'top' => '',
133 'bottom' => '0',
134 'color' => '',
135 'backcolor' => '',
136 ),
137 'dif_button_hover' => array(
138 'fontsize' => '',
139 'color' => '',
140 'backcolor' => '',
141 ),
142 'clear_button' => array(
143 'fontsize' => '',
144 'top' => '',
145 'bottom' => '0',
146 'color' => '',
147 'backcolor' => '',
148 ),
149 'clear_button_hover' => array(
150 'fontsize' => '',
151 'color' => '',
152 'backcolor' => '',
153 ),
154 'comparebutton' => array(
155 'fontsize' => '',
156 'width' => '',
157 'color' => '',
158 'backcolor' => '',
159 ),
160 'comparebuttonhover' => array(
161 'fontsize' => '',
162 'width' => '',
163 'color' => '',
164 'backcolor' => '',
165 ),
166 'comparebuttonadded' => array(
167 'fontsize' => '',
168 'width' => '',
169 'color' => '',
170 'backcolor' => '',
171 ),
172 ),
173 'text_settings' => array(
174 'compare' => 'Compare',
175 'add_compare' => 'Compare',
176 'added_compare' => 'Added',
177 'toolbar' => 'Products For Compare',
178 'attribute' => 'Attributes',
179 'custom' => 'Other attributes',
180 'availability' => 'Availability',
181 'description' => 'Description',
182 'remove_all_compare_text' => '',
183 'hide_same_button_text' => '',
184 'show_same_button_text' => '',
185 ),
186 'javascript_settings' => array(
187 'before_load' => '',
188 'after_load' => '',
189 'before_remove' => '',
190 'after_remove' => '',
191 'custom_css' => '',
192 ),
193 'fontawesome_frontend_disable' => '',
194 'fontawesome_frontend_version' => '',
195 );
196 $this->values = array(
197 'settings_name' => 'br-compare-products-options',
198 'option_page' => 'br-compare-products',
199 'premium_slug' => 'woocommerce-products-compare',
200 'free_slug' => 'products-compare-for-woocommerce',
201 'hpos_comp' => true
202 );
203 $this->feature_list = array();
204 $this->framework_data['fontawesome_frontend'] = true;
205 $this->active_libraries = array('addons', 'popup', 'templates');
206 parent::__construct( $this );
207 if( $this->check_framework_version() ) {
208 if ( $this->init_validation() ) {
209 $options_global = $this->get_option();
210 $options = $options_global['general_settings'];
211 $this->add_compare_actions();
212 add_action ( 'berocket_add_compare_actions', array($this, 'add_compare_actions') );
213 add_action ( 'berocket_remove_compare_actions', array($this, 'remove_compare_actions') );
214 add_action ( "widgets_init", array ( $this, 'widgets_init' ) );
215 add_filter('berocket_compare_acf_product_field', array($this, 'acf_product_field'), 10, 3);
216 add_filter('berocket_compare_acf_product_field_height', array($this, 'acf_product_field_height'), 10, 2);
217 add_action( "wp_ajax_br_get_compare_products", array ( $this, 'listener_products' ) );
218 add_action( "wp_ajax_nopriv_br_get_compare_products", array ( $this, 'listener_products' ) );
219 add_action( "wp_ajax_br_get_compare_list", array ( $this, 'compare_list' ) );
220 add_action( "wp_ajax_nopriv_br_get_compare_list", array ( $this, 'compare_list' ) );
221 add_action( "br_compare_button_options", array ( $this, 'get_compare_button_options' ) );
222 add_shortcode( 'br_compare_table', array( $this, 'shortcode' ) );
223 add_shortcode( 'br_compare_text', array( $this, 'shortcode_text' ) );
224 add_shortcode( 'br_compare_button', array( $this, 'get_compare_button' ) );
225 if( empty($options['remove_compare_table']) ) {
226 add_filter ( 'the_content', array( $this, 'compare_page' ) );
227 }
228 if( isset($_GET['compare']) ) {
229 $_GET['compare'] = urldecode($_GET['compare']);
230 }
231 add_filter('BeRocket_popup_open_page_elements', array($this, 'popup_open_page_elements'), 10, 2);
232 if( ! empty($options_global['template']) ) {
233 $template_data = $this->libraries->libraries_class['templates']->get_active_template_info($options_global['template']);
234 $theme_template = $template_data['class'];
235 do_action('berocket_init_template_'.$this->info['plugin_name'], $options_global['template']);
236 $this->theme_template = $theme_template;
237 }
238 add_action( 'divi_extensions_init', array($this, 'divi_initialize_extension') );
239 }
240 } else {
241 add_filter( 'berocket_display_additional_notices', array(
242 $this,
243 'old_framework_notice'
244 ) );
245 }
246 }
247
248 public function popup_open_page_elements($html_elements, $elements) {
249 $pattern = '/<div([^<>]+)>popup_compare_fullsize_table<\/div>/i';
250 $replacement = '';
251 $html_elements['html_content'] = preg_replace($pattern, $replacement, $html_elements['html_content']);
252 return $html_elements;
253 }
254
255 public function add_compare_actions() {
256 $this->add_remove_compare_actions('add');
257 }
258
259 public function remove_compare_actions() {
260 $this->add_remove_compare_actions('remove');
261 }
262
263 public function add_remove_compare_actions($add_remove = 'add') {
264 $options_global = $this->get_option();
265 $action = $add_remove.'_action';
266 $options = $options_global['general_settings'];
267 switch($options['button_position']) {
268 case 'before_all':
269 $action( 'woocommerce_before_shop_loop_item', array( $this, 'get_compare_button' ), 5 );
270 $action( 'lgv_advanced_before', array( $this, 'get_compare_button' ), 38 );
271 break;
272 case 'after_image':
273 $action( 'woocommerce_before_shop_loop_item_title', array( $this, 'get_compare_button' ), 20 );
274 $action( 'lgv_advanced_after_img', array( $this, 'get_compare_button' ), 38 );
275 break;
276 case 'after_title':
277 $action( 'woocommerce_shop_loop_item_title', array( $this, 'get_compare_button' ), 38 );
278 $action( 'lgv_advanced_before_description', array( $this, 'get_compare_button' ), 38 );
279 break;
280 case 'after_price':
281 $action( 'woocommerce_after_shop_loop_item_title', array( $this, 'get_compare_button' ), 38 );
282 $action( 'lgv_advanced_after_price', array( $this, 'get_compare_button' ), 38 );
283 break;
284 case 'after_add_to_cart':
285 $action( 'woocommerce_after_shop_loop_item', array( $this, 'get_compare_button' ), 38 );
286 $action( 'lgv_advanced_after_price', array( $this, 'get_compare_button' ), 30 );
287 break;
288 }
289 switch($options_global['button_position_product']) {
290 case 'before_all':
291 $action( 'woocommerce_before_single_product_summary', array( $this, 'get_compare_button' ), 5 );
292 break;
293 case 'after_image':
294 $action( 'woocommerce_before_single_product_summary', array( $this, 'get_compare_button' ), 38 );
295 break;
296 case 'after_title':
297 $action( 'woocommerce_single_product_summary', array( $this, 'get_compare_button' ), 8 );
298 break;
299 case 'after_price':
300 $action( 'woocommerce_single_product_summary', array( $this, 'get_compare_button' ), 15 );
301 break;
302 case 'after_add_to_cart':
303 $action( 'woocommerce_single_product_summary', array( $this, 'get_compare_button' ), 38 );
304 break;
305 }
306 }
307 function init_validation() {
308 return parent::init_validation() && $this->check_framework_version();
309 }
310 function check_framework_version() {
311 return ( ! empty(BeRocket_Framework::$framework_version) && version_compare(BeRocket_Framework::$framework_version, 2.1, '>=') );
312 }
313 function old_framework_notice($notices) {
314 $notices[] = array(
315 'start' => 0,
316 'end' => 0,
317 'name' => $this->info[ 'plugin_name' ].'_old_framework',
318 'html' => __('<strong>Please update all BeRocket plugins to the most recent version. Products Compare for WooCommerce is not working correctly with older versions.</strong>', 'products-compare-for-woocommerce'),
319 'righthtml' => '',
320 'rightwidth' => 0,
321 'nothankswidth' => 0,
322 'contentwidth' => 1600,
323 'subscribe' => false,
324 'priority' => 10,
325 'height' => 50,
326 'repeat' => false,
327 'repeatcount' => 1,
328 'image' => array(
329 'local' => '',
330 'width' => 0,
331 'height' => 0,
332 'scale' => 1,
333 )
334 );
335 return $notices;
336 }
337 public function init () {
338 parent::init();
339 add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_plugin'));
340 }
341 public function enqueue_scripts_plugin() {
342 wp_reset_query();
343 $element_i = $this->add_popup('ajax_load');
344
345 $options_global = $this->get_option();
346 wp_register_style( 'berocket_compare_products_style', plugins_url( 'css/products_compare.css', __FILE__ ), "", BeRocket_Compare_Products_version );
347 wp_enqueue_style( 'berocket_compare_products_style' );
348 wp_enqueue_script( 'berocket_jquery_cookie', plugins_url( 'js/jquery.cookie.js', __FILE__ ), array( 'jquery' ), BeRocket_Compare_Products_version );
349 wp_enqueue_script( 'berocket_compare_products_script', plugins_url( 'js/products_compare.js', __FILE__ ), array( 'jquery' ), BeRocket_Compare_Products_version );
350 wp_enqueue_script( 'jquery-mousewheel', plugins_url( 'js/jquery.mousewheel.min.js', __FILE__ ), array( 'jquery' ), BeRocket_Compare_Products_version );
351 $javascript = $options_global['javascript_settings'];
352 $options = $options_global['general_settings'];
353 $style = $options_global['style_settings'];
354
355 global $wp_query;
356 $page = $options['compare_page'];
357 $is_compare_page = false;
358 $page_id = ( isset($wp_query->queried_object->ID) ? $wp_query->queried_object->ID : '' );
359 if( ! empty( $page_id ) && $wp_query->is_main_query() ) {
360 $default_language = apply_filters( 'wpml_default_language', NULL );
361 $page_id = apply_filters( 'wpml_object_id', $page_id, 'page', true, $default_language );
362 $is_compare_page = $page_id == $page;
363 }
364 wp_localize_script(
365 'berocket_compare_products_script',
366 'the_compare_products_data',
367 array(
368 'ajax_url' => admin_url( 'admin-ajax.php' ),
369 'user_func' => $javascript,
370 'home_url' => site_url(),
371 'hide_same' => (empty($options_global['text_settings']['hide_same_button_text']) ? __( 'Hide attributes with same values', 'products-compare-for-woocommerce' ) : $options_global['text_settings']['hide_same_button_text']),
372 'show_same' => (empty($options_global['text_settings']['show_same_button_text']) ? __( 'Show attributes with same values', 'products-compare-for-woocommerce' ) : $options_global['text_settings']['show_same_button_text']),
373 'hide_same_default' => ! empty($options['hide_same_default']),
374 'compare_selector' => '#br_popup_'.$element_i,
375 'toppadding' => (int) $style['table']['toppadding'],
376 'is_compare_page' => $is_compare_page,
377 )
378 );
379 }
380 public function widgets_init() {
381 register_widget("berocket_compare_products_widget");
382 }
383
384 public static function get_all_compare_products() {
385 if ( ! empty($_COOKIE['br_products_compare']) ) {
386 $cookie = $_COOKIE['br_products_compare'];
387 $products = explode( ',', $cookie );
388 return $products;
389 } else {
390 return false;
391 }
392 }
393 public static function is_set_cookie( $id ) {
394 if ( ! empty($_COOKIE['br_products_compare']) ) {
395 $cookie = $_COOKIE['br_products_compare'];
396 if ( preg_match( "/(^".$id.",)|(,".$id."$)|(,".$id.",)|(^".$id."$)/", $cookie ) ) {
397 return true;
398 } else {
399 return false;
400 }
401 } else {
402 return false;
403 }
404 }
405
406 public function listener_products() {
407 set_query_var( 'type', 'image' );
408 $this->br_get_template_part('selected_products');
409 wp_die();
410 }
411
412 public function compare_list() {
413 $options_global = $this->get_option();
414 $options = $options_global['general_settings'];
415 $template_name = ( empty($options['compare_template']) || $options['compare_template'] == 'compare' ? 'new-compare' : $options['compare_template'] );
416 set_query_var( 'is_full_screen', true );
417 set_query_var( 'br_compare_apply_filters', ! empty($options_global['apply_filters']) );
418 $this->br_get_template_part($template_name);
419 wp_die();
420 }
421
422 public function shortcode_text($atts = array(), $content = '') {
423 if( ! is_array($atts) ) {
424 $atts = array();
425 }
426 $atts = array_merge(array(
427 'noprod' => '1'
428 ), $atts);
429 if( isset($_GET['compare']) && $_GET['compare'] ) {
430 $products = explode(',', $_GET['compare']);
431 } else {
432 $products = $this->get_all_compare_products();
433 }
434 if( ! is_array($products) ) {
435 $products = array();
436 }
437 $has_prod = (! empty($products) && count($products) > 0);
438 if( ($has_prod && empty($atts['noprod'])) || (! $has_prod && !empty($atts['noprod'])) ) {
439 return $content;
440 }
441 return '';
442 }
443 public function shortcode($atts = array()) {
444 $options_global = $this->get_option();
445 $options = $options_global['general_settings'];
446 global $wp;
447 $default_atts = array(
448 'addthis' => '0',
449 );
450 if( ! is_array($atts) ) {
451 $atts = array();
452 }
453 if( ! empty($options['use_full_screen']) ) {
454 $element_i = $this->add_popup('page');
455 set_query_var( 'berocket_element_i', $element_i );
456 }
457 $atts = array_merge($default_atts, $atts);
458 $br_compare_uri = add_query_arg('compare', (empty($_COOKIE['br_products_compare']) ? '' : $_COOKIE['br_products_compare']), home_url( $wp->request ));
459 $template_name = ( empty($options['compare_template']) || $options['compare_template'] == 'compare' ? 'new-compare' : $options['compare_template'] );
460 set_query_var( 'br_compare_apply_filters', ! empty($options_global['apply_filters']) );
461 ob_start();
462 $this->br_get_template_part($template_name);
463 $compare_page = ob_get_clean();
464 if( empty($compare_page) ) {
465 return '';
466 }
467 ob_start();
468 ?>
469 <script>
470 var br_compare_page = "<?php echo remove_query_arg('compare', home_url( $wp->request )); ?>";
471 var br_compare_uri = "<?php echo $br_compare_uri; ?>";
472 <?php
473 if( ! isset($_GET['compare']) && ! empty($_COOKIE['br_products_compare']) ) {
474 ?>
475 if('history' in window && 'pushState' in history) {
476 var stateParameters = { BeRocket: "Rules" };
477 history.replaceState(stateParameters, "BeRocket Rules", br_compare_uri);
478 history.pathname = br_compare_uri;
479 } else {
480 location.replace(br_compare_uri);
481 }
482 <?php } ?>
483 </script>
484 <?php if( ! empty($atts['addthis']) ) { ?>
485 <div class="addthis_sharing_toolbox" data-url="<?php echo $br_compare_uri; ?>"></div>
486 <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $options['addthisID']; ?>"></script>
487 <?php
488 }
489 echo '<div class="woocommerce">'.$compare_page.'</div>';
490 return ob_get_clean();
491 }
492
493 public function compare_page ($content) {
494 global $wp_query;
495 $options_global = $this->get_option();
496 $options = $options_global['general_settings'];
497 $page = $options['compare_page'];
498 $page_id = ( isset($wp_query->queried_object->ID) ? $wp_query->queried_object->ID : '' );
499 remove_filter ( 'the_content', array( $this, 'compare_page' ) );
500 if( ! empty( $page_id ) && $wp_query->is_main_query() ) {
501 $default_language = apply_filters( 'wpml_default_language', NULL );
502 $page_id = apply_filters( 'wpml_object_id', $page_id, 'page', true, $default_language );
503 if ( $page == $page_id ) {
504 ob_start();
505 $br_compare_uri = add_query_arg('compare', (empty($_COOKIE['br_products_compare']) ? '' : $_COOKIE['br_products_compare']), get_page_link($page));
506 ?>
507 <script>
508 var br_compare_page = "<?php echo get_page_link($page); ?>";
509 var br_compare_uri = "<?php echo $br_compare_uri; ?>";
510 <?php
511 if( ! isset($_GET['compare']) && ! empty($_COOKIE['br_products_compare']) ) {
512 ?>
513 if('history' in window && 'pushState' in history) {
514 var stateParameters = { BeRocket: "Rules" };
515 history.replaceState(stateParameters, "BeRocket Rules", br_compare_uri);
516 history.pathname = br_compare_uri;
517 } else {
518 location.replace(br_compare_uri);
519 }
520 <?php } ?>
521 </script>
522 <?php if( ! empty($options['addthisID']) ) { ?>
523 <div class="addthis_sharing_toolbox" data-url="<?php echo $br_compare_uri; ?>"></div>
524 <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $options['addthisID']; ?>"></script>
525 <?php
526 }
527 if( ! empty($options['use_full_screen']) ) {
528 $element_i = $this->add_popup('page');
529 set_query_var( 'berocket_element_i', $element_i );
530 }
531 set_query_var( 'br_compare_apply_filters', ! empty($options_global['apply_filters']) );
532 $template_name = ( empty($options['compare_template']) || $options['compare_template'] == 'compare' ? 'new-compare' : $options['compare_template'] );
533 $this->br_get_template_part($template_name);
534 $content = ob_get_clean() . $content;
535 }
536 }
537 add_filter ( 'the_content', array( $this, 'compare_page' ) );
538 return $content;
539 }
540
541 public function add_popup($type = 'page') {
542 $open_type = array();
543 $html_content = '';
544 if( $type == 'page' ) {
545 $open_type = array('click' => array('type' => 'click', 'selector' => '.br_new_compare_full_size'));
546 $html_content = 'popup_compare_fullsize_table';
547 }
548 $popup_options = array(
549 'close_delay' => '0',
550 'hide_body_scroll' => true,
551 'print_button' => false,
552 'width' => '90%',
553 'height' => '90%',
554 'theme' => $this->theme_template,
555 );
556 return BeRocket_popup_display::add_popup($popup_options, $html_content, $open_type);
557 }
558
559 public function get_compare_button() {
560 $this->get_compare_button_options();
561 }
562 public function get_compare_button_options($atts = array()) {
563 global $product, $wp_query;
564 $options_global = $this->get_option();
565 if( empty($atts['product']) ) {
566 if( empty($product) ) {
567 return false;
568 }
569 $product_id = br_wc_get_product_id($product);
570 $product_id = intval($product_id);
571 } else {
572 $product_id = intval($atts['product']);
573 }
574 $default_language = apply_filters( 'wpml_default_language', NULL );
575 $product_id = apply_filters( 'wpml_object_id', $product_id, 'product', true, $default_language );
576 $options = $options_global['general_settings'];
577 $text = $options_global['text_settings'];
578 $page_compare = intval($options['compare_page']);
579 $page_compare = apply_filters( 'wpml_object_id', $page_compare, 'page', true );
580 if( ! empty($atts) ) {
581 if( ! empty($atts['added_compare']) ) {
582 $text['added_compare'] = sanitize_text_field($atts['added_compare']);
583 }
584 if( ! empty($atts['add_compare']) ) {
585 $text['add_compare'] = sanitize_text_field($atts['add_compare']);
586 }
587 if( isset($atts['fast_compare']) ) {
588 $options['fast_compare'] = ! empty($atts['fast_compare']);
589 }
590 }
591 $button_class = array(
592 'add_to_cart_button',
593 'button',
594 'br_compare_button',
595 'br_product_'.$product_id
596 );
597 if ( $this->is_set_cookie($product_id) ) {
598 $button_class[] = 'br_compare_added';
599 }
600 if ( ! empty($options['fast_compare']) ) {
601 $button_class[] = 'berocket_product_smart_compare';
602 }
603 $button_class = implode(' ', $button_class);
604 $button_class = esc_html($button_class);
605 $href_link = '#no_compare_page';
606 if( get_post($page_compare) ) {
607 $href_link = get_page_link($page_compare);
608 }
609 echo '<a class="'.$button_class.'" data-id="'.$product_id.'" href="'.$href_link.'">
610 <i class="fa fa-square-o"></i>
611 <i class="fa fa-check-square-o"></i>
612 <span class="br_compare_button_text" data-added="'.(empty($text['added_compare']) ? __( 'Added', 'products-compare-for-woocommerce' ) : $text['added_compare']).'" data-not_added="'.(empty($text['add_compare']) ? __( 'Compare Product', 'products-compare-for-woocommerce' ) : $text['add_compare']).'">
613 '.( $this->is_set_cookie($product_id) ? (empty($text['added_compare']) ? __( 'Added', 'products-compare-for-woocommerce' ) : $text['added_compare']) : (empty($text['add_compare']) ? __( 'Compare Product', 'products-compare-for-woocommerce' ) : $text['add_compare']) ).'
614 </span>
615 </a>';
616 }
617
618 public function acf_product_field($field_text, $field, $term) {
619 if( is_array($field) && isset($field['type']) ) {
620 if( $field['type'] == 'image' ) {
621 $img = get_field($field['name'], $term['id']);
622 if( empty($img) ) {
623 $field_text = '';
624 } else {
625 $field_text = '<img style="display:inline-block;max-height: 90px;max-width:100%;" src="'.$img.'">';
626 }
627 } elseif($field['type'] == 'color_picker') {
628 $color = get_field($field['name'], $term['id']);
629 if( empty($color) ) {
630 $field_text = '';
631 } else {
632 $field_text = '<p><span style="border:2px solid black; display: inline-block; width: 30px;height:30px;background-color: '.$color.';"></span></p>';
633 }
634 }
635 }
636 return $field_text;
637 }
638 public function acf_product_field_height($height, $field) {
639 if( is_array($field) && isset($field['type']) ) {
640 if( $field['type'] == 'image' ) {
641 $height = 'height:100px!important;';
642 }
643 }
644 return $height;
645 }
646 public function admin_init () {
647 parent::admin_init();
648 $options = $this->get_option();
649 $this->update_from_not_framework();
650 wp_enqueue_script( 'berocket_compare_products_admin_script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ) );
651 wp_register_style( 'berocket_compare_products_admin_style', plugins_url( 'css/admin.css', __FILE__ ), "", BeRocket_Compare_Products_version );
652 wp_enqueue_style( 'berocket_compare_products_admin_style' );
653 }
654
655 public function activation() {
656 parent::activation();
657 $this->update_from_not_framework();
658 $options_global = $this->get_option();
659 if ( ! $options_global['general_settings']['compare_page'] ) {
660 $compare_page = array(
661 'post_title' => 'Compare',
662 'post_content' => '',
663 'post_status' => 'publish',
664 'post_type' => 'page',
665 );
666
667 $post_id = wp_insert_post($compare_page);
668 $options_global['general_settings']['compare_page'] = $post_id;
669 update_option($this->values['settings_name'], $options_global);
670 }
671 }
672 public function update_from_not_framework() {
673 $update_option = false;
674 $options = $this->get_option();
675 $settings_list = array('general_settings', 'style_settings', 'text_settings', 'javascript_settings');
676 foreach($settings_list as $setting_list) {
677 $settings = get_option('br_compare_products_'.$setting_list);
678 if( ! empty($settings) && is_array($settings) ) {
679 $update_option = true;
680 $options[$setting_list] = $settings;
681 delete_option('br_compare_products_'.$setting_list);
682 }
683 }
684 if($update_option) {
685 $options = $this->recursive_array_set( $this->defaults, $options );
686 update_option($this->values[ 'settings_name' ], $options);
687 }
688 }
689 public function set_styles () {
690 $options_global = $this->get_option();
691 $general_options = $options_global['general_settings'];
692 $template_name = ( empty($general_options['compare_template']) || $general_options['compare_template'] == 'compare' ? 'new-compare' : $general_options['compare_template'] );
693 $options = $options_global['style_settings'];
694 //TABLE STYLE
695 if( $template_name == 'compare' ) {
696 //OLD TABLE STYLE
697 echo '<style>';
698 echo '.berocket_compare_box .br_moved_attr tr td {';
699 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).';';
700 echo '}';
701 echo '.berocket_compare_box .berocket_compare_table_hidden {';
702 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).';';
703 echo '}';
704 echo 'div.berocket_compare_box.berocket_full_screen_box {';
705 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).';';
706 echo '}';
707 echo 'div.berocket_compare_box .berocket_compare_table td {';
708 echo 'min-width: '.$options['table']['colwidth'].'px;';
709 echo '}';
710 //DIF BUTTON
711 echo '.berocket_compare_table_hidden .br_product_hidden_first .br_show_compare_dif {';
712 if( strlen($options['dif_button']['fontsize']) > 0 ) {
713 echo 'font-size: '.$options['dif_button']['fontsize'].'px!important;';
714 }
715 if( strlen($options['dif_button']['top']) > 0 ) {
716 echo 'top: '.$options['dif_button']['top'].'px;';
717 }
718 if( strlen($options['dif_button']['bottom']) > 0 ) {
719 echo 'bottom: '.$options['dif_button']['bottom'].'px;';
720 }
721 if( strlen($options['dif_button']['color']) > 0 ) {
722 echo 'color: #'.str_replace( '#', '', $options['dif_button']['color'] ).';';
723 }
724 if( strlen($options['dif_button']['backcolor']) > 0 ) {
725 echo 'background-color: #'.str_replace( '#', '', $options['dif_button']['backcolor'] ).';';
726 }
727 echo '}';
728 echo '.berocket_compare_table_hidden .br_product_hidden_first .br_show_compare_dif:hover {';
729 if( strlen($options['dif_button_hover']['fontsize']) > 0 ) {
730 echo 'font-size: '.$options['dif_button_hover']['fontsize'].'px;';
731 }
732 if( strlen($options['dif_button_hover']['color']) > 0 ) {
733 echo 'color: #'.str_replace( '#', '', $options['dif_button_hover']['color'] ).';';
734 }
735 if( strlen($options['dif_button_hover']['backcolor']) > 0 ) {
736 echo 'background-color: #'.str_replace( '#', '', $options['dif_button_hover']['backcolor'] ).';';
737 }
738 echo '}';
739 //CLEAR BUTTON
740 echo '.berocket_compare_table_hidden .br_product_hidden_first .br_remove_all_compare {';
741 if( strlen($options['clear_button']['fontsize']) > 0 ) {
742 echo 'font-size: '.$options['clear_button']['fontsize'].'px!important;';
743 }
744 if( strlen($options['clear_button']['top']) > 0 ) {
745 echo 'top: '.$options['clear_button']['top'].'px;';
746 }
747 if( strlen($options['clear_button']['bottom']) > 0 ) {
748 echo 'bottom: '.$options['clear_button']['bottom'].'px;';
749 }
750 if( strlen($options['clear_button']['color']) > 0 ) {
751 echo 'color: #'.str_replace( '#', '', $options['clear_button']['color'] ).';';
752 }
753 if( strlen($options['clear_button']['backcolor']) > 0 ) {
754 echo 'background-color: #'.str_replace( '#', '', $options['clear_button']['backcolor'] ).';';
755 }
756 echo '}';
757 echo '.berocket_compare_table_hidden .br_product_hidden_first .br_remove_all_compare:hover {';
758 if( strlen($options['clear_button_hover']['fontsize']) > 0 ) {
759 echo 'font-size: '.$options['clear_button_hover']['fontsize'].'px;';
760 }
761 if( strlen($options['clear_button_hover']['color']) > 0 ) {
762 echo 'color: #'.str_replace( '#', '', $options['clear_button_hover']['color'] ).';';
763 }
764 if( strlen($options['clear_button_hover']['backcolor']) > 0 ) {
765 echo 'background-color: #'.str_replace( '#', '', $options['clear_button_hover']['backcolor'] ).';';
766 }
767 echo '}';
768 echo 'div.berocket_compare_box .br_moved_attr tr td {';
769 echo 'min-width: '.$options['table']['colwidth'].'px;';
770 echo '}';
771 echo '.beroket_compare_box .berocket_compare_table img {';
772 echo 'width: '.$options['table']['imgwidth'].'px;';
773 echo '}';
774 echo '.berocket_compare_box {';
775 echo 'margin-top: '.$options['table']['margintop'].'px;';
776 echo 'margin-bottom: '.$options['table']['marginbottom'].'px;';
777 echo 'margin-left: '.$options['table']['marginleft'].'px;';
778 echo 'margin-right: '.$options['table']['marginright'].'px;';
779 echo '}';
780 echo 'div.berocket_full_screen_box.berocket_compare_box {';
781 echo 'top: '.$options['table']['top'].'px;';
782 echo 'bottom: '.$options['table']['bottom'].'px;';
783 echo 'left: '.$options['table']['left'].'px;';
784 echo 'right: '.$options['table']['right'].'px;';
785 echo '}';
786 echo 'div.berocket_back_full_screen {';
787 echo 'background-color: #'.str_replace( '#', '', $options['fulltable']['backcolor'] ).';';
788 if( isset($options['fulltable']['backopacity']) && $options['fulltable']['backopacity'] >= 0 && $options['fulltable']['backopacity'] <= 1 ) {
789 echo 'opacity: '.$options['fulltable']['backopacity'].';';
790 }
791 echo '}';
792 echo '.berocket_compare_box a.berocket_normal_size {';
793 echo 'font-size: '.$options['fulltable']['closesize'].'px;';
794 if( isset($options['fulltable']['closetop']) && strlen($options['fulltable']['closetop']) > 0 ) {
795 echo 'top: '.$options['fulltable']['closetop'].'px;';
796 }
797 if( isset($options['fulltable']['closebottom']) && strlen($options['fulltable']['closebottom']) > 0 ) {
798 echo 'bottom: '.$options['fulltable']['closebottom'].'px;';
799 }
800 if( isset($options['fulltable']['closeleft']) && strlen($options['fulltable']['closeleft']) > 0 ) {
801 echo 'left: '.$options['fulltable']['closeleft'].'px;';
802 }
803 if( isset($options['fulltable']['closeright']) && strlen($options['fulltable']['closeright']) > 0 ) {
804 echo 'right: '.$options['fulltable']['closeright'].'px;';
805 }
806 echo 'color: #'.str_replace( '#', '', $options['fulltable']['closecolor'] ).';';
807 echo '}';
808 echo '.berocket_compare_box .br_same_attr td {';
809 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolorsame'] ).';';
810 echo '}';
811 echo '</style>';
812 } else {
813 //NEW TABLE STYLE
814 echo '<style>';
815 echo '.br_new_compare_block .br_left_table {';
816 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).'!important;';
817 echo '}';
818 echo '.br_new_compare_block .br_main_top table {';
819 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).'!important;';
820 echo '}';
821 echo 'div.br_new_compare_block.br_full_size_popup {';
822 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).'!important;';
823 echo '}';
824 echo '
825 div.br_new_compare .br_right_table tr td,
826 div.br_new_compare .br_right_table tr th,
827 div.br_new_compare .br_left_table,
828 div.br_new_compare_block .br_top_table table th,
829 div.br_new_compare_block .br_top_table table td {';
830 echo 'width: '.$options['table']['colwidth'].'px!important;';
831 echo 'min-width: '.$options['table']['colwidth'].'px!important;';
832 echo 'max-width: '.$options['table']['colwidth'].'px!important;';
833 echo '}';
834 echo '
835 div.br_new_compare div.br_right_table,
836 div.br_top_table div.br_main_top,
837 div.br_top_table div.br_opacity_top{';
838 echo 'margin-left: '.$options['table']['colwidth'].'px!important;';
839 echo '}';
840 echo 'div.br_new_compare_block .br_top_table .br_show_compare_dif {';
841 echo 'max-width: '.$options['table']['colwidth'].'px!important;';
842 echo '}';
843 //DIF BUTTON
844 echo 'div.br_new_compare_block .br_show_compare_dif {';
845 if( strlen($options['dif_button']['fontsize']) > 0 ) {
846 echo 'font-size: '.$options['dif_button']['fontsize'].'px!important;';
847 }
848 if( strlen($options['dif_button']['top']) > 0 ) {
849 echo 'top: '.$options['dif_button']['top'].'px!important;';
850 }
851 if( strlen($options['dif_button']['bottom']) > 0 ) {
852 echo 'bottom: '.$options['dif_button']['bottom'].'px!important;';
853 }
854 if( strlen($options['dif_button']['color']) > 0 ) {
855 echo 'color: #'.str_replace( '#', '', $options['dif_button']['color'] ).'!important;';
856 }
857 if( strlen($options['dif_button']['backcolor']) > 0 ) {
858 echo 'background-color: #'.str_replace( '#', '', $options['dif_button']['backcolor'] ).'!important;';
859 }
860 echo '}';
861 echo 'div.br_new_compare_block .br_show_compare_dif:hover {';
862 if( strlen($options['dif_button_hover']['fontsize']) > 0 ) {
863 echo 'font-size: '.$options['dif_button_hover']['fontsize'].'px!important;';
864 }
865 if( strlen($options['dif_button_hover']['color']) > 0 ) {
866 echo 'color: #'.str_replace( '#', '', $options['dif_button_hover']['color'] ).'!important;';
867 }
868 if( strlen($options['dif_button_hover']['backcolor']) > 0 ) {
869 echo 'background-color: #'.str_replace( '#', '', $options['dif_button_hover']['backcolor'] ).'!important;';
870 }
871 echo '}';
872 //CLEAR BUTTON
873 echo 'div.br_new_compare_block .br_remove_all_compare {';
874 if( strlen($options['clear_button']['fontsize']) > 0 ) {
875 echo 'font-size: '.$options['clear_button']['fontsize'].'px!important;';
876 }
877 if( strlen($options['clear_button']['top']) > 0 ) {
878 echo 'top: '.$options['clear_button']['top'].'px!important;';
879 }
880 if( strlen($options['clear_button']['bottom']) > 0 ) {
881 echo 'bottom: '.$options['clear_button']['bottom'].'px!important;';
882 }
883 if( strlen($options['clear_button']['color']) > 0 ) {
884 echo 'color: #'.str_replace( '#', '', $options['clear_button']['color'] ).'!important;';
885 }
886 if( strlen($options['clear_button']['backcolor']) > 0 ) {
887 echo 'background-color: #'.str_replace( '#', '', $options['clear_button']['backcolor'] ).'!important;';
888 }
889 echo '}';
890 echo 'div.br_new_compare_block .br_remove_all_compare:hover {';
891 if( strlen($options['clear_button_hover']['fontsize']) > 0 ) {
892 echo 'font-size: '.$options['clear_button_hover']['fontsize'].'px!important;';
893 }
894 if( strlen($options['clear_button_hover']['color']) > 0 ) {
895 echo 'color: #'.str_replace( '#', '', $options['clear_button_hover']['color'] ).'!important;';
896 }
897 if( strlen($options['clear_button_hover']['backcolor']) > 0 ) {
898 echo 'background-color: #'.str_replace( '#', '', $options['clear_button_hover']['backcolor'] ).'!important;';
899 }
900 echo '}';
901 // -------
902 echo '.br_new_compare_block .br_new_compare img {';
903 echo 'width: '.$options['table']['imgwidth'].'px!important;';
904 echo '}';
905 echo '.br_new_compare_block {';
906 echo 'margin-top: '.$options['table']['margintop'].'px!important;';
907 echo 'margin-bottom: '.$options['table']['marginbottom'].'px!important;';
908 echo 'margin-left: '.$options['table']['marginleft'].'px!important;';
909 echo 'margin-right: '.$options['table']['marginright'].'px!important;';
910 echo '}';
911 echo 'div.br_new_compare_block.br_full_size_popup {';
912 echo 'top: '.$options['table']['top'].'px!important;';
913 echo 'bottom: '.$options['table']['bottom'].'px!important;';
914 echo 'left: '.$options['table']['left'].'px!important;';
915 echo 'right: '.$options['table']['right'].'px!important;';
916 echo '}';
917 echo 'div.br_new_compare_black_popup {';
918 echo 'background-color: #'.str_replace( '#', '', $options['fulltable']['backcolor'] ).'!important;';
919 if( isset($options['fulltable']['backopacity']) && $options['fulltable']['backopacity'] >= 0 && $options['fulltable']['backopacity'] <= 1 ) {
920 echo 'opacity: '.$options['fulltable']['backopacity'].'!important;';
921 }
922 echo '}';
923 echo '.br_full_size_close a {';
924 echo 'font-size: '.$options['fulltable']['closesize'].'px!important;';
925 if( isset($options['fulltable']['closetop']) && strlen($options['fulltable']['closetop']) > 0 ) {
926 echo 'top: '.$options['fulltable']['closetop'].'px!important;';
927 }
928 if( isset($options['fulltable']['closebottom']) && strlen($options['fulltable']['closebottom']) > 0 ) {
929 echo 'bottom: '.$options['fulltable']['closebottom'].'px!important;';
930 }
931 if( isset($options['fulltable']['closeleft']) && strlen($options['fulltable']['closeleft']) > 0 ) {
932 echo 'left: '.$options['fulltable']['closeleft'].'px!important;';
933 }
934 if( isset($options['fulltable']['closeright']) && strlen($options['fulltable']['closeright']) > 0 ) {
935 echo 'right: '.$options['fulltable']['closeright'].'px!important;';
936 }
937 echo 'color: #'.str_replace( '#', '', $options['fulltable']['closecolor'] ).'!important;';
938 echo '}';
939 echo '.br_new_compare_block .br_same_attr {';
940 echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolorsame'] ).'!important;';
941 echo '}';
942 echo '</style>';
943 }
944 //OTHER STYLE
945 echo '<style>';
946 echo '.berocket_compare_widget_start .berocket_compare_widget .berocket_open_compare ,';
947 echo '.berocket_compare_widget_toolbar .berocket_compare_widget .berocket_open_compare {';
948 echo 'border-color: #'.str_replace( '#', '', $options['button']['bcolor'] ).';';
949 echo 'border-width: '.$options['button']['bwidth'].'px;';
950 echo 'border-radius: '.$options['button']['bradius'].'px;';
951 echo 'font-size: '.$options['button']['fontsize'].'px;';
952 echo 'color: #'.str_replace( '#', '', $options['button']['fcolor'] ).';';
953 echo 'background-color: #'.str_replace( '#', '', $options['button']['backcolor'] ).';';
954 echo '}';
955 echo '.berocket_compare_widget_start .berocket_show_compare_toolbar {';
956 echo 'border-color: #'.str_replace( '#', '', $options['toolbutton']['bcolor'] ).';';
957 echo 'border-width: '.$options['toolbutton']['bwidth'].'px;';
958 echo 'border-radius: '.$options['toolbutton']['bradius'].'px;';
959 echo 'font-size: '.$options['toolbutton']['fontsize'].'px;';
960 echo 'color: #'.str_replace( '#', '', $options['toolbutton']['fcolor'] ).';';
961 echo 'background-color: #'.str_replace( '#', '', $options['toolbutton']['backcolor'] ).';';
962 echo '}';
963 echo '.br_compare_button {';
964 echo 'background-color: #'.str_replace( '#', '', $options['comparebutton']['backcolor'] ).'!important;';
965 echo 'color: #'.str_replace( '#', '', $options['comparebutton']['color'] ).'!important;';
966 if( isset($options['comparebutton']['fontsize']) && strlen($options['comparebutton']['fontsize']) > 0 ) {
967 echo 'font-size: '.$options['comparebutton']['fontsize'].'px!important;';
968 }
969 if( isset($options['comparebutton']['width']) && strlen($options['comparebutton']['width']) > 0 ) {
970 echo 'width: '.$options['comparebutton']['width'].'px!important;';
971 }
972 echo '}';
973 echo '.button.br_compare_button:hover {';
974 echo 'background-color: #'.str_replace( '#', '', $options['comparebuttonhover']['backcolor'] ).'!important;';
975 echo 'color: #'.str_replace( '#', '', $options['comparebuttonhover']['color'] ).'!important;';
976 if( isset($options['comparebuttonhover']['fontsize']) && strlen($options['comparebuttonhover']['fontsize']) > 0 ) {
977 echo 'font-size: '.$options['comparebuttonhover']['fontsize'].'px!important;';
978 }
979 if( isset($options['comparebuttonhover']['width']) && strlen($options['comparebuttonhover']['width']) > 0 ) {
980 echo 'width: '.$options['comparebuttonhover']['width'].'px!important;';
981 }
982 echo '}';
983 echo '.br_compare_added {';
984 echo 'background-color: #'.str_replace( '#', '', $options['comparebuttonadded']['backcolor'] ).'!important;';
985 echo 'color: #'.str_replace( '#', '', $options['comparebuttonadded']['color'] ).'!important;';
986 if( isset($options['comparebuttonadded']['fontsize']) && strlen($options['comparebuttonadded']['fontsize']) > 0 ) {
987 echo 'font-size: '.$options['comparebuttonadded']['fontsize'].'px!important;';
988 }
989 if( isset($options['comparebuttonadded']['width']) && strlen($options['comparebuttonadded']['width']) > 0 ) {
990 echo 'width: '.$options['comparebuttonadded']['width'].'px!important;';
991 }
992 echo '}';
993 echo '</style>';
994 $javascript_css = $options_global['javascript_settings'];
995 if( ! empty($javascript_css['custom_css']) ) {
996 echo '<style>'.$javascript_css['custom_css'].'</style>';
997 }
998 }
999 public function admin_settings( $tabs_info = array(), $data = array() ) {
1000 $pages = get_pages();
1001 $pages_option = array();
1002 foreach($pages as $page) {
1003 $pages_option[] = array('value' => $page->ID, 'text' => $page->post_title);
1004 }
1005 parent::admin_settings(
1006 array(
1007 'General' => array(
1008 'icon' => 'cog',
1009 'name' => __( 'General', "products-compare-for-woocommerce" ),
1010 ),
1011 'Popup Templates' => array(
1012 'icon' => 'files-o',
1013 'name' => __( 'Popup Templates', "products-compare-for-woocommerce" ),
1014 ),
1015 'Style' => array(
1016 'icon' => 'eye',
1017 'name' => __( 'Style', "products-compare-for-woocommerce" ),
1018 ),
1019 'Text' => array(
1020 'icon' => 'align-center',
1021 'name' => __( 'Text', "products-compare-for-woocommerce" ),
1022 ),
1023 'Custom CSS/JavaScript' => array(
1024 'icon' => 'css3',
1025 'name' => __( 'Custom CSS/JavaScript', "products-compare-for-woocommerce" ),
1026 ),
1027 'License' => array(
1028 'icon' => 'unlock-alt',
1029 'link' => admin_url( 'admin.php?page=berocket_account' )
1030 ),
1031 ),
1032 array(
1033 'General' => array(
1034 'fast_compare' => array(
1035 "label" => __('Fast compare', 'products-compare-for-woocommerce'),
1036 "label_for" => __('Open compare table via AJAX on same page', 'products-compare-for-woocommerce'),
1037 "type" => "checkbox",
1038 "name" => array("general_settings", "fast_compare"),
1039 "value" => '1',
1040 ),
1041 'hide_same_button' => array(
1042 "label" => __('Hide attributes with same value', 'products-compare-for-woocommerce'),
1043 "items" => array(
1044 "hide_same_button" => array(
1045 "label_for" => __('Display button to hide/show attributes', 'products-compare-for-woocommerce'),
1046 "type" => "checkbox",
1047 "name" => array("general_settings", "hide_same_button"),
1048 "value" => '1',
1049 ),
1050 "hide_same_default" => array(
1051 "label_for" => __('Hide attributes by default', 'products-compare-for-woocommerce'),
1052 "label_be_for"=> '<br>',
1053 "type" => "checkbox",
1054 "name" => array("general_settings", "hide_same_default"),
1055 "value" => '1',
1056 ),
1057 ),
1058 ),
1059 'remove_all_compare' => array(
1060 "label" => __('Clear compare list', 'products-compare-for-woocommerce'),
1061 "label_for" => __('Display button to remove all products from compare', 'products-compare-for-woocommerce'),
1062 "type" => "checkbox",
1063 "name" => array("general_settings", "remove_all_compare"),
1064 "value" => '1',
1065 ),
1066 'compare_template' => array(
1067 "tr_class" => "berocket_compare_template_hidden",
1068 "label" => __( 'Compare template', "products-compare-for-woocommerce" ),
1069 "name" => array("general_settings", "compare_template"),
1070 "type" => "selectbox",
1071 "options" => array(
1072 array('value' => 'new-compare', 'text' => __( 'Static CSS Build', "products-compare-for-woocommerce" )),
1073 ),
1074 "value" => ''
1075 ),
1076 'button_position' => array(
1077 "label" => __( 'Button position Shop', "products-compare-for-woocommerce" ),
1078 "name" => array("general_settings", "button_position"),
1079 "type" => "selectbox",
1080 "options" => array(
1081 array('value' => 'before_all', 'text' => __( 'Before all', "products-compare-for-woocommerce" )),
1082 array('value' => 'after_image', 'text' => __( 'After Image', "products-compare-for-woocommerce" )),
1083 array('value' => 'after_title', 'text' => __( 'After Title', "products-compare-for-woocommerce" )),
1084 array('value' => 'after_price', 'text' => __( 'After Price', "products-compare-for-woocommerce" )),
1085 array('value' => 'after_add_to_cart', 'text' => __( 'After Add to cart button', "products-compare-for-woocommerce" )),
1086 array('value' => '', 'text' => __( '== Disable ==', "products-compare-for-woocommerce" )),
1087 ),
1088 "value" => ''
1089 ),
1090 'button_position_product' => array(
1091 "label" => __( 'Button position Product', "products-compare-for-woocommerce" ),
1092 "name" => "button_position_product",
1093 "type" => "selectbox",
1094 "options" => array(
1095 array('value' => 'before_all', 'text' => __( 'Before all', "products-compare-for-woocommerce" )),
1096 array('value' => 'after_image', 'text' => __( 'After Image', "products-compare-for-woocommerce" )),
1097 array('value' => 'after_title', 'text' => __( 'After Title', "products-compare-for-woocommerce" )),
1098 array('value' => 'after_price', 'text' => __( 'After Price', "products-compare-for-woocommerce" )),
1099 array('value' => 'after_add_to_cart', 'text' => __( 'After Add to cart button', "products-compare-for-woocommerce" )),
1100 array('value' => '', 'text' => __( '== Disable ==', "products-compare-for-woocommerce" )),
1101 ),
1102 "value" => ''
1103 ),
1104 'compare_page' => array(
1105 "label" => __( 'Compare Page', "products-compare-for-woocommerce" ),
1106 "name" => array("general_settings", "compare_page"),
1107 "type" => "selectbox",
1108 "options" => $pages_option,
1109 "value" => ''
1110 ),
1111 'remove_compare_table' => array(
1112 "label" => __('Remove compare table', 'products-compare-for-woocommerce'),
1113 "label_for" => __('Remove compare table on "Compare page"', 'products-compare-for-woocommerce'),
1114 "type" => "checkbox",
1115 "name" => array("general_settings", "remove_compare_table"),
1116 "value" => '1',
1117 ),
1118 'addthisID' => array(
1119 "label" => __('AddThis ID', 'products-compare-for-woocommerce'),
1120 "label_for" => ' ' . __('Your ID from AddThis site', 'products-compare-for-woocommerce') . ' <a target="_blank" href="https://www.addthis.com/">https://www.addthis.com/</a>',
1121 "type" => "text",
1122 "name" => array("general_settings", "addthisID"),
1123 "value" => '1',
1124 ),
1125 'use_full_screen' => array(
1126 "label" => __('Full screen button on compare page', 'products-compare-for-woocommerce'),
1127 "type" => "checkbox",
1128 "name" => array("general_settings", "use_full_screen"),
1129 "value" => '1',
1130 ),
1131 'apply_filters' => array(
1132 "label" => __('Apply Filters', 'products-compare-for-woocommerce'),
1133 "type" => "checkbox",
1134 "name" => array("apply_filters"),
1135 "label_for" => __('Apply filters from plugins(Use WP Query. Can cause some issues with compare tables)', 'products-compare-for-woocommerce'),
1136 "value" => '1',
1137 ),
1138 'attribute' => array(
1139 "label" => "",
1140 "section" => 'attributes'
1141 ),
1142 ),
1143 'Style' => array(
1144 'all_style' => array(
1145 "label" => "",
1146 "section" => 'all_style'
1147 ),
1148 ),
1149 'Text' => array(
1150 'compare' => array(
1151 "label" => __('Text on compare button', 'products-compare-for-woocommerce'),
1152 "type" => "text",
1153 "name" => array("text_settings", "compare"),
1154 "value" => '',
1155 ),
1156 'add_compare' => array(
1157 "label" => __('Add to compare button', 'products-compare-for-woocommerce'),
1158 "type" => "text",
1159 "name" => array("text_settings", "add_compare"),
1160 "value" => '',
1161 ),
1162 'added_compare' => array(
1163 "label" => __('Add to compare button if product added', 'products-compare-for-woocommerce'),
1164 "type" => "text",
1165 "name" => array("text_settings", "added_compare"),
1166 "value" => '',
1167 ),
1168 'toolbar' => array(
1169 "label" => __('Text on button for toolbar open', 'products-compare-for-woocommerce'),
1170 "type" => "text",
1171 "name" => array("text_settings", "toolbar"),
1172 "value" => '',
1173 ),
1174 'attribute' => array(
1175 "label" => __('Attribute text', 'products-compare-for-woocommerce'),
1176 "type" => "text",
1177 "name" => array("text_settings", "attribute"),
1178 "value" => '',
1179 ),
1180 'custom' => array(
1181 "label" => __('Custom taxonomies text', 'products-compare-for-woocommerce'),
1182 "type" => "text",
1183 "name" => array("text_settings", "custom"),
1184 "value" => '',
1185 ),
1186 'availability' => array(
1187 "label" => __('Availability text', 'products-compare-for-woocommerce'),
1188 "type" => "text",
1189 "name" => array("text_settings", "availability"),
1190 "value" => '',
1191 ),
1192 'description' => array(
1193 "label" => __('Description text', 'products-compare-for-woocommerce'),
1194 "type" => "text",
1195 "name" => array("text_settings", "description"),
1196 "value" => '',
1197 ),
1198 'remove_all_compare_text' => array(
1199 "label" => __('Clear compare list Button text', 'products-compare-for-woocommerce'),
1200 "type" => "text",
1201 "name" => array("text_settings", "remove_all_compare_text"),
1202 "extra" => 'placeholder="'.__( 'Clear compare list', 'products-compare-for-woocommerce' ).'"',
1203 "value" => '',
1204 ),
1205 'hide_same_button_text' => array(
1206 "label" => __('Hide attributes with same value Button text', 'products-compare-for-woocommerce'),
1207 "type" => "text",
1208 "name" => array("text_settings", "hide_same_button_text"),
1209 "extra" => 'placeholder="'.__( 'Hide attributes with same values', 'products-compare-for-woocommerce' ).'"',
1210 "value" => '',
1211 ),
1212 'show_same_button_text' => array(
1213 "label" => __('Show attributes with same value Button text', 'products-compare-for-woocommerce'),
1214 "type" => "text",
1215 "name" => array("text_settings", "show_same_button_text"),
1216 "extra" => 'placeholder="'.__( 'Show attributes with same values', 'products-compare-for-woocommerce' ).'"',
1217 "value" => '',
1218 ),
1219 ),
1220 'Custom CSS/JavaScript' => array(
1221 array(
1222 "label" => __("Custom CSS", 'products-compare-for-woocommerce'),
1223 "name" => array("javascript_settings", "custom_css"),
1224 "type" => "textarea",
1225 "value" => "",
1226 ),
1227 array(
1228 "label" => __("JavaScript Before products load", 'products-compare-for-woocommerce'),
1229 "name" => array("javascript_settings", "before_load"),
1230 "type" => "textarea",
1231 "value" => "",
1232 ),
1233 array(
1234 "label" => __("JavaScript After products load", 'products-compare-for-woocommerce'),
1235 "name" => array("javascript_settings", "after_load"),
1236 "type" => "textarea",
1237 "value" => "",
1238 ),
1239 array(
1240 "label" => __("JavaScript Before remove product", 'products-compare-for-woocommerce'),
1241 "name" => array("javascript_settings", "before_remove"),
1242 "type" => "textarea",
1243 "value" => "",
1244 ),
1245 array(
1246 "label" => __("JavaScript After remove product", 'products-compare-for-woocommerce'),
1247 "name" => array("javascript_settings", "after_remove"),
1248 "type" => "textarea",
1249 "value" => "",
1250 ),
1251 ),
1252 'Popup Templates' => array(
1253 'templates' => array(
1254 "label" => "",
1255 "section" => 'templates'
1256 ),
1257 )
1258 ) );
1259 }
1260 public function section_attributes($data, $options_global) {
1261 $options = $options_global['general_settings'];
1262 $settings_name = $this->values['settings_name'];
1263 $html = '<th>' . __( 'Uses Attributes', 'products-compare-for-woocommerce' ) . '</th>
1264 <td>' . __( 'Select attributes that will be displayed on compare table', 'products-compare-for-woocommerce' ) . '</td>
1265 </tr>
1266 <tr><th></th><td>';
1267 $attributes = get_taxonomies();
1268 unset( $attributes['category']);
1269 unset( $attributes['post_tag']);
1270 unset( $attributes['nav_menu']);
1271 unset( $attributes['link_category']);
1272 unset( $attributes['post_format']);
1273 unset( $attributes['product_type']);
1274 unset( $attributes['product_tag']);
1275 unset( $attributes['product_shipping_class']);
1276 foreach ( $attributes as $key_attr => $attr ) {
1277 $tax = get_taxonomy( $attr );
1278 $attributes[$key_attr] = $tax->labels->singular_name;
1279 }
1280 $attributes = array(
1281 'cp_price' => __('Price', 'products-compare-for-woocommerce'),
1282 'cp_add_to_cart' => __('Add To Cart Button', 'products-compare-for-woocommerce'),
1283 'cp_short_description' => __('Short Description', 'products-compare-for-woocommerce'),
1284 'cp_available' => __('Availability', 'products-compare-for-woocommerce'),
1285 'cp_image' => __('Image', 'products-compare-for-woocommerce'),
1286 ) + $attributes;
1287 foreach ( $attributes as $attr => $attr_label ) {
1288 $checked = '';
1289 if ( ( is_array( $options['attributes'] ) && in_array( $attr, $options['attributes'] ) ) || ! is_array( $options['attributes'] ) || count( $options['attributes'] ) == 0 ) {
1290 $checked = ' checked';
1291 }
1292 $html .= '<p><label><input name="' . $settings_name . '[general_settings][attributes][]" type="checkbox" value="' . $attr . '"' . $checked . '>' . $attr_label . '</label></p>';
1293 }
1294 if( function_exists('acf_get_field_groups') ) {
1295 $groups = acf_get_field_groups();
1296 if ( is_array( $groups ) ) {
1297 foreach ( $groups as $group ) {
1298 $fields = acf_get_fields($group);
1299 if( is_array($fields) ) {
1300 foreach($fields as $field) {
1301 $checked = '';
1302 if ( is_array( $options['attributes'] ) && isset( $options['attributes']['acf_br_fields'] ) && is_array( $options['attributes']['acf_br_fields'] ) && in_array($field['name'], $options['attributes']['acf_br_fields']) ) {
1303 $checked = ' checked';
1304 }
1305 $html .= '<p><label>
1306 <input name="' . $settings_name . '[general_settings][attributes][acf_br_fields][]" type="checkbox" value="' . $field['name'] . '"' . $checked . '>
1307 <strong>ACF </strong><small>[' . $group['title'] . ']</small> ' . $field['label'] . '
1308 </label></p>';
1309 }
1310 }
1311 }
1312 }
1313 }
1314 $html .= '</td>';
1315 return $html;
1316 }
1317 public function section_all_style($data, $options_global) {
1318 $settings_name = $this->values['settings_name'];
1319 $options = $options_global['style_settings'];
1320 $defaults = $this->defaults['style_settings'];
1321 ob_start();
1322 include('templates/style_section.php');
1323 return ob_get_clean();
1324 }
1325 public function divi_initialize_extension() {
1326 if( class_exists('DiviExtension') ) {
1327 require_once plugin_dir_path( __FILE__ ) . 'divi/includes/CompareExtension.php';
1328 }
1329 }
1330 }
1331
1332 new BeRocket_Compare_Products;
1333