<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}






function shrk_yith_wcqv_init() {
	if ( class_exists( 'YITH_WCQV_Frontend' ) ) {
		$yith_wcqv = YITH_WCQV_Frontend();

		// Remove default placement
		remove_action( 'woocommerce_after_shop_loop_item',   array( $yith_wcqv, 'yith_add_quick_view_button' ), 15 );
		remove_action( 'yith_wcwl_table_after_product_name', array( $yith_wcqv, 'yith_add_quick_view_button' ), 15 );

		// Add to custom theme location
		add_action( 'woocommerce_after_shop_loop_item_title', 'shrk_yith_add_quick_view_button', 15 );
		add_action( 'yith_wcwl_table_after_product_name',     'shrk_yith_add_quick_view_button', 15 );

		if ( get_option( 'yith-wcqv-enable-mobile' ) != 'yes' ) {
			add_filter( 'body_class', function ( $c ) { 
				$c[] = 'wcqv-no-mobile'; 
				return $c;
			});
		}
	}
}
add_action( 'after_setup_theme', 'shrk_yith_wcqv_init' );

/**
 * Replace yith function with this one 
 * to add tooltip
 */
function shrk_yith_add_quick_view_button() {
	global $product;

	$label = get_option( 'yith-wcqv-button-label' );

	echo '<a href="#" class="button yith-wcqv-button" data-product_id="' . esc_attr( $product->get_id() ) . '"><div class="tooltip">' . esc_html( $label ) . '</div><span class="btn-text">' . esc_html( $label ) . '</span></a>';
}

?>