<?php
/**
 * WooCommerce Compatibility File
 *
 * @link https://woocommerce.com/
 *
 * @package Vite_Nera
 */

/**
 * WooCommerce setup function.
 *
 * @link https://docs.woocommerce.com/document/third-party-custom-theme-compatibility/
 * @link https://github.com/woocommerce/woocommerce/wiki/Enabling-product-gallery-features-(zoom,-swipe,-lightbox)
 * @link https://github.com/woocommerce/woocommerce/wiki/Declaring-WooCommerce-support-in-themes
 *
 * @return void
 */
function vite_nera_woocommerce_setup()
{
    add_theme_support(
        'woocommerce',
        array(
            'thumbnail_image_width' => 330,
            'single_image_width' => 900,
            'gallery_thumbnail_image_width' => 100,
            'product_grid' => array(
                'default_rows' => 3,
                'min_rows' => 1,
                'default_columns' => 4,
                'min_columns' => 3,
                'max_columns' => 4,
            ),
        )
    );
    add_theme_support('wc-product-gallery-zoom');
    add_theme_support('wc-product-gallery-lightbox');
    add_theme_support('wc-product-gallery-slider');
}

add_action('after_setup_theme', 'vite_nera_woocommerce_setup');

function vite_nera_woocommerce_widgets_init()
{
    register_sidebar(
        array(
            'name' => esc_html__('Shop Filters', 'vite-nera'),
            'id' => 'shop-filters',
            'description' => esc_html__('Add widgets here.', 'vite-nera'),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget' => '</section>',
            'before_title' => '<h4 class="widget-title">',
            'after_title' => '</h4>',
        )
    );

    register_sidebar(
        array(
            'name' => esc_html__('Shop Info', 'vite-nera'),
            'id' => 'shop-info',
            'description' => esc_html__('Add widgets here.', 'vite-nera'),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget' => '</section>',
            'before_title' => '<h4 class="widget-title">',
            'after_title' => '</h4>',
        )
    );
}

add_action('widgets_init', 'vite_nera_woocommerce_widgets_init');


/**
 * WooCommerce specific scripts & stylesheets.
 *
 * @return void
 */
function vite_nera_woocommerce_scripts()
{
    wp_enqueue_style('vite-nera-woocommerce-style', get_template_directory_uri() . '/woocommerce.css', array(), VITE_NERA_VERSION);
}

add_action('wp_enqueue_scripts', 'vite_nera_woocommerce_scripts');

/**
 * Disable the default WooCommerce stylesheet.
 *
 * Removing the default WooCommerce stylesheet and enqueing your own will
 * protect you during WooCommerce core updates.
 *
 * @link https://docs.woocommerce.com/document/disable-the-default-stylesheet/
 */
add_filter('woocommerce_enqueue_styles', '__return_empty_array');

/**
 * Add 'woocommerce-active' class to the body tag.
 *
 * @param  array $classes CSS classes applied to the body tag.
 * @return array $classes modified to include 'woocommerce-active' class.
 */
function vite_nera_woocommerce_active_body_class($classes)
{
    $classes[] = 'woocommerce-active';

    return $classes;
}

add_filter('body_class', 'vite_nera_woocommerce_active_body_class');

/**
 * Related Products Args.
 *
 * @param array $args related products args.
 * @return array $args related products args.
 */
function vite_nera_woocommerce_related_products_args($args)
{
    $defaults = array(
        'posts_per_page' => 5,
        'columns' => 5,
    );

    $args = wp_parse_args($defaults, $args);

    return $args;
}

add_filter('woocommerce_output_related_products_args', 'vite_nera_woocommerce_related_products_args');

/**
 * Remove default WooCommerce wrapper.
 */
remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

if (!function_exists('vite_nera_woocommerce_wrapper_before')) {
    /**
     * Before Content.
     *
     * Wraps all WooCommerce content in wrappers which match the theme markup.
     *
     * @return void
     */
    function vite_nera_woocommerce_wrapper_before()
    {
        ?>
        <main id="primary" class="site-main">
        <?php
    }
}
add_action('woocommerce_before_main_content', 'vite_nera_woocommerce_wrapper_before');

