<commit_before><?php
/*
Plugin Name: DISTRIBUIDORA GC - TRUPER Image Placeholder
Plugin URI: http://developercats.com
Description: Plugin for WooCommerce to replace the default image placeholder for the TRUPER image.
Author: <NAME>
Version: 1.0
Author URI: http://developercats.com
*/

add_action( 'init', 'custom_fix_thumbnail' );
 
function custom_fix_thumbnail() {
	add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
   
	function custom_woocommerce_placeholder_img_src( $src ) {
		global $product;
		$upload_dir = wp_upload_dir();
		$uploads = untrailingslashit( $upload_dir['baseurl'] );
		$src = 'http://www.truperenlinea.com/reng/info/fichas/img/ch/' . $product->get_sku() . '.jpg';

		if ( ! imageExists($src) ) {
			$src = WC()->plugin_url() . '/assets/images/placeholder.png';
		} else {
			// # @TODO Fix image size when none square source is provided. 
			// add_filter( 'woocommerce_get_image_size_shop_single', 'wptt_single_image_size' );
		}
		return $src;
	}

	// function wptt_single_image_size( $size ){
	//     $size['width'] = '150';
	//     $size['height'] = '150';
	//     return $size;		 
	// }

	function imageExists( $src ) {
		$file_headers = @get_headers($src);
		if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
			return false;
		}
		return true;
	}

}<commit_msg>Fix to display products in products section; it was crashing.<commit_after><?php
/*
Plugin Name: DISTRIBUIDORA GC - TRUPER Image Placeholder
Plugin URI: http://developercats.com
Description: Plugin for WooCommerce to replace the default image placeholder for the TRUPER image.
Author: <NAME>
Version: 1.0
Author URI: http://developercats.com
*/

add_action( 'init', 'custom_fix_thumbnail' );

function custom_fix_thumbnail() {
	if ($_GET['post_type']!='product' && $_GET['action']!='edit')
	add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
   
	function custom_woocommerce_placeholder_img_src( $src ) {
		global $product;
		$upload_dir = wp_upload_dir();
		$uploads = untrailingslashit( $upload_dir['baseurl'] );
		$src = 'http://www.truperenlinea.com/reng/info/fichas/img/gr/' . $product->get_sku() . '.jpg';

		if ( ! imageExists($src) ) {
			$src = WC()->plugin_url() . '/assets/images/placeholder.png';
		}
		return $src;
	}

	function imageExists( $src ) {
		$file_headers = @get_headers($src);
		if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
			return false;
		}
		return true;
	}

}
{'fraction_non_alphanumeric': 0.15160113498175923, 'fraction_numerical': 0.008917713822456425, 'mean_word_length': 4.436123348017621, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613771', 'n_tokens_mistral': 933, 'n_tokens_neox': 869, 'n_words': 183}