PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.3.2
Ever Compare – Products Compare Plugin for WooCommerce v1.3.2
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / includes / classes / Frontend / Manage_Compare.php

Manage_Compare.php in Ever Compare – Products Compare Plugin for WooCommerce 1.3.2, at includes/classes/Frontend/Manage_Compare.php

688 lines 24.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EverCompare\Frontend;
3 /**
4 * Button handlers class
5 */
6 class Manage_Compare {
7
8 /**
9 * [$_instance]
10 * @var null
11 */
12 private static $_instance = null;
13
14 /**
15 * [$reached_max_limit]
16 * @var boolean
17 */
18 public $reached_max_limit = false;
19
20 public $max_limit;
21
22 /**
23 * [instance] Initializes a singleton instance
24 * @return [Compare_Button]
25 */
26 public static function instance() {
27 if ( is_null( self::$_instance ) ) {
28 self::$_instance = new self();
29 }
30 return self::$_instance;
31 }
32
33 /**
34 * Initialize the class
35 */
36 private function __construct() {
37 $this->max_limit = intval( ever_compare_get_option( 'limit','ever_compare_table_settings_tabs', get_option( 'posts_per_page' ) ));
38 add_action( 'init', [ $this, 'button_manager' ] );
39 add_action( 'ever_compare_before_table', [ $this, 'reached_max_limit_message' ], 1 );
40 add_action( 'ever_compare_after_table', [ $this, 'shareable_link' ], 1 );
41 }
42
43 /**
44 * [compare_button]
45 * @return [void]
46 */
47 public function button_print(){
48 echo do_shortcode( '[evercompare_button]' );
49 }
50
51 /**
52 * [button_manager] Button Manager
53 * @return [void]
54 */
55 public function button_manager(){
56
57 $enable_btn = ever_compare_get_option( 'btn_show_shoppage', 'ever_compare_settings_tabs', 'off' );
58 $product_enable_btn = ever_compare_get_option( 'btn_show_productpage', 'ever_compare_settings_tabs', 'on' );
59
60 $shop_page_btn_position = ever_compare_get_option( 'shop_btn_position', 'ever_compare_settings_tabs', 'after_cart_btn' );
61 $product_page_btn_position = ever_compare_get_option( 'product_btn_position', 'ever_compare_settings_tabs', 'after_cart_btn' );
62
63
64 // Shop Button Position
65 if( $shop_page_btn_position != 'use_shortcode' && $enable_btn == 'on' ){
66 switch ( $shop_page_btn_position ) {
67
68 case 'before_cart_btn':
69 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'button_print' ], 7 );
70 break;
71
72 case 'top_thumbnail':
73 add_action( 'woocommerce_before_shop_loop_item', [ $this, 'button_print' ], 5 );
74 break;
75
76 case 'custom_position':
77 $hook_name = ever_compare_get_option( 'shop_custom_hook_name', 'ever_compare_settings_tabs', '' );
78 $priority = ever_compare_get_option( 'shop_custom_hook_priority', 'ever_compare_settings_tabs', 10 );
79 if( !empty( $hook_name ) ){
80 add_action( $hook_name, [ $this, 'button_print' ], $priority );
81 }
82 break;
83
84 default:
85 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'button_print' ], 20 );
86 break;
87
88 }
89 }
90
91 // Product Page Button Position
92 if( $product_page_btn_position != 'use_shortcode' && $product_enable_btn == 'on' ){
93 switch ( $product_page_btn_position ) {
94
95 case 'before_cart_btn':
96 add_action( 'woocommerce_before_add_to_cart_button', [ $this, 'button_print' ], 20 );
97 break;
98
99 case 'after_thumbnail':
100 add_action( 'woocommerce_product_thumbnails', [ $this, 'button_print' ], 21 );
101 break;
102
103 case 'after_summary':
104 add_action( 'woocommerce_after_single_product_summary', [ $this, 'button_print' ], 11 );
105 break;
106
107 case 'custom_position':
108 $hook_name = ever_compare_get_option( 'product_custom_hook_name', 'ever_compare_settings_tabs', '' );
109 $priority = ever_compare_get_option( 'product_custom_hook_priority', 'ever_compare_settings_tabs', 10 );
110 if( !empty( $hook_name ) ){
111 add_action( $hook_name, [ $this, 'button_print' ], $priority );
112 }
113 break;
114
115 default:
116 add_action( 'woocommerce_single_product_summary', [ $this, 'button_print' ], 31 );
117 break;
118 }
119 }
120
121 /**
122 * Popup HTML Render
123 */
124 if( ever_compare_get_option( 'open_popup', 'ever_compare_settings_tabs', 'on' ) === 'on' ){
125 add_action( 'wp_footer', [ $this, 'pop_up_html' ] );
126 }
127
128 /**
129 * Manage maximum product added message
130 */
131 if( isset( $_COOKIE[ 'ever_compare_max_limit' ] ) && $_COOKIE[ 'ever_compare_max_limit' ] == 'yes' ) {
132 setcookie( 'ever_compare_max_limit', 'no', 0, COOKIEPATH, COOKIE_DOMAIN, false, false );
133 $this->reached_max_limit = true;
134 }
135
136
137 }
138
139 /**
140 * [button_html] Button HTML
141 * @param [type] $atts
142 * @return [HTML]
143 */
144 public function button_html( $atts ) {
145 $button_attr = apply_filters( 'evercompare_button_arg', $atts );
146 return ever_compare_get_template( 'evercompare-button-'.$atts['template_name'].'.php', $button_attr, false );
147 }
148
149 /**
150 * [table_html] Wishlist table HTML
151 * @return [HTML]
152 */
153 public function table_html( $atts ) {
154 $table_attr = apply_filters( 'evercompare_table_arg', $atts );
155 return ever_compare_get_template( 'evercompare-table.php', $table_attr, false );
156 }
157
158 /**
159 * [count_html] Count HTML
160 * @param [type] $atts
161 * @return [HTML]
162 */
163 public function count_html( $atts ) {
164 $button_attr = apply_filters( 'evercompare_count_arg', $atts );
165 return ever_compare_get_template( 'evercompare-count.php', $button_attr, false );
166 }
167
168 /**
169 * [pop_up_html]
170 * @return [void]
171 */
172 public function pop_up_html(){
173 echo '<div class="htcompare-popup"><div class="htcompare-popup-content-area"><span class="htcompare-popup-close">&nbsp;</span>'.do_shortcode( '[evercompare_table]' ).'</div></div>';
174 }
175
176 /**
177 * [reached_max_limit_message]
178 * @return [void]
179 */
180 public function reached_max_limit_message(){
181 if( ! $this->reached_max_limit ) {
182 return;
183 }
184
185 $message = !empty( ever_compare_get_option('reached_max_limit_message','ever_compare_table_settings_tabs') ) ? ever_compare_get_option('reached_max_limit_message','ever_compare_table_settings_tabs') : esc_html__( 'You are already added the maximum number of products.', 'ever-compare' );
186 echo '<div class="ever-compare-message-error"><p>'. wp_kses_post( $message ).'</p></div>';
187
188 }
189
190 /**
191 * [shareable_link]
192 * @return [void]
193 */
194 public function shareable_link(){
195
196 $shareable_link = ever_compare_get_option( 'enable_shareable_link','ever_compare_table_settings_tabs','off' );
197 if ( $shareable_link !== 'on' ) {
198 return;
199 }
200
201 $ids = $this->get_compared_products();
202
203 if ( isset( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
204 $query_perametter_ids = sanitize_text_field( wp_unslash($_GET['evcompare']) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
205 if( !empty( $query_perametter_ids ) ){
206 $ids = explode( ',', $query_perametter_ids );
207 }
208 }
209
210 $buttonText = ever_compare_get_option( 'shareable_link_button_text','ever_compare_table_settings_tabs','Copy shareable link' ) ? ever_compare_get_option( 'shareable_link_button_text','ever_compare_table_settings_tabs','Copy shareable link' ) : esc_html__( 'Copy shareable link', 'ever-compare' );
211 $aftercopy_buttonText = ever_compare_get_option( 'shareable_link_after_button_text','ever_compare_table_settings_tabs','Copied' ) ? ever_compare_get_option( 'shareable_link_after_button_text','ever_compare_table_settings_tabs','Copied' ) : esc_html__( 'Copied', 'ever-compare' );
212 $button_pos = ever_compare_get_option( 'linkshare_btn_pos','ever_compare_table_settings_tabs','right' );
213
214 $idsString = is_array( $ids ) ? implode( ',', $ids ) : '';
215 $shareablelink = $this->get_compare_page_url() . '?evcompare='.$idsString;
216 ?>
217 <div class="ever-compare-shareable-link <?php echo esc_attr( $button_pos );?>">
218 <button class="evercompare-copy-link" data-copytext="<?php echo esc_attr( $aftercopy_buttonText ); ?>" data-btntext="<?php echo esc_attr( $buttonText ); ?>"><?php echo esc_html($buttonText); ?></button>
219 <p style="display: none;" class="evercompare-share-link"><?php echo esc_html($shareablelink); ?></p>
220 </div>
221 <?php
222
223 }
224
225 /**
226 * [add_to_compare] Ajax callable function
227 */
228 public function add_to_compare( $id ) {
229
230 $cookie_name = $this->get_cookie_name();
231
232 if ( $this->is_product_in_compare( $id ) ) {
233 $this->compare_json_response();
234 }
235
236 $products = $this->get_compared_products();
237
238 // Reached Maximum Limit
239 if( $this->reached_max_limit() ) {
240 setcookie( 'ever_compare_max_limit', 'yes', 0, COOKIEPATH, COOKIE_DOMAIN, false, false );
241 $this->compare_json_response();
242 }
243
244 $products[] = $id;
245
246 setcookie( $cookie_name, wp_json_encode( $products ), 0, COOKIEPATH, COOKIE_DOMAIN, false, false );
247
248 $_COOKIE[$cookie_name] = wp_json_encode( $products );
249
250 $this->compare_json_response();
251
252 }
253
254 /**
255 * [reached_max_limit]
256 * @return [bool]
257 */
258 public function reached_max_limit(){
259
260 $products = $this->get_compared_products();
261
262 if( $this->max_limit && count( $products ) >= $this->max_limit ) {
263 $this->reached_max_limit = true;
264 } else {
265 $this->reached_max_limit = false;
266 }
267
268 return $this->reached_max_limit;
269 }
270
271 /**
272 * [remove_from_compare] Ajax callable function
273 * @return [json]
274 */
275 public function remove_from_compare( $id ) {
276
277 $cookie_name = $this->get_cookie_name();
278
279 if ( ! $this->is_product_in_compare( $id ) ) {
280 $this->compare_json_response();
281 }
282
283 $products = $this->get_compared_products();
284
285 foreach ( $products as $prod_key => $product_id ) {
286 if ( intval( $id ) == $product_id ) {
287 unset( $products[ $prod_key ] );
288 $this->reached_max_limit = false;
289 }
290 }
291
292 if ( empty( $products ) ) {
293 setcookie( $cookie_name, false, 0, COOKIEPATH, COOKIE_DOMAIN, false, false );
294 $_COOKIE[$cookie_name] = false;
295 } else {
296 setcookie( $cookie_name, wp_json_encode( $products ), 0, COOKIEPATH, COOKIE_DOMAIN, false, false );
297 $_COOKIE[$cookie_name] = wp_json_encode( $products );
298 }
299
300 $this->compare_json_response();
301 }
302
303 /**
304 * [get_response_html ] Compare product table HTML
305 * @return [html]
306 */
307 public function get_response_html(){
308
309 $products = $this->get_compared_products_data();
310 $fields = $this->get_compare_fields();
311
312 $empty_compare_text = ever_compare_get_option('empty_table_text','ever_compare_table_settings_tabs');
313 $return_shop_button = ever_compare_get_option('shop_button_text','ever_compare_table_settings_tabs','Return to shop');
314
315 $custom_heading = !empty( ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) : array();
316
317 $default_atts = array(
318 'evercompare' => self::instance(),
319 'products' => $products,
320 'fields' => $fields,
321 'heading_txt' => $custom_heading,
322 'return_shop_button' => $return_shop_button,
323 'empty_compare_text' => $empty_compare_text,
324 );
325 $table_attr = apply_filters( 'evercompare_response_html_args', $default_atts );
326
327 ever_compare_get_template( 'evercompare-table.php', $table_attr );
328
329 }
330
331 /**
332 * [get_compared_products_data] generate compared products data
333 * @return [array] product list
334 */
335 public function get_compared_products_data() {
336 $ids = $this->get_compared_products();
337
338 // For shareable link
339 $shareable_link = ever_compare_get_option('enable_shareable_link','ever_compare_table_settings_tabs','off');
340 if ( ( $shareable_link === 'on' ) && isset( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
341 $query_perametter_ids = sanitize_text_field( wp_unslash($_GET['evcompare']) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
342 if( !empty( $query_perametter_ids ) ){
343 $ids = explode( ',', $query_perametter_ids );
344 }
345 }
346
347 if ( empty( $ids ) ) {
348 return array();
349 }
350
351 $args = array(
352 'include' => $ids,
353 'limit' => $this->max_limit
354 );
355
356 $products = wc_get_products( $args );
357
358 $products_data = array();
359
360 $fields = $this->get_compare_fields();
361
362 $fields = array_filter( $fields, function( $field ) {
363 return 'pa_' === substr( $field, 0, 3 );
364 }, ARRAY_FILTER_USE_KEY );
365
366 $data_none = '-';
367
368 foreach ( $products as $product ) {
369
370 $rating_count = $product->get_rating_count();
371 $average = $product->get_average_rating();
372
373 $products_data[ $product->get_id() ] = array(
374 'primary' => array(
375 'image' => $product->get_image() ? $product->get_image('ever-compare-image') : $data_none,
376 ),
377 'id' => $product->get_id(),
378 'title' => $product->get_title() ? $product->get_title() : $data_none,
379 'image_id' => $product->get_image_id(),
380 'permalink' => $product->get_permalink(),
381 'price' => $product->get_price_html() ? $product->get_price_html() : $data_none,
382 'rating' => wc_get_rating_html( $average, $rating_count ),
383 'add_to_cart' => $this->add_to_cart_html( $product ) ? $this->add_to_cart_html( $product ) :$data_none,
384 'dimensions' => wc_format_dimensions( $product->get_dimensions( false ) ),
385 'description' => $product->get_short_description() ? $product->get_short_description() : $data_none,
386 'weight' => $product->get_weight() ? $product->get_weight() : $data_none,
387 'sku' => $product->get_sku() ? $product->get_sku() : $data_none,
388 'availability' => $this->availability_html( $product ),
389 );
390
391 foreach ( $fields as $field_id => $field_name ) {
392 if ( taxonomy_exists( $field_id ) ) {
393 $products_data[ $product->get_id() ][ $field_id ] = array();
394 $terms = get_the_terms( $product->get_id(), $field_id );
395 if ( ! empty( $terms ) ) {
396 foreach ( $terms as $term ) {
397 $term = sanitize_term( $term, $field_id );
398 $products_data[ $product->get_id() ][ $field_id ][] = $term->name;
399 }
400 } else {
401 $products_data[ $product->get_id() ][ $field_id ][] = '-';
402 }
403 $products_data[ $product->get_id() ][ $field_id ] = implode( ', ', $products_data[ $product->get_id() ][ $field_id ] );
404 }
405 }
406 }
407
408 return $products_data;
409 }
410
411 /**
412 * [get_compare_fields] Table field list
413 * @return [array] Table Field list
414 */
415 public function get_compare_fields() {
416 $fields = array(
417 'primary' => ''
418 );
419
420 $default_show = array(
421 'title' => esc_html__( 'title', 'ever-compare' ),
422 'ratting' => esc_html__( 'ratting', 'ever-compare' ),
423 'price' => esc_html__( 'price', 'ever-compare' ),
424 'add_to_cart' => esc_html__( 'add_to_cart', 'ever-compare' ),
425 'description' => esc_html__( 'description', 'ever-compare' ),
426 'availability' => esc_html__( 'availability', 'ever-compare' ),
427 'sku' => esc_html__( 'sku', 'ever-compare' ),
428 'weight' => esc_html__( 'weight', 'ever-compare' ),
429 'dimensions' => esc_html__( 'dimensions', 'ever-compare' ),
430 );
431
432 $fields_settings = !empty( ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) : array();
433
434 if ( isset( $fields_settings ) && count( $fields_settings ) > 1 ) {
435 $fields = $fields + $fields_settings;
436 }else{
437 $fields = $fields + $default_show;
438 }
439
440 return $fields;
441 }
442
443 /**
444 * [is_products_have_field]
445 * @param [string] $field_id
446 * @param [object] $products
447 * @return boolean
448 */
449 public function is_products_have_field( $field_id, $products ) {
450 foreach ( $products as $product_id => $product ) {
451 if ( isset( $product[ $field_id ] ) && ( ! empty( $product[ $field_id ] ) && '-' !== $product[ $field_id ] && 'N/A' !== $product[ $field_id ] ) ) {
452 return true;
453 }
454 }
455 return false;
456 }
457
458 /**
459 * [compare_display_field]
460 * @param [string] $field_id
461 * @param [array] $product
462 * @return [html]
463 */
464 public function compare_display_field( $field_id, $product ) {
465
466 $type = $field_id;
467
468 if ( 'pa_' === substr( $field_id, 0, 3 ) ) {
469 $type = 'attribute';
470 }
471
472 switch ( $type ) {
473 case 'primary':
474 ?>
475 <div class="htcompare-primary-content-area">
476 <a href="#" class="htcompare-remove" data-product_title="<?php echo esc_attr( $product['title'] ); ?>" data-product_id="<?php echo esc_attr( $product['id'] ); ?>">&nbsp;</a>
477 <a href="<?php echo esc_url(get_permalink( $product['id'] )); ?>" class="htcompare-product-image">
478 <?php echo wp_kses_post($product['primary']['image']); ?>
479 </a>
480 </div>
481 <?php
482 break;
483
484 case 'title':
485 echo '<a href="'.esc_url(get_permalink( $product['id'] )).'" class="htcompare-product-title">'.esc_html($product[ $field_id ]).'</a>';
486 break;
487
488 case 'ratting':
489 echo '<span class="htcompare-product-ratting">'.wp_kses_post( $product[ $field_id ] ).'</span>';
490 break;
491
492 case 'price':
493 echo '<div class="htcompare-product-price">'.wp_kses_post( $product[ $field_id ] ).'</div>';
494 break;
495
496 case 'add_to_cart':
497 echo wp_kses_post(apply_filters( 'htcompare_add_to_cart_btn', $product[ $field_id ] ));
498 break;
499
500 case 'attribute':
501 echo wp_kses_post( $product[ $field_id ] );
502 break;
503
504 case 'weight':
505 if ( $product[ $field_id ] ) {
506 $unit = $product[ $field_id ] !== '-' ? get_option( 'woocommerce_weight_unit' ) : '';
507 echo wp_kses_post(wc_format_localized_decimal( $product[ $field_id ] )) . ' ' . esc_attr( $unit );
508 }
509 break;
510
511 case 'description':
512 echo wp_kses_post(apply_filters( 'woocommerce_short_description', $product[ $field_id ] ));
513 break;
514
515 default:
516 echo wp_kses_post( $product[ $field_id ] );
517 break;
518 }
519 }
520
521 /**
522 * [add_to_cart_html] Generate Cart button
523 * @param [object] $product
524 */
525 public function add_to_cart_html( $product ) {
526 if ( ! $product ) return;
527
528 $defaults = array(
529 'quantity' => 1,
530 'class' => implode( ' ', array_filter( array(
531 'htcompare-cart-button button',
532 'product_type_' . $product->get_type(),
533 $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
534 $product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
535 ) ) ),
536 'attributes' => array(
537 'data-product_id' => $product->get_id(),
538 'data-product_sku' => $product->get_sku(),
539 'aria-label' => $product->add_to_cart_description(),
540 'rel' => 'nofollow',
541 ),
542 );
543
544 $args = apply_filters( 'woocommerce_loop_add_to_cart_args', $defaults, $product );
545
546 if ( isset( $args['attributes']['aria-label'] ) ) {
547 $args['attributes']['aria-label'] = wp_strip_all_tags( $args['attributes']['aria-label'] );
548 }
549
550 return apply_filters( 'woocommerce_loop_add_to_cart_link',
551 sprintf( '<a href="%s" data-quantity="%s" class="%s add-to-cart-loop" %s><span>%s</span></a>',
552 esc_url( $product->add_to_cart_url() ),
553 esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
554 esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
555 isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
556 esc_html( $product->add_to_cart_text() )
557 ),
558 $product, $args );
559 }
560
561 /**
562 * [availability_html]
563 * @param [object] $product
564 * @return [html]
565 */
566 public function availability_html( $product ) {
567 $html = '';
568 $availability = $product->get_availability();
569
570 if( empty( $availability['availability'] ) ) {
571 $availability['availability'] = __( 'In stock', 'woocommerce' );
572 }
573
574 if ( ! empty( $availability['availability'] ) ) {
575 ob_start();
576
577 wc_get_template( 'single-product/stock.php', array(
578 'product' => $product,
579 'class' => $availability['class'],
580 'availability' => $availability['availability'],
581 ) );
582
583 $html = ob_get_clean();
584 }
585
586 return apply_filters( 'woocommerce_get_stock_html', $html, $product );
587 }
588
589 /**
590 * [compare_cookie_name] Get Compare cookie name
591 * @return [string]
592 */
593 public function get_cookie_name() {
594 $name = 'ever_compare_compare_list';
595 if ( is_multisite() ){
596 $name .= '_' . get_current_blog_id();
597 }
598 return $name;
599 }
600
601 /**
602 * [is_product_in_compare]
603 * @param [int] $id product id
604 * @return [array] product id list
605 */
606 public function is_product_in_compare( $id ) {
607 $list = $this->get_compared_products();
608 return in_array( strval($id), $list, true );
609 }
610
611 /**
612 * [get_compared_products]
613 * @return [json]
614 */
615 public function get_compared_products() {
616 $cookie_name = $this->get_cookie_name();
617 if(!empty( $_COOKIE[ $cookie_name ] )) {
618 return json_decode( sanitize_text_field(wp_unslash( $_COOKIE[ $cookie_name ] )), true );
619 }
620 return [];
621 }
622
623 /**
624 * [compare_json_response]
625 * @return [json] product json
626 */
627 public function compare_json_response() {
628 $count = 0;
629 $products = $this->get_compared_products();
630
631 ob_start();
632
633 $this->get_response_html();
634
635 $table_html = ob_get_clean();
636
637 if ( is_array( $products ) ) {
638 $count = count( $products );
639 }
640
641 $res = [
642 'count' => $count,
643 'table' => $table_html,
644 'products' => $products,
645 'limitReached' => '<div class="ever-compare-message-error"><p>'. wp_kses_post( esc_html__( 'You have already added the maximum number of products.', 'ever-compare' ) ).'</p></div>'
646 ];
647 wp_send_json( $res );
648
649 }
650
651 /**
652 * [get_compare_page_url] Compare Page Link
653 * @return [URL]
654 */
655 public function get_compare_page_url() {
656 $page_id = ever_compare_get_option( 'compare_page', 'ever_compare_table_settings_tabs' );
657 return get_permalink( $page_id );
658 }
659
660 /**
661 * [field_name]
662 * @param [string] $field
663 * @return [string]
664 */
665 public function field_name( $field = '', $custom = false ){
666
667 if( empty( $field ) ){
668 return;
669 }
670
671 if( $custom === true ){
672 return $field;
673 }
674
675 $default = ever_compare_get_default_fields();
676
677 $str = substr( $field, 0, 3 );
678 if( 'pa_' === $str ){
679 $field_name = wc_attribute_label( $field );
680 }else{
681 $field_name = $default[$field];
682 }
683 return $field_name;
684
685 }
686
687
688 }