get_id() : 0; } // Return if product doesn't exist. if ( empty( $product_id ) || apply_filters( 'yith_woocompare_remove_compare_link_by_cat', false, $product_id ) ) { return; } $is_button = ! isset( $button_or_link ) || ! $button_or_link ? get_option( 'yith_woocompare_is_button', 'button' ) : $button_or_link; if ( ! isset( $button_text ) || 'default' === $button_text ) { $button_text = get_option( 'yith_woocompare_button_text', __( 'Compare', 'ayyash' ) ); $compare_icon = get_option( 'ayyash_yith_woocompare_compare_icon', 'ai-compare' ); do_action( 'wpml_register_single_string', 'Plugins', 'plugin_yit_compare_button_text', $button_text ); $button_text = apply_filters( 'wpml_translate_single_string', $button_text, 'Plugins', 'plugin_yit_compare_button_text' ); } printf( '
%s
', $yith_woocompare->obj->add_product_url( $product_id ), 'compare' . ( 'button' === $is_button ? ' button' : '' ), $product_id, $compare_icon, $button_text ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * @return void */ function ayyash_handle_yith_compare_hooks() { /** @var YITH_Woocompare $yith_woocompare */ global $yith_woocompare; // Bail if yith compare not enabled. if ( ! isset( $yith_woocompare ) ) { // @phpstan-ignore-line return; } if ( ! $yith_woocompare->is_frontend() ) { return; } /** * APPLY_FILTERS: yith compare positions * * Filter the array of positions where to display the 'Add to wishlist' button in the product page. * * @param array $positions Array of positions * * @return array */ $positions = apply_filters( 'yith_compare_positions', array( 'after_add_to_cart' => array( 'hook' => 'woocommerce_single_product_summary', 'priority' => 31, ), 'add-to-cart' => array( 'hook' => 'woocommerce_single_product_summary', 'priority' => 31, ), 'thumbnails' => array( 'hook' => 'woocommerce_product_thumbnails', 'priority' => 21, ), 'summary' => array( 'hook' => 'woocommerce_after_single_product_summary', 'priority' => 11, ), 'inside_ayyash_product_actions' => array( 'hook' => 'ayyash_product_actions', 'priority' => 10, ), ) ); // Add the link "Add to Compare". $position = get_option('ayyash_yith_woocompare_position', 'inside_ayyash_product_actions'); if ( 'yes' === get_option( 'yith_woocompare_compare_button_in_product_page', 'yes' ) ) { remove_action( 'woocommerce_single_product_summary', [ $yith_woocompare->obj, 'add_compare_link' ], 35 ); // @phpstan-ignore-line if ( isset( $positions[ $position ] ) ) { add_action( $positions[ $position ]['hook'], 'ayyash_add_compare_link', $positions[ $position ]['priority'] ); } } if ( 'yes' === get_option( 'yith_woocompare_compare_button_in_products_list', 'no' ) ) { remove_action( 'woocommerce_after_shop_loop_item', [ $yith_woocompare->obj, 'add_compare_link' ], 20 ); // @phpstan-ignore-line add_action( 'woocommerce_after_shop_loop_item', 'ayyash_add_compare_link', 20 ); } } add_action( 'init', 'ayyash_handle_yith_compare_hooks', 12 ); if ( ! function_exists( 'ayyash_yith_compare_icons' ) ) { /** * Return array of available icons * * @param string $none_label Label to use for none option. * @param string $custom_label Label to use for custom option. * * @return array Array of available icons, in class => name format */ function ayyash_yith_compare_icons( $none_label = '', $custom_label = '' ) { $ayyash_icons = json_decode( file_get_contents( AYYASH_THEME_DIR . 'assets/ayyash-icons.json' ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $themify_icons = json_decode( file_get_contents( AYYASH_THEME_DIR . 'assets/themify-icons.json' ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $icons = array_merge( $ayyash_icons, $themify_icons ); $icons['none'] = $none_label ? $none_label : __( 'None', 'ayyash' ); $icons['custom'] = $custom_label ? $custom_label : __( 'Custom', 'ayyash' ); /** * APPLY_FILTERS: ayyash_yith_compare_icons * * Filter the icons used in the plugin. * * @param array $icons Icons * @param string $none_label Label to use for none option * @param string $custom_label Label to use for custom option * * @return array */ return apply_filters( 'ayyash_yith_compare_icons', $icons, $none_label, $custom_label ); } } /** * Ayyash YITH Compare custom tab * * @param $admin_tabs * * @return mixed */ function ayyash_yith_woocompare_admin_tab( $admin_tabs ) { $ayyash_admin_tab = array( 'ayyash_settings' => __( 'Ayyash Settings', 'ayyash' ), ); return array_merge( $admin_tabs, $ayyash_admin_tab ); } add_filter( 'yith_woocompare_admin_tabs', 'ayyash_yith_woocompare_admin_tab' ); /** * Yith Compare Position Settings * * @param $settings * * @return array */ function ayyash_yith_compare_position( $settings ) { $settings['ayyash_settings'][] = array( 'name' => __( 'Ayyash Settings', 'ayyash' ), 'type' => 'title', 'desc' => '', 'id' => 'ayyash_yith_woocompare', ); $settings['ayyash_settings'][] = array( 'name' => __( 'Ayyash single product position', 'ayyash' ), 'desc_tip' => __( 'Choose if you want to change compare button location for Product summary area.', 'ayyash' ), 'id' => 'ayyash_yith_woocompare_position', 'default' => 'inside_ayyash_product_actions', 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array( 'add-to-cart' => __( 'After "Add to cart"', 'ayyash' ), 'thumbnails' => __( 'After thumbnails', 'ayyash' ), 'summary' => __( 'After summary', 'ayyash' ), 'inside_ayyash_product_actions' => __( 'Inside Ayyash product actions', 'ayyash' ), ), ); $settings['ayyash_settings'][] = array( 'name' => __( '"Compare" icon', 'ayyash' ), 'desc' => __( 'Select an icon for Compare button', 'ayyash' ), 'id' => 'ayyash_yith_woocompare_compare_icon', 'default' => 'ai-compare', 'type' => 'yith-field', 'yith-type' => 'select', 'class' => 'icon-select', 'options' => ayyash_yith_compare_icons(), ); $settings['ayyash_settings'][] = array( 'type' => 'sectionend', 'id' => 'ayyash_yith_woocompare_end', ); return $settings; } add_filter('yith_woocompare_general_settings', 'ayyash_yith_compare_position'); /** * Yith Compare localize Settings * * @param $array * * @return array */ function thmeoo_yith_woocompare_localize_array( $array ) { $compare_icon = get_option( 'ayyash_yith_woocompare_compare_icon', 'ai-compare' ); $array['button_text'] = "" . get_option( 'yith_woocompare_button_text', __( 'Compare', 'ayyash' ) ) . ''; return $array; } add_filter( 'yith_woocompare_main_script_localize_array', 'thmeoo_yith_woocompare_localize_array' ); /** * Ayyash wishlist options * * @param $options * * @return array */ function ayyash_wishlist_options( $options ) { $options['add_to_wishlist']['add_to_wishlist_position']['options']['inside_themoo_product_actions'] = __( 'Inside Ayyash product actions', 'ayyash' ); return $options; } add_filter( 'yith_wcwl_add_to_wishlist_options', 'ayyash_wishlist_options' ); /** * Ayyash wishlist positions * * @param $positions * * @return array */ function ayyash_wishlist_positions( $positions ) { $positions['inside_themoo_product_actions'] = array( 'hook' => 'ayyash_product_actions', 'priority' => 10, ); return $positions; } add_filter( 'yith_wcwl_positions', 'ayyash_wishlist_positions' );