<?php
/**
 * Product Category name
 *
 * This template can be overridden by copying it to yourtheme/smart-post-show-pro/templates/item/product-category-name.php
 *
 * @package    Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/public
 */

if ( $show_product_category_name ) {
	$allowed_html_tags = array(
		'em'     => array(),
		'strong' => array(),
		'sup'    => array(),
		'i'      => array(),
		'small'  => array(),
		'del'    => array(),
		'ins'    => array(),
		'br'     => array(),
		'span'   => array(
			'style' => array(),
			'class' => array(),
		),
	);
	?>
	<div class="sp-smart-post-product-cat">
	<?php
		$categories = get_the_terms( $post->ID, 'product_cat' );
	if ( $categories && ! is_wp_error( $categories ) ) {
		$unique_categories = array_unique( $categories, SORT_REGULAR );
		$category_names    = array();
		foreach ( $unique_categories as $category ) {
			$category_link    = get_term_link( $category, 'product_cat' );
			$category_names[] = $category->name;
		}
		$category_list = join( ', ', $category_names );
		?>
		<a href="<?php echo esc_url( $category_link ); ?>"><?php echo wp_kses( trim( $category_list ), $allowed_html_tags ); ?></a>
		<?php
	}
	?>
	</div>
	<?php
}
