$hooks_list_type ) { foreach ( $hooks_list_type as $hooks_display => $hooks_list ) { if ( $hooks_display === 'single' && ! is_singular( 'product' ) ) { continue; } foreach ( $hooks_list as $hook_name => $hook_vars ) { if ( isset( $hook_vars['js'] ) && is_array( $hook_vars['js'] ) ) { $label_selector = '.awl-label-type-' . $hooks_display . '.awl-position-type-' . sanitize_title( str_replace( '_', '-', $position ) ); $selectors[$label_selector] = $hook_vars['js']; } } } } } /** * Filter js selectors for labels * @since 1.00 * @param array $selectors Array of css selectors */ $selectors = apply_filters( 'awl_js_selectors', $selectors ); return $selectors; } /** * Get Labels post type * @since 1.0 * @param array $args Array of arguments * @return array List of label posts */ static public function get_awl_labels( $args = array() ) { $query_args = wp_parse_args( $args, array( 'post_type' => 'awl-labels', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_key' => '_awl_label_priority', 'orderby' => 'meta_value_num date', 'order' => 'DESC', 'update_post_term_cache' => false, 'fields' => 'ids', 'suppress_filters' => true, 'no_found_rows' => 1, 'lang' => '' ) ); $post_query = new WP_Query( $query_args ); $labels = $post_query->posts; return apply_filters( 'awl_get_labels', $labels ); } /** * Match label condition * @since 1.0 * @param array $conditions List of label conditions * @return bool */ static public function match_conditions( $conditions ) { $condition = new AWL_Conditions_Check( $conditions ); return $condition->match(); } /** * Get label text * @since 1.0 * @param array $label_settings Array of label settings * @return string */ static public function get_label_text( $label_settings ) { if ( ! $label_settings || ! isset( $label_settings['text'] ) ) { return ''; } $label_text = stripslashes( $label_settings['text'] ); if ( strpos( $label_text, '{' ) !== false && strpos( $label_text, '}' ) !== false ) { $label_text_obj = new AWL_Label_Text( $label_text ); $label_text = $label_text_obj->text(); } /** * Filter labels text * @since 1.00 * @param string $label_text * @param array $label_settings */ $label_text = apply_filters( 'awl_label_text', $label_text, $label_settings ); return $label_text; } /** * Get label markup * @since 1.0 * @param array $labels Array of labels * @param string $label_position_type Labels position * @return string */ static public function get_label_html( $labels, $label_position_type ) { if ( ! $labels || ! is_array( $labels ) || empty( $labels ) ) { return ''; } $global_settings = AWL()->get_settings(); $label_html_obj = new AWL_Label_View( $labels, $label_position_type, $global_settings ); return $label_html_obj->html(); } /** * Get label type ( single or archive ) * @since 1.0 * @return string */ static public function get_label_type() { global $wp_current_filter; $last_hook = end ( $wp_current_filter ); $single_hooks = array( 'woocommerce_product_thumbnails', 'woocommerce_single_product_summary', 'woocommerce_before_single_product_summary', 'woocommerce_before_single_product' ); if ( is_singular('product') && in_array( $last_hook, $single_hooks ) ) { return 'single'; } else { return 'archive'; } } /** * Get all available labels positions * @since 1.0 * @return array */ static public function get_labels_positions() { $settings_array = AWL_Admin_Options::include_label_settings(); $positions = array(); foreach ( $settings_array as $settings ) { foreach ( $settings as $setting ) { if ( $setting && isset( $setting['id'] ) && $setting['id'] === 'position_type' && isset( $setting['choices'] ) ) { foreach( $setting['choices'] as $pos_slug => $pos_name ) { $positions[] = array( 'slug' => $pos_slug, 'name' => $pos_name ); } break; } } } /** * Filter labels positions * @since 1.00 * @param array $positions */ $positions = apply_filters( 'awl_labels_positions', $positions ); return $positions; } /** * Get standard WooCommerce hooks * @since 1.0 * @return array */ static public function get_woocommerce_hooks() { $hooks = array( 'woocommerce_before_shop_loop_item', 'woocommerce_before_shop_loop_item_title', 'woocommerce_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item', 'woocommerce_before_single_product', 'woocommerce_before_single_product_summary', 'woocommerce_single_product_summary', 'woocommerce_after_single_product_summary', 'woocommerce_after_single_product', ); /** * Filter WooCommerce hooks * @since 1.00 * @param array $hooks */ $hooks = apply_filters( 'awl_woocommerce_hooks', $hooks ); return $hooks; } /* * Check weather one of language plugin active or not * @return bool */ static public function is_lang_plugin_active() { return function_exists( 'pll_current_language' ) || function_exists( 'qtranxf_getLanguage' ) || has_filter( 'wpml_active_languages' ); } /* * Get current active site language * * @return string Language code */ static public function get_current_lang() { $current_lang = ''; if ( ( defined( 'ICL_SITEPRESS_VERSION' ) || function_exists( 'pll_current_language' ) ) ) { if ( has_filter('wpml_current_language') ) { $current_lang = apply_filters( 'wpml_current_language', NULL ); } elseif ( function_exists( 'pll_current_language' ) ) { $current_lang = pll_current_language(); } } elseif( function_exists( 'qtranxf_getLanguage' ) ) { $current_lang = qtranxf_getLanguage(); } return $current_lang; } } endif;