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