| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugisn Options value |
| 4 |
* return on/off |
| 5 |
*/ |
| 6 |
function ever_compare_get_option( $option, $section, $default = '' ){ |
| 7 |
$options = get_option( $section ); |
| 8 |
if ( isset( $options[$option] ) ) { |
| 9 |
return $options[$option]; |
| 10 |
} |
| 11 |
return $default; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* [ever_compare_woocommerce_installed] |
| 16 |
* @return [boolean] |
| 17 |
*/ |
| 18 |
function ever_compare_woocommerce_installed() { |
| 19 |
return class_exists( 'WooCommerce' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Get Post List |
| 24 |
* return array |
| 25 |
*/ |
| 26 |
function ever_compare_get_post_list( $post_type = 'page' ){ |
| 27 |
$options = array(); |
| 28 |
$options['0'] = __('Select','ever-compare'); |
| 29 |
$perpage = -1; |
| 30 |
$all_post = array( 'posts_per_page' => $perpage, 'post_type'=> $post_type ); |
| 31 |
$post_terms = get_posts( $all_post ); |
| 32 |
if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ){ |
| 33 |
foreach ( $post_terms as $term ) { |
| 34 |
$options[ $term->ID ] = $term->post_title; |
| 35 |
} |
| 36 |
return $options; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* [ever_compare_locate_template] |
| 42 |
* @param [string] $tmp_name Template name |
| 43 |
* @return [Template path] |
| 44 |
*/ |
| 45 |
function ever_compare_locate_template( $tmp_name ) { |
| 46 |
$woo_tmp_base = WC()->template_path(); |
| 47 |
|
| 48 |
$woo_tmp_path = $woo_tmp_base . $tmp_name; //active theme directory/woocommerce/ |
| 49 |
$theme_tmp_path = '/' . $tmp_name; //active theme root directory |
| 50 |
$plugin_tmp_path = EVERCOMPARE_DIR . 'includes/templates/' . $tmp_name; |
| 51 |
|
| 52 |
$located = locate_template( [ $woo_tmp_path, $theme_tmp_path ] ); |
| 53 |
|
| 54 |
if ( ! $located && file_exists( $plugin_tmp_path ) ) { |
| 55 |
return apply_filters( 'evercompare_locate_template', $plugin_tmp_path, $tmp_name ); |
| 56 |
} |
| 57 |
|
| 58 |
return apply_filters( 'evercompare_locate_template', $located, $tmp_name ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* [ever_compare_get_template] |
| 63 |
* @param [string] $tmp_name Template name |
| 64 |
* @param [array] $args template argument array |
| 65 |
* @param boolean $echo |
| 66 |
* @return [void] |
| 67 |
*/ |
| 68 |
function ever_compare_get_template( $tmp_name, $args = null, $echo = true ) { |
| 69 |
$located = ever_compare_locate_template( $tmp_name ); |
| 70 |
|
| 71 |
if ( $args && is_array( $args ) ) { |
| 72 |
extract( $args ); |
| 73 |
} |
| 74 |
|
| 75 |
if ( $echo !== true ) { ob_start(); } |
| 76 |
|
| 77 |
// include file located. |
| 78 |
include( $located ); |
| 79 |
|
| 80 |
if ( $echo !== true ) { return ob_get_clean(); } |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
/** |
| 86 |
* Get Post List |
| 87 |
* return array |
| 88 |
*/ |
| 89 |
function ever_compare_get_available_attributes() { |
| 90 |
$attribute_list = array(); |
| 91 |
|
| 92 |
if( function_exists( 'wc_get_attribute_taxonomies' ) ) { |
| 93 |
$attribute_list = wc_get_attribute_taxonomies(); |
| 94 |
} |
| 95 |
|
| 96 |
$checked = !empty( ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) : array(); |
| 97 |
|
| 98 |
$fields = array( |
| 99 |
'title' => esc_html__( 'Title', 'ever-compare' ), |
| 100 |
'ratting' => esc_html__( 'Ratting', 'ever-compare' ), |
| 101 |
'price' => esc_html__( 'Price', 'ever-compare' ), |
| 102 |
'add_to_cart' => esc_html__( 'Add To Cart', 'ever-compare' ), |
| 103 |
'description' => esc_html__( 'Description', 'ever-compare' ), |
| 104 |
'availability' => esc_html__( 'Availability', 'ever-compare' ), |
| 105 |
'sku' => esc_html__( 'Sku', 'ever-compare' ), |
| 106 |
'weight' => esc_html__( 'Weight', 'ever-compare' ), |
| 107 |
'dimensions' => esc_html__( 'Dimensions', 'ever-compare' ), |
| 108 |
); |
| 109 |
|
| 110 |
$fields = array_merge( $checked, $fields ); |
| 111 |
|
| 112 |
if ( count( $attribute_list ) > 0 ) { |
| 113 |
foreach ( $attribute_list as $attribute ) { |
| 114 |
$fields[ 'pa_' . $attribute->attribute_name ] = $attribute->attribute_label; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
return $fields; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* [ever_compare_table_active_heading] |
| 123 |
* @return [array] |
| 124 |
*/ |
| 125 |
function ever_compare_table_active_heading(){ |
| 126 |
$active_heading = !empty( ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) : array(); |
| 127 |
return $active_heading; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* [ever_compare_table_heading] |
| 132 |
* @return [array] |
| 133 |
*/ |
| 134 |
function ever_compare_table_heading(){ |
| 135 |
$new_list = array(); |
| 136 |
$default = array( |
| 137 |
'title' => esc_html__( 'Title', 'ever-compare' ), |
| 138 |
'ratting' => esc_html__( 'Ratting', 'ever-compare' ), |
| 139 |
'price' => esc_html__( 'Price', 'ever-compare' ), |
| 140 |
'add_to_cart' => esc_html__( 'Add to cart', 'ever-compare' ), |
| 141 |
'description' => esc_html__( 'Description', 'ever-compare' ), |
| 142 |
'availability' => esc_html__( 'Availability', 'ever-compare' ), |
| 143 |
'sku' => esc_html__( 'Sku', 'ever-compare' ), |
| 144 |
'weight' => esc_html__( 'Weight', 'ever-compare' ), |
| 145 |
'dimensions' => esc_html__( 'Dimensions', 'ever-compare' ), |
| 146 |
); |
| 147 |
$field_list = count( ever_compare_table_active_heading() ) > 0 ? ever_compare_table_active_heading() : $default; |
| 148 |
foreach ( $field_list as $key => $value ) { |
| 149 |
$new_list[$key] = \EverCompare\Frontend\Manage_Compare::instance()->field_name( $value ); |
| 150 |
} |
| 151 |
return $new_list; |
| 152 |
} |