
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

/* -----------------------------------------------------------------------------
 * Mandatory Functions
 * -------------------------------------------------------------------------- */

if ( ! function_exists( 'presso_has_woocommerce' ) ) {
	function presso_has_woocommerce() {
		return function_exists( 'is_woocommerce' );
	}
}

if ( ! function_exists( 'presso_is_woocommerce' ) ) {
	function presso_is_woocommerce() {
		return function_exists( 'is_woocommerce' ) && is_woocommerce();		
	}
}

if ( ! function_exists( 'presso_is_shop' ) ) {
	function presso_is_shop() {
		return function_exists( 'is_shop' ) && is_shop();
	}
}

if ( ! function_exists( 'presso_get_shop_page_id' ) ) {
	function presso_get_shop_page_id() {
		return wc_get_page_id( 'shop' );
	}
}

if ( ! function_exists( 'presso_woo_get_cart_permalink' ) ) {
	function presso_woo_get_cart_permalink() {
		global $woocommerce;
		return $woocommerce->cart->get_cart_url();
	}
}



/* ============================================================================= */
/* Avoid loading unnecessary code, For reduce memory usage */
if ( ! function_exists( 'is_woocommerce' ) ) return;
/* ============================================================================= */




/* -----------------------------------------------------------------------------
 * Custom WooCommerce Functions
 * -------------------------------------------------------------------------- */
/**
 * Enqueue Scripts
 */
add_action( 'wp_enqueue_scripts', 'presso_enqueue_woocommerce_script' );
if ( ! function_exists( 'presso_enqueue_woocommerce_script' ) ) {
	function presso_enqueue_woocommerce_script() {
		if ( presso_is_rtl() ) {
			// RTL styles
			wp_enqueue_style( 'vwcss-woocommerce-rtl', get_template_directory_uri().'/woocommerce-assets/css/custom-woocommerce-rtl.css', array( 'presso-css-theme' ), PRESSO_THEME_VERSION );
		} else {
			// Default styles
			wp_enqueue_style( 'vwcss-woocommerce', get_template_directory_uri().'/woocommerce-assets/css/custom-woocommerce.css', array( 'presso-css-theme' ), PRESSO_THEME_VERSION );
		}
	}
}

/**
 * Manage WooCommerce features
 */
