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