<?php
/**
 * Woocommerce Compatibility 
 *
 * @package Moesia
 */

/**
 * Declare support
 */
add_theme_support( 'woocommerce' );

/**
 * Remove WooCommerce wrappers
 */
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

/**
 * Add the wrappers for the theme
 */
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);

function my_theme_wrapper_start() {
	echo '<div id="primary" class="content-area">';
		echo '<main id="main" class="site-main" role="main">';
}

function my_theme_wrapper_end() {
		echo '</main>';
	echo '</div>';
}

/**
 * Remove default WooCommerce CSS
 */

add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
	unset( $enqueue_styles['woocommerce-general'] );	// Remove the gloss
	return $enqueue_styles;
}

/**
 * Enqueue custom CSS for Woocommerce
 */
function moesia_woocommerce_css() {
	if ( class_exists('WooCommerce') ) {
    	wp_enqueue_style( 'moesia-wc-css', get_template_directory_uri() . '/woocommerce/css/wc.css' );
	}
}
add_action( 'wp_enqueue_scripts', 'moesia_woocommerce_css' );

/**
 * Add short product description on WC categories
 */
function moesia_product_desc() {
	$content = get_the_content();
	$trimmed = wp_trim_words( $content, 20 );
	echo '<div class="wc-excerpt">' . $trimmed . '</div>';
}
add_action( 'woocommerce_after_shop_loop_item', 'moesia_product_desc', 9 );
