invp_get_the_carfax_icon_html( $post_ID = null )

invp_get_the_carfax_icon_html


Description Description

Outputs Carfax button HTML or empty string if the vehicle is not eligible or does not have a free report.


Top ↑

Return Return

(string) HTML that renders a Carfax button or empty string


Top ↑

Source Source

File: includes/template-tags.php

function invp_get_the_carfax_icon_html( $post_ID = null )
{
	if( empty( $post_ID ) )
	{
		$post_ID = get_the_ID();
	}

	//Does this vehicle have a Carfax-eligible VIN? 
	if( strlen( invp_get_the_VIN( $post_ID ) ) != 17 || invp_get_the_year( $post_ID ) < 1980 )
	{
		return '';
	}

	/**
	 * Do we have a report? Can't just rely on there being a report URL
	 * because as long as we have a VIN we can create a fallback report
	 * URL.
	 */
	if( ! invp_have_carfax_report( $post_ID ) )
	{
		return '';
	}

	$svg_url = invp_get_the_carfax_url_svg( $post_ID );
	if( empty( $svg_url ) )
	{
		return '';
	}

	return sprintf(
		'<a href="%s" target="_blank" rel="noopener noreferrer"><img src="%s" alt="SHOW ME THE CARFAX" /></a>',
		invp_get_the_carfax_url_report( $post_ID ),
		$svg_url
	);
}