if (!function_exists('vite_nera_woocommerce_wrapper_after')) {
    /**
     * After Content.
     *
     * Closes the wrapping divs.
     *
     * @return void
     */
    function vite_nera_woocommerce_wrapper_after()
    {
        ?>
        </main><!-- #main -->
        <?php
    }
}
add_action('woocommerce_after_main_content', 'vite_nera_woocommerce_wrapper_after');

/**
 * Sample implementation of the WooCommerce Mini Cart.
 *
 * You can add the WooCommerce Mini Cart to header.php like so ...
 *
 * <?php
 * if ( function_exists( 'vite_nera_woocommerce_header_cart' ) ) {
 * vite_nera_woocommerce_header_cart();
 * }
 * ?>
 */

if (!function_exists('vite_nera_woocommerce_cart_link_fragment')) {
    /**
     * Cart Fragments.
     *
     * Ensure cart contents update when products are added to the cart via AJAX.
     *
     * @param array $fragments Fragments to refresh via AJAX.
     * @return array Fragments to refresh via AJAX.
     */
    function vite_nera_woocommerce_cart_link_fragment($fragments)
    {
        ob_start();
        vite_nera_woocommerce_cart_link();
        $fragments['a.cart-contents'] = ob_get_clean();

        return $fragments;
    }
}
add_filter('woocommerce_add_to_cart_fragments', 'vite_nera_woocommerce_cart_link_fragment');

if (!function_exists('vite_nera_woocommerce_cart_link')) {
    /**
     * Cart Link.
     *
     * Displayed a link to the cart including the number of items present and the cart total.
     *
     * @return void
     */
    function vite_nera_woocommerce_cart_link()
    {
        ?>
        <a class="cart-contents" href="<?php echo esc_url(wc_get_cart_url()); ?>"
           title="<?php esc_attr_e('View your shopping cart', 'vite-nera'); ?>">
            <span class="lnr lnr-cart"></span><span
                    class="count"><?php echo esc_html(WC()->cart->get_cart_contents_count()); ?></span>
        </a>
        <?php
    }
}

if (!function_exists('vite_nera_woocommerce_header_cart')) {
    /**
     * Display Header Cart.
     *
     * @return void
     */
    function vite_nera_woocommerce_header_cart()
    {
        if (is_cart()) {
            $class = 'current-menu-item';
        } else {
            $class = '';
        }
        ?>
        <ul id="site-header-cart" class="site-header-cart">
            <li class="<?php echo esc_attr($class); ?>">
                <?php vite_nera_woocommerce_cart_link(); ?>
            </li>
            <li>
                <?php
                $instance = array(
                    'title' => '',
                );

                the_widget('WC_Widget_Cart', $instance);
                ?>
            </li>
        </ul>
        <?php
    }
}

if (!function_exists('vite_nera_woocommerce_acoount_link')) {
    function vite_nera_woocommerce_acoount_link()
    {
        if (!get_option('woocommerce_myaccount_page_id')) {
            return;
        }

        ?>
        <div class="site-header-account">
            <a class="account-link" href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>"
               title="<?php esc_html_e('My Account', 'vite-nera'); ?>"><span class="lnr lnr-user"></span></a>
        </div>
        <?php
    }
}

if (!function_exists('vite_nera_woocommerce_header_search')) {
    function vite_nera_woocommerce_header_search()
    {
        ?>
        <div class="site-header-product-search">
            <button class="mobile-search-toggle">
                <span class="lnr lnr-magnifier"></span>
            </button>
            <div class="product-search-form-wrapper" id="product-search-form">
                <?php
                $instance = array(
                    'title' => '',
                );

                the_widget('WC_Widget_Product_Search', $instance);
                ?>

                <button class="mobile-search-toggle">
                    <span class="lnr lnr-cross"></span>
                </button>
            </div>
        </div>
        <?php
    }
}