add_action( 'after_setup_theme', 'presso_setup_woocommerce' );
if ( ! function_exists( 'presso_setup_woocommerce' ) ) {
	function presso_setup_woocommerce() {
		add_theme_support( 'woocommerce' );

		/* Remove page title */
		add_filter( 'woocommerce_show_page_title', '__return_false' );

		/* Hide archive description */
		// remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );

		/* Swap position */
		remove_filter( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
		add_filter( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 9 );
	}
}

/**
 * Remove WooCommerce style
 */
add_filter( 'woocommerce_enqueue_styles', 'presso_woocommerce_dequeue_styles' );
if ( ! function_exists( 'presso_woocommerce_dequeue_styles' ) ) {
	function presso_woocommerce_dequeue_styles( $enqueue_styles ) {
		/* Remove the gloss */
		unset( $enqueue_styles['woocommerce-general'] );
		
		/* Remove the layout */
		unset( $enqueue_styles['woocommerce-layout'] );

		/* Remove the small screen optimization */
		unset( $enqueue_styles['woocommerce-smallscreen'] );

		return $enqueue_styles;
	}
}

/**
 * Update image size for this theme
 */
add_action( 'after_switch_theme', 'presso_setup_woocommerce_image_dimensions' );
if ( ! function_exists( 'presso_setup_woocommerce_image_dimensions' ) ) {
	function presso_setup_woocommerce_image_dimensions() {
		$catalog = array(
			'width' 	=> '399',	// px
			'height'	=> '399',	// px
			'crop'		=> 1
		);
	 
		$single = array(
			'width' 	=> '608',	// px
			'height'	=> '608',	// px
			'crop'		=> 1
		);
	 
		$thumbnail = array(
			'width' 	=> '60',	// px
			'height'	=> '60',	// px
			'crop'		=> 1
		);
	 
		// Image sizes
		update_option( 'shop_catalog_image_size', $catalog ); 		// Product category thumbs
		update_option( 'shop_single_image_size', $single ); 		// Single product image
		update_option( 'shop_thumbnail_image_size', $thumbnail ); 	// Image gallery thumbs
	}
}

/**
 * Apply show breaking news option
 */
add_filter( 'presso_filter_is_enable_breaking_news', 'presso_woocommerce_is_enable_breaking_news' );
if ( ! function_exists( 'presso_woocommerce_is_enable_breaking_news' ) ) {
	function presso_woocommerce_is_enable_breaking_news( $is_enabled ) {
		if ( presso_is_woocommerce() ) {
			return presso_get_theme_option( 'woocommerce_show_breaking_news' );

		} else {
			return $is_enabled;
		}
	}
}

/**
 * Apply sidebar position option
 */
add_filter( 'presso_filter_sidebar_position', 'presso_woocommerce_sidebar_position' );
if ( ! function_exists( 'presso_woocommerce_sidebar_position' ) ) {
	function presso_woocommerce_sidebar_position( $sidebar_position ) {
		if ( presso_is_woocommerce() ) {
			$sidebar_position = presso_get_theme_option( 'blog_sidebar_position' );

			if ( is_product() ) {
				$sidebar_position = 'no';
				
			} else {
				$woo_sidebar_position = get_post_meta( presso_get_shop_page_id(), 'vw_sidebar_position', true );

				if ( $woo_sidebar_position != 'default' && ! empty( $woo_sidebar_position ) ) {
					$sidebar_position = $woo_sidebar_position;
				}
			}
		}
		
		return $sidebar_position;
	}
}

/**
 * Apply sidebar option
 */
add_filter( 'presso_filter_sidebar', 'presso_woocommerce_sidebar' );
if ( ! function_exists( 'presso_woocommerce_sidebar' ) ) {
	function presso_woocommerce_sidebar( $sidebar ) {
		if ( presso_is_woocommerce() ) {
			$sidebar = presso_get_theme_option( 'blog_default_sidebar' );

			$woo_sidebar = get_post_meta( presso_get_shop_page_id(), 'vw_sidebar', true );
			if ( ! empty( $woo_sidebar ) ) {
				$sidebar = $woo_sidebar;
			}
		}
		
		return $sidebar;
	}
}


/**
 * Change the breacrumb separater
 */
add_filter( 'woocommerce_breadcrumb_defaults', 'presso_change_breadcrumb_delimiter' );
if ( ! function_exists( 'presso_change_breadcrumb_delimiter' ) ) {
	function presso_change_breadcrumb_delimiter( $defaults ) {
		$defaults['delimiter'] = ' <span class="vw-breadcrumb-delimiter">&raquo;</span> ';
		$defaults['wrap_before'] = '<div class="vw-woocommerce-breadcrumb vw-header-font" itemprop="breadcrumb">';
		$defaults['wrap_after'] = '</div>';
		$defaults['home'] = esc_html__( 'Shop', 'presso' );

		return $defaults;
	}
}

/**
 * Change home url
 */
add_filter( 'woocommerce_breadcrumb_home_url', 'presso_woo_get_shop_permalink' );
if ( ! function_exists( 'presso_woo_get_shop_permalink' ) ) {
	function presso_woo_get_shop_permalink() {
	    return get_permalink( presso_get_shop_page_id() );
	}
}

/**
 * Change shop columns
 */
add_filter( 'loop_shop_columns', 'presso_woo_product_columns' );
if ( ! function_exists( 'presso_woo_product_columns' ) ) {
	function presso_woo_product_columns() {
		switch ( presso_get_sidebar_position() ) {
			case 'none':
				return 4;

			case 'mini-content-right':
			case 'left-content-mini':
			case 'content-mini-right':
				return 2;
			
			default: /* left & right */
				return 3;
		}
	}
}

/**
 * Apply product per page option
 */
add_filter( 'loop_shop_per_page', 'presso_woo_setup_product_per_page' );
if ( ! function_exists( 'presso_woo_setup_product_per_page' ) ) {
	function presso_woo_setup_product_per_page() {
		return presso_get_theme_option( 'woocommerce_products_per_page' );
	}
}

/**
 * Add body classes
 */
add_filter( 'body_class', 'presso_woo_body_class_options' );
if ( ! function_exists( 'presso_woo_body_class_options' ) ) {
	function presso_woo_body_class_options( $classes ) {
		if ( is_woocommerce() ) {
			if ( is_product() ) {
				$is_enable_sidebar = presso_get_theme_option( 'woocommerce_enable_product_sidebar' );

				if ( $is_enable_sidebar ) {
					$classes[] = 'woocommerce-enable-product-sidebar';
				} else {
					$classes[] = 'woocommerce-disable-product-sidebar';
				}
			} else {
				$is_enable_sidebar = presso_get_theme_option( 'woocommerce_enable_shop_sidebar' );

				if ( $is_enable_sidebar ) {
					$classes[] = 'woocommerce-enable-shop-sidebar';
				} else {
					$classes[] = 'woocommerce-disable-shop-sidebar';
				}
			}
		}

		return $classes;
	}
}

/**
 * Add Archive Title
 */

add_filter( 'presso_filter_archive_title', 'presso_woo_archive_title' );
if ( ! function_exists( 'presso_woo_archive_title' ) ) {
	function presso_woo_archive_title( $title ) {
		if ( is_product_category() || is_product_tag() ) {
			$title = single_term_title( '', false );

		}
		
		return $title;
	}
}

/* -----------------------------------------------------------------------------
 * Template Tag: Cart Button
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_woo_render_cart_button' ) ) {
	function presso_woo_render_cart_button() {
		global $woocommerce;
		?>
		<a class="vw-cart-button" href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>" title="<?php esc_attr_e('View your shopping cart', 'presso'); ?>">
			<i class="vw-icon icon-entypo-basket"></i><span class="vw-cart-button-count vw-header-font"><?php echo esc_html( $woocommerce->cart->cart_contents_count ); ?></span>
		</a>

		<?php
	}
}

if ( ! function_exists( 'presso_woo_render_cart_panel' ) ) {
	function presso_woo_render_cart_panel() {
		if ( is_cart() || is_checkout() ) return;  
		?>

		<div class="vw-cart-button-panel">
			<?php the_widget( 'WC_Widget_Cart' ); ?>
		</div>

		<?php
	}
}

if ( ! function_exists( 'presso_woo_add_cart_fragment' ) ) {
	function presso_woo_add_cart_fragment( $fragments ) {
		global $woocommerce;
		
		ob_start();
		presso_woo_render_cart_button();
		$fragments['.vw-cart-button'] = ob_get_clean();
		
		return $fragments;
	}
}

/**
 * Add cart icon in main menu
 */
if ( ! function_exists( 'presso_woo_add_cart_icon' ) ) {
	function presso_woo_add_cart_icon() {
		?>
		<div class="vw-cart-button-wrapper">
			<?php presso_woo_render_cart_button(); ?>
			<?php presso_woo_render_cart_panel(); ?>
		</div>
		<?php
	}
}

/**
 * Add cart icon in mobile menu
 */

if ( ! function_exists( 'presso_woo_add_cart_icon_to_mobile_menu' ) ) {
	function presso_woo_add_cart_icon_to_mobile_menu() {
		if ( ! presso_has_woocommerce() ) return;
	}
}


add_action( 'woocommerce_after_single_product_summary', 'presso_woo_template_single_title', 5 );
if ( ! function_exists( 'presso_woo_template_single_title' ) ) {
	function presso_woo_template_single_title() {
		echo '<div class="clearfix"></div>';
	}
}

add_action( 'woocommerce_after_shop_loop_item_title', 'presso_woo_add_product_tagline', 4 );
if ( ! function_exists( 'presso_woo_add_product_tagline' ) ) {
	function presso_woo_add_product_tagline() {
		$tagline = get_post_meta( get_the_id(), 'vw_tagline', true );
		if ( ! empty( $tagline ) ) : ?>
		<div class="vw-product-tagline">
			<?php echo esc_html( $tagline ); ?>
		</div>
		<?php endif;
	}
}