<?php
/**
 * WooCommerce theme integrations.
 *
 * @subpackage storecraft
 * @since 1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Remove default WooCommerce breadcrumbs (theme header/breadcrumb handles navigation).
 */
function storecraft_woocommerce_setup() {
	remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
}
add_action( 'init', 'storecraft_woocommerce_setup' );

/**
 * Show primary product category above the title on single product pages.
 */
function storecraft_single_product_category() {
	if ( ! is_product() ) {
		return;
	}

	$terms = get_the_terms( get_the_ID(), 'product_cat' );
	if ( empty( $terms ) || is_wp_error( $terms ) ) {
		return;
	}

	echo '<div class="hbs-product-category">' . esc_html( $terms[0]->name ) . '</div>';
}
add_action( 'woocommerce_single_product_summary', 'storecraft_single_product_category', 4 );

/**
 * Add body class on single product pages.
 *
 * @param array $classes Body classes.
 * @return array
 */
function storecraft_single_product_body_class( $classes ) {
	if ( function_exists( 'is_product' ) && is_product() ) {
		$classes[] = 'hbs-single-product-page';
	}

	return $classes;
}
add_filter( 'body_class', 'storecraft_single_product_body_class' );
