<?php

/**
 * FILE: functions-product-overlays.php
 * REF:  https://wp-tutorials.tech/refine-wordpress/add-woocommerce-product-overlays/
 *
 * Add WooCommerce Product Overlays (WPO), text & HTML, to product cards.
 * Add this to your functions.php file:
 *
 *   const WPO_IS_ENABLED = true;
 *   const WPO_IN_CART = false;
 *   require_once 'functions-product-overlays.php';
 */

// Block direct access.
defined('WPINC') || die();

/**
 * Given a product_id, return the overlays as HTML that can be
 * added inside the produc's div container.
 */
 
 
function wpo_get_overlays(int $product_id) {
	
	global $family;
	
	
	
   $html = '';

	  $prodclass=get_the_title($product_id);
	  $prodclass=strtolower($prodclass);
	  $prodclass = str_replace(' ', '-', $prodclass);
	   
      $html .= '<div class="prod-overlay location-'.$prodclass.'">';
	  
	  if(isset($_GET['id'])){
		  
	  //setcookie("family",$_GET["id"],time()+3600,"/",'familycresting.com');
	  
	  $family=$_GET["id"];
	  
	  //$meta = wp_get_attachment_metadata($query->ID);
	 //var_dump($meta); exit;
	 
	  
	  $image=wp_get_attachment_image($_GET['id'],'full');
	  }
	  else{
		  //if(isset($_COOKIE['family'])) $image=wp_get_attachment_image($_COOKIE['family'],'full');
		  
		  if(isset($family)) $image=wp_get_attachment_image($family,'full');
			  
		  }
      
	  $html .=$image;
      $html .= '</div>'; // .prod-overlay


   return $html;
}



//For Shop Page


function wpo_before_shop_loop_item_title() {
  
      $product_id = get_the_ID();
      echo wpo_get_overlays($product_id);
   
}
add_action('woocommerce_before_shop_loop_item_title', 'wpo_before_shop_loop_item_title', 9);


     
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
     
	
add_filter( 'woocommerce_product_tabs', 'my_remove_product_tabs', 98 );
 
function my_remove_product_tabs( $tabs ) {
  unset( $tabs['additional_information'] ); // To remove the additional information tab
  return $tabs;
}	
	  
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_show_product_thumbnails', 25 );



 add_action( 'woocommerce_before_single_product_summary', 'add_replacement_product_image', 20 );

//For Single Product Page
function add_replacement_product_image(){
    
    echo '<div id="single-product" class="woocommerce-product-gallery images">';
	$product_id = get_the_ID();
	$image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ), 'single-post-thumbnail' ); 
                 
    $product_id = get_the_ID();
      echo wpo_get_overlays($product_id); ?>
				 
    <img src="<?php  echo $image[0]; ?>" data-id="<?php echo $loop->post->ID; ?>">
	
<?php
 
   echo '</div>';
  
}



 
 