if (!function_exists('vite_nera_woocommerce_header_actions')) {
    function vite_nera_woocommerce_header_actions()
    {
        ?>
        <div class="woo-header-actions">
            <?php
            if (function_exists('vite_nera_woocommerce_header_search')) {
                vite_nera_woocommerce_header_search();
            }

            if (function_exists('vite_nera_woocommerce_acoount_link')) {
                vite_nera_woocommerce_acoount_link();
            }

            if (function_exists('vite_nera_woocommerce_header_cart')) {
                vite_nera_woocommerce_header_cart();
            }
            ?>
        </div>
        <?php
    }
}

function vite_nera_woocommerce_shop_header()
{
    do_action('vite_nera_woocommerce_shop_header');
}

add_action('woocommerce_before_main_content', 'vite_nera_woocommerce_shop_header', 5);

add_action('vite_nera_woocommerce_shop_header', 'woocommerce_breadcrumb', 15);
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);

function vite_nera_woocommerce_render_archive_header()
{
    if (is_singular()) {
        return;
    }

    $img_url = vite_nera_woocommerce_get_shop_header_image_url();
    $class = $img_url ? 'has-image' : '';
    ?>
    <div class="woo-archive-header <?php echo esc_attr($class); ?>"
         style="background-image: url(<?php echo esc_url($img_url); ?>)">

        <div class="woo-archive-header-wrapper">
            <?php if (apply_filters('woocommerce_show_page_title', true)) : ?>
                <h2 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h2>
            <?php endif;
            do_action('woocommerce_archive_description');
            ?>
        </div>

    </div>
    <?php
}

add_action('vite_nera_woocommerce_shop_header', 'vite_nera_woocommerce_render_archive_header', 10);

function vite_nera_woocommerce_get_shop_header_image_url()
{
    $url = '';

    $id = wc_get_page_id('shop');
    if ($id && is_shop()) {
        $url = get_the_post_thumbnail_url($id, 'full');

    }

    if (is_tax() && function_exists('z_taxonomy_image_url')) {
        $tax = get_queried_object();
        $tax_img_url = z_taxonomy_image_url($tax->term_id);
        if ($tax_img_url) {
            $url = $tax_img_url;
        }
    }

    return $url;
}

function vite_nera_woocommerce_breadcrumbs_wrapper_open()
{
    ?>
    <div class="woo-breadcrumbs-container">
    <div class="woo-breadcrumbs-wrapper">
    <?php
}

add_action('vite_nera_woocommerce_shop_header', 'vite_nera_woocommerce_breadcrumbs_wrapper_open', 13);

function vite_nera_woocommerce_breadcrumbs_wrapper_close()
{
    if (is_archive() && is_active_sidebar('shop-filters')):
        ?>
        <button class="woo-mobile-filters-open"><?php esc_html_e('Filters', 'vite-nera'); ?></button>
    <?php
    endif;
    ?>
    </div>
    </div>
    <?php
}

add_action('vite_nera_woocommerce_shop_header', 'vite_nera_woocommerce_breadcrumbs_wrapper_close', 17);


remove_action('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10);
add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5);

remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5);
add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 15);

add_action('woocommerce_before_shop_loop_item_title', 'vite_nera_woocommerce_thumbnail_wrapper_open', 5);
add_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5);

function vite_nera_woocommerce_thumbnail_wrapper_open()
{
    ?>
    <div class="woo-product-thumbnail-wrapper">
    <?php
}

add_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 15);
add_action('woocommerce_before_shop_loop_item_title', 'vite_nera_woocommerce_thumbnail_wrapper_close', 15);

function vite_nera_woocommerce_thumbnail_wrapper_close()
{
    ?>
    </div>
    <?php
}

remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);

function vite_nera_woocommerce_add_to_cart_wrapper_open()
{
    ?>
    <div class="add-to-cart-wrapper">
    <?php
}

function vite_nera_woocommerce_add_to_cart_wrapper_close()
{
    ?>
    </div>
    <?php
}

add_action('woocommerce_before_shop_loop_item_title', 'vite_nera_woocommerce_add_to_cart_wrapper_open', 10);
add_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10);
add_action('woocommerce_before_shop_loop_item_title', 'vite_nera_woocommerce_add_to_cart_wrapper_close', 10);

//remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5);
//add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_rating', 1);
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_price', 1);

