<?php
/**
 * Single Product tabs
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     2.0.0
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Filter tabs and allow third parties to add their own
 *
 * Each tab is an array containing title, callback and priority.
 * @see woocommerce_default_product_tabs()
 */

function sf_add_desc_tab($tabs = array()) {
	global $post;
	$product_description = sf_get_post_meta($post->ID, 'sf_product_description', true);
	if ($product_description != "") {
		$tabs['description'] = array(
			'title'    => __( 'Description', 'woocommerce' ),
			'priority' => 10,
			'callback' => 'woocommerce_product_description_tab'
		);
	}
	return $tabs;
}
add_filter('woocommerce_product_tabs', 'sf_add_desc_tab', 0);
 
$tabs = apply_filters( 'woocommerce_product_tabs', array() );

$options = get_option('sf_neighborhood_options');
if (isset($options['enable_default_tabs'])) {
	$enable_default_tabs = $options['enable_default_tabs'];
} else {
	$enable_default_tabs = false;
}

if ( ! empty( $tabs ) ) : ?>	
	
	<?php if ($enable_default_tabs) { ?>

	<div class="woocommerce-tabs">
		<ul class="tabs">
			<?php foreach ( $tabs as $key => $tab ) : ?>

				<li class="<?php echo $key ?>_tab">
					<a href="#tab-<?php echo $key ?>"><?php echo apply_filters( 'woocommerce_product_' . $key . '_tab_title', $tab['title'], $key ) ?></a>
				</li>

			<?php endforeach; ?>
		</ul>
		<?php foreach ( $tabs as $key => $tab ) : ?>

			<div class="panel entry-content" id="tab-<?php echo $key ?>">
				<?php call_user_func( $tab['callback'], $key, $tab ) ?>
			</div>

		<?php endforeach; ?>
	</div>
	
	<?php } else { ?>
			
	<div class="accordion" id="product-accordion">
					
		<?php foreach ( $tabs as $key => $tab ) : ?>			
		
		<div class="accordion-group">
			<div class="accordion-heading">
				<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#product-accordion" href="#product-<?php echo $key ?>">
					<?php echo apply_filters( 'woocommerce_product_' . $key . '_tab_title', $tab['title'], $key ) ?>
				</a>
	    	</div>
	    	<div id="product-<?php echo $key ?>" class="accordion-body collapse">
	      		<div class="accordion-inner">
	      			<?php call_user_func( $tab['callback'], $key, $tab ) ?>
	      		</div>
	  		</div>
		</div>
		<?php endforeach; ?>
		
	</div>
	
	<?php } ?>

<?php endif; ?>