<?php

/**
 * Provide a public-facing view for the plugin
 *
 * This file is used to markup the public-facing aspects of the plugin.
 *
 * @link       https://wondercode.pro/
 * @since      1.0.0
 *
 * @package    Awesome_Designs_For_Woocommerce
 * @subpackage Awesome_Designs_For_Woocommerce/public/partials
 */

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}


add_filter( 'woocommerce_product_get_image', 'awesome_designs_for_woocommerce_product_get_image', 10, 6 );

function awesome_designs_for_woocommerce_product_get_image( $image, $product, $size, $attr, $placeholder, $image_size ) {
    // Verify and initialize attributes
    if ( ! is_array( $attr ) ) {
        $attr = array();
    }

    if ( ! is_bool( $placeholder ) ) {
        $placeholder = true;
    }

    // Apply filter to get the image size
    $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size );

    // Retrieve the product image with modified attributes, avoiding infinite recursion
    remove_filter( 'woocommerce_product_get_image', 'awesome_designs_for_woocommerce_product_get_image', 10, 6 );
    $image = $product->get_image( $image_size, $attr, $placeholder );
    add_filter( 'woocommerce_product_get_image', 'awesome_designs_for_woocommerce_product_get_image', 10, 6 );

    // Wrap the image in a span with a custom class
    $image = '<span class="adfw-product-thumb">' . $image . '</span>';

    return $image;
}