add_action('woocommerce_before_shop_loop', 'vite_nera_change_rating_html');

function vite_nera_change_rating_html()
{
    add_filter('woocommerce_product_get_rating_html', 'vite_nera_woocommerce_rating_html', 10, 3);
}

function vite_nera_woocommerce_rating_html($html, $rating, $count)
{
    global $product;

    if (0 < $rating) {
        $reviews_count_html = "<div class='reviews-count'>({$product->get_review_count()})</div>";
        $html = "<div class='star-rating-wrapper'>{$html}{$reviews_count_html}</div>";
    }

    return $html;
}

add_filter('woocommerce_pagination_args', 'vite_nera_woocommerce_filter_pagination');

function vite_nera_woocommerce_filter_pagination($args)
{
    $args['mid_size'] = 1;
    $args['prev_text'] = '<span class="lnr lnr-chevron-left">';
    $args['next_text'] = '<span class="lnr lnr-chevron-right">';
    $args['type'] = 'plain';
    return $args;
}

remove_action('woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10);
add_action('woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 30);

add_action('woocommerce_before_main_content', 'vite_nera_woocommerce_before_shop_loop', 35);

function vite_nera_woocommerce_before_shop_loop()
{

    if (is_singular()) {
        return;
    }

    ?>
    <div class="woo-shop-wrapper">
    <div class="woo-shop-products-wrapper">
    <?php
}

//add_action('woocommerce_after_shop_loop', 'vite_nera_woocommerce_after_shop_loop', 20);
add_action('woocommerce_after_main_content', 'vite_nera_woocommerce_after_shop_loop', 5);

function vite_nera_woocommerce_after_shop_loop()
{

    if (is_singular()) {
        return;
    }

    ?>
    </div>
    <?php
    vite_nera_woocommerce_shop_sidebar();
    ?>
    </div>
    <?php
}

function vite_nera_woocommerce_shop_sidebar()
{
    if (!is_active_sidebar('shop-filters') && !is_active_sidebar('shop-info')) {
        return;
    }

    ?>
    <div class="woocommerce-widgets">
        <?php
        if (is_active_sidebar('shop-filters')):
            ?>
            <div class="widget-area shop-filters">
                <div class="shop-filters-wrapper">
                    <button class="woo-mobile-filters-close"><span class="lnr lnr-cross"></span></button>
                    <?php dynamic_sidebar('shop-filters'); ?>
                </div>
            </div>
        <?php
        endif;

        if (is_active_sidebar('shop-info')):
            ?>
            <div class="widget-area shop-info">
                <?php dynamic_sidebar('shop-info'); ?>
            </div>
        <?php
        endif;
        ?>
    </div>
    <?php
}

remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar', 10);

add_action('woocommerce_before_single_product_summary', 'vite_nera_woocommerce_before_single_product_summary', 5);

function vite_nera_woocommerce_before_single_product_summary()
{
    ?>
    <div class="woo-product-info-wrapper">
    <div class="woo-product-images-wrapper">
    <?php
}

add_action('woocommerce_before_single_product_summary', 'vite_nera_woocommerce_after_single_product_images', 25);

function vite_nera_woocommerce_after_single_product_images()
{
    ?>
    </div>
    <?php
}

add_action('woocommerce_after_single_product_summary', 'vite_nera_woocommerce_after_single_product_summary', 5);
function vite_nera_woocommerce_after_single_product_summary()
{
    ?>
    </div>
    <?php
}

add_filter('woocommerce_product_thumbnails_columns', 'vite_nera_woocommerce_product_thumbnails_columns', 10, 1);
function vite_nera_woocommerce_product_thumbnails_columns($columns)
{
    return 5;
}

add_filter('woocommerce_grouped_product_list_column_price', 'vite_nera_woocommerce_grouped_product_list_column_price', 10, 2);

function vite_nera_woocommerce_grouped_product_list_column_price($value, $grouped_product_child)
{
    $value = "<div class='price-wrapper'>{$value}</div>";

    return $value;
}

remove_action('woocommerce_review_before_comment_meta', 'woocommerce_review_display_rating', 10);
remove_action('woocommerce_review_meta', 'woocommerce_review_display_meta', 10);

add_action('woocommerce_review_before', 'vite_nera_woocommerce_review_header_before', 5);

function vite_nera_woocommerce_review_header_before()
{
    ?>
    <div class="woo-review-header">
    <?php
}

add_action('woocommerce_review_before', 'vite_nera_woocommerce_review_header_after', 40);

function vite_nera_woocommerce_review_header_after()
{
    ?>
    </div>
    <?php
}

add_action('woocommerce_review_before', 'vite_nera_woocommerce_review_meta_before', 15);

function vite_nera_woocommerce_review_meta_before()
{
    ?>
    <div class="woo-review-meta">
    <?php
}

add_action('woocommerce_review_before', 'vite_nera_woocommerce_review_meta_after', 35);

function vite_nera_woocommerce_review_meta_after()
{
    ?>
    </div>
    <?php
}

add_action('woocommerce_review_before', 'woocommerce_review_display_rating', 20);
add_action('woocommerce_review_before', 'woocommerce_review_display_meta', 30);

add_filter('woocommerce_upsells_total', 'vite_nera_woocommerce_upsells_total');

function vite_nera_woocommerce_upsells_total()
{
    return 5;
}

add_filter('woocommerce_upsells_columns', 'vite_nera_woocommerce_upsells_columns');

function vite_nera_woocommerce_upsells_columns()
{
    return 5;
}

add_filter('woocommerce_cross_sells_columns', 'vite_nera_woocommerce_cross_sells_columns');

function vite_nera_woocommerce_cross_sells_columns()
{
    return 5;
}

add_filter('woocommerce_cross_sells_total', 'vite_nera_woocommerce_cross_sells_total');

function vite_nera_woocommerce_cross_sells_total()
{
    return 5;
}

//remove_action('woocommerce_checkout_shipping', array(WC_Checkout::instance(), 'checkout_form_shipping'));

//add_action('woocommerce_checkout_before_order_review_heading', array(WC_Checkout::instance(), 'checkout_form_shipping'), 15);

//add_action('woocommerce_checkout_before_customer_details', 'vite_nera_woocommerce_checkout_column_open', 5);
//add_action('woocommerce_checkout_before_order_review_heading', 'vite_nera_woocommerce_checkout_column_open', 10);

function vite_nera_woocommerce_checkout_column_open()
{
    ?>
    <div class="checkout-column">
    <?php
}


//add_action('woocommerce_checkout_after_customer_details', 'vite_nera_woocommerce_checkout_column_close', 15);
//add_action('woocommerce_checkout_after_order_review', 'vite_nera_woocommerce_checkout_column_close', 15);

function vite_nera_woocommerce_checkout_column_close()
{
    ?>
    </div>
    <?php
}

add_action('woocommerce_no_products_found', 'vite_nera_woocommerce_no_products_found_before', 5);

function vite_nera_woocommerce_no_products_found_before()
{
    ?>
    <div class="woo-no-products-wrapper">
    <?php
}

add_action('woocommerce_no_products_found', 'vite_nera_woocommerce_no_products_found_after', 15);

function vite_nera_woocommerce_no_products_found_after()
{
    ?>
    </div>
    <?php
}

add_action('template_redirect', 'vite_nera_woocommerce_shop_ordering_filtering');

function vite_nera_woocommerce_shop_ordering_filtering()
{
    if (is_archive()) {
        add_action('woocommerce_before_main_content', 'woocommerce_output_all_notices', 30);
        add_action('woocommerce_before_main_content', 'vite_nera_woocommerce_shop_filtering_ordering_open', 40);
        add_action('woocommerce_before_main_content', 'woocommerce_result_count', 50);
        add_action('woocommerce_before_main_content', 'woocommerce_catalog_ordering', 60);
        add_action('woocommerce_before_main_content', 'vite_nera_woocommerce_shop_filtering_ordering_close', 70);
        add_action('woocommerce_before_main_content', 'vite_nera_woocommerce_active_filters', 80);
    }
}

remove_action('woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10);
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);

function vite_nera_woocommerce_active_filters()
{
    $instance = array(
        'title' => '',
    );

    ?>
    <div class="woo-shop-active-filters">
        <?php
        the_widget('WC_Widget_Layered_Nav_Filters', $instance);
        ?>
    </div>
    <?php
}

function vite_nera_woocommerce_shop_filtering_ordering_open()
{
    ?>
    <div class="woo-filtering-ordering">
    <?php
}

function vite_nera_woocommerce_shop_filtering_ordering_close()
{
    ?>
    </div>
    <?php
}

add_action('wp', 'vite_nera_setup_gridlist_view', 20);

function vite_nera_setup_gridlist_view()
{
    if (class_exists('WC_List_Grid') && !is_singular()) {
        global $WC_List_Grid;
        remove_action('woocommerce_before_shop_loop', array($WC_List_Grid, 'gridlist_toggle_button'), 30);
        add_action('woocommerce_before_main_content', array($WC_List_Grid, 'gridlist_toggle_button'), 45);
        add_action('woocommerce_before_shop_loop_item_title', 'vite_nera_grid_list_product_info_before', 20);
        add_action('woocommerce_after_shop_loop_item', 'vite_nera_grid_list_product_info_after', 30);
        add_action('woocommerce_after_shop_loop_item', 'vite_nera_grid_list_product_description_after', 5);
        add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_price', 7);
        add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
    }
}

function vite_nera_grid_list_product_info_before()
{
    ?>
    <div class="woo-grid-list-product-info">
    <div class="woo-grid-list-product-description">
    <?php
}

function vite_nera_grid_list_product_description_after(){
    ?>
    </div>
    <div class="woo-grid-list-product-price">
    <?php
}

function vite_nera_grid_list_product_info_after()
{
    ?>
    </div>
    </div>
    <?php
}

add_filter('gridlist_toggle_button_output', 'vite_nera_gridlist_toggle_button_output', 10, 3);

function vite_nera_gridlist_toggle_button_output($output, $grid_view, $list_view)
{

    $grid_svg = '<svg  width="16px" height="16px">
        <path fill-rule="evenodd"
        d="M14.000,10.000 C12.895,10.000 12.000,9.104 12.000,8.000 C12.000,6.895 12.895,6.000 14.000,6.000 C15.104,6.000 16.000,6.895 16.000,8.000 C16.000,9.104 15.104,10.000 14.000,10.000 ZM14.000,4.000 C12.895,4.000 12.000,3.104 12.000,2.000 C12.000,0.895 12.895,-0.000 14.000,-0.000 C15.104,-0.000 16.000,0.895 16.000,2.000 C16.000,3.104 15.104,4.000 14.000,4.000 ZM8.000,16.000 C6.895,16.000 6.000,15.104 6.000,14.000 C6.000,12.895 6.895,12.000 8.000,12.000 C9.104,12.000 10.000,12.895 10.000,14.000 C10.000,15.104 9.104,16.000 8.000,16.000 ZM8.000,10.000 C6.895,10.000 6.000,9.104 6.000,8.000 C6.000,6.895 6.895,6.000 8.000,6.000 C9.104,6.000 10.000,6.895 10.000,8.000 C10.000,9.104 9.104,10.000 8.000,10.000 ZM8.000,4.000 C6.895,4.000 6.000,3.104 6.000,2.000 C6.000,0.895 6.895,-0.000 8.000,-0.000 C9.104,-0.000 10.000,0.895 10.000,2.000 C10.000,3.104 9.104,4.000 8.000,4.000 ZM2.000,16.000 C0.895,16.000 0.000,15.104 0.000,14.000 C0.000,12.895 0.895,12.000 2.000,12.000 C3.105,12.000 4.000,12.895 4.000,14.000 C4.000,15.104 3.105,16.000 2.000,16.000 ZM2.000,10.000 C0.895,10.000 0.000,9.104 0.000,8.000 C0.000,6.895 0.895,6.000 2.000,6.000 C3.105,6.000 4.000,6.895 4.000,8.000 C4.000,9.104 3.105,10.000 2.000,10.000 ZM2.000,4.000 C0.895,4.000 0.000,3.104 0.000,2.000 C0.000,0.895 0.895,-0.000 2.000,-0.000 C3.105,-0.000 4.000,0.895 4.000,2.000 C4.000,3.104 3.105,4.000 2.000,4.000 ZM14.000,12.000 C15.104,12.000 16.000,12.895 16.000,14.000 C16.000,15.104 15.104,16.000 14.000,16.000 C12.895,16.000 12.000,15.104 12.000,14.000 C12.000,12.895 12.895,12.000 14.000,12.000 Z"/>
        </svg>';

    $list_svg = '<svg width="16px" height="16px">
        <path fill-rule="evenodd"
        d="M14.000,10.000 L2.000,10.000 C0.895,10.000 -0.000,9.104 -0.000,8.000 C-0.000,6.895 0.895,6.000 2.000,6.000 L14.000,6.000 C15.104,6.000 16.000,6.895 16.000,8.000 C16.000,9.104 15.104,10.000 14.000,10.000 ZM14.000,4.000 L2.000,4.000 C0.895,4.000 -0.000,3.104 -0.000,2.000 C-0.000,0.895 0.895,-0.000 2.000,-0.000 L14.000,-0.000 C15.104,-0.000 16.000,0.895 16.000,2.000 C16.000,3.104 15.104,4.000 14.000,4.000 ZM2.000,12.000 L14.000,12.000 C15.104,12.000 16.000,12.895 16.000,14.000 C16.000,15.104 15.104,16.000 14.000,16.000 L2.000,16.000 C0.895,16.000 -0.000,15.104 -0.000,14.000 C-0.000,12.895 0.895,12.000 2.000,12.000 Z"/>
        </svg>';

    $output = '';
    $output .= '<nav class="gridlist-toggle">';
    $output .= sprintf('<a href="#" id="grid" title="%1$s">%2$s</a>', $grid_view, $grid_svg);
    $output .= sprintf('<a href="#" id="list" title="%1$s">%2$s</a>', $list_view, $list_svg);
    $output .= '</nav>';

    return $output;
}

add_action('woocommerce_checkout_before_order_review_heading', 'vite_nera_woocommerce_checkout_before_order_review_heading');

function vite_nera_woocommerce_checkout_before_order_review_heading()
{
    ?>
    <div class="woo-order-review">
    <?php
}

add_action('woocommerce_checkout_after_order_review', 'vite_nera_woocommerce_checkout_after_order_review');

function vite_nera_woocommerce_checkout_after_order_review()
{
    ?>
    </div>
    <?php
}

add_action('woocommerce_before_subcategory_title', 'woocommerce_template_loop_category_link_close', 20);
add_action('woocommerce_before_subcategory_title', 'woocommerce_template_loop_category_link_open', 30);
add_action('woocommerce_before_subcategory_title', 'vite_nera_woocommerce_thumbnail_wrapper_open', 5);
add_action('woocommerce_before_subcategory_title', 'vite_nera_woocommerce_thumbnail_wrapper_close', 15);
add_filter('woocommerce_subcategory_count_html', '__return_false');

remove_action('woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10);
remove_action('woocommerce_archive_description', 'woocommerce_product_archive_description', 10);
add_action('woocommerce_archive_description', 'vite_nera_woocommerce_archive_description', 15);

function vite_nera_woocommerce_archive_description()
{
    if (is_shop()) {
        $shop_page = get_post(wc_get_page_id('shop'));
        if ($shop_page) {
            $description = wc_format_content($shop_page->post_content);
            if ($description) {
                echo '<div class="page-description">' . $description . '</div>'; // WPCS: XSS ok.
            }
        }
    }

    if (is_product_taxonomy()) {
        $term = get_queried_object();

        if ($term && !empty($term->description)) {
            echo '<div class="term-description">' . wc_format_content($term->description) . '</div>'; // WPCS: XSS ok.
        }
    }
}

add_filter('woocommerce_price_filter_widget_step', 'vite_nera_woocommerce_price_filter_widget_step');

function vite_nera_woocommerce_price_filter_widget_step()
{
    return 1;
}