<?php
add_theme_support( 'woocommerce' );

// $content_width
if ( ! isset( $content_width ) ) {
	$content_width = 1170;
}

// after setup of the child theme
add_action( 'after_setup_theme', 'uni_theme_theme_setup' );
function uni_theme_theme_setup() {

    // Enable featured image
    add_theme_support( 'post-thumbnails');

    // Add default posts and comments RSS feed links to head
    add_theme_support( 'automatic-feed-links' );

    // translation files for the child theme
    load_child_theme_textdomain( 'asana', get_stylesheet_directory() . '/languages' );
}

// Option tree theme options
//add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
require( trailingslashit( get_template_directory() ) . 'includes/theme-options.php' );
require( trailingslashit( get_template_directory() ) . 'option-tree/ot-loader.php' );
require( trailingslashit( get_template_directory() ) . 'includes/uni-metabox.php' );

// Customizer additions.
require get_template_directory() . '/includes/customizer.php';

// Colour schemes
add_filter( 'ot_radio_images', 'uni_color_schemes_radio_images', 10, 2 );
function uni_color_schemes_radio_images( $array, $field_id ) {
    if ( $field_id == 'uni_color_schemes' ) {
        $array = array(
            array(
                'value'   => 'default',
                'label'   => esc_html__( 'Default scheme', 'asana' ),
                'src'     => get_template_directory_uri() . '/images/schemes/default.jpg'
            ),
            array(
                'value'   => 'purple',
                'label'   => esc_html__( 'Purple colour scheme', 'asana' ),
                'src'     => get_template_directory_uri() . '/images/schemes/purple.jpg'
            ),
            array(
                'value'   => 'blue',
                'label'   => esc_html__( 'Blue colour scheme', 'asana' ),
                'src'     => get_template_directory_uri() . '/images/schemes/blue.jpg'
            ),
            array(
                'value'   => 'red',
                'label'   => esc_html__( 'Red colour scheme', 'asana' ),
                'src'     => get_template_directory_uri() . '/images/schemes/red.jpg'
            ),
            array(
                'value'   => 'orange',
                'label'   => esc_html__( 'Orange colour scheme', 'asana' ),
                'src'     => get_template_directory_uri() . '/images/schemes/orange.jpg'
            ),
        );
    }
    return $array;
}

// Mailchimp API 3.0
include(trailingslashit( get_template_directory() ) . 'includes/class-uni-mailchimp-universal.php');

// Register Custom Menu Function
if (function_exists('register_nav_menus')) {
		register_nav_menus( array(
			'primary' => esc_html__( 'Asana Main Menu', 'asana' ),
            'footer' => esc_html__( 'Asana Footer Menu', 'asana' )
		) );
}

// Menu fallback
function uni_nav_fallback() {
    $sOutput = '<nav class="mainMenu"><ul class="clear">';
    $sOutput .= wp_list_pages( array('title_li' => '', 'echo' => false) );
    $sOutput .= '</ul></nav>';
    echo $sOutput;
}

// Menu footer fallback
function uni_nav_footer_fallback() {
    $sOutput = '';
    echo $sOutput;
}

// wp-title
add_theme_support( 'title-tag' );
if ( ! function_exists( '_wp_render_title_tag' ) ) :
    function theme_slug_render_title() {
?>
<title><?php wp_title( '-', true, 'right' ); ?></title>
<?php
    }
    add_action( 'wp_head', 'theme_slug_render_title' );
endif;

// Add html5 suppost for search form and comments list
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );

// TGM class 2.5.0 - neccessary plugins
include(trailingslashit( get_template_directory() ) . 'includes/class-tgm-plugin-activation.php');

add_action( 'tgmpa_register', 'my_theme_register_required_plugins' );
function my_theme_register_required_plugins() {

    $plugins = array(
        array(
            'name'      => 'Instagram Feed',
            'slug'      => 'instagram-feed',
            'required'  => true,
        ),
        array(
            'name'      => 'OTF Regenerate Thumbnails',
            'slug'      => 'otf-regenerate-thumbnails',
            'required'  => true,
        ),
		array(
			'name'               => 'Envato Market',
			'slug'               => 'envato-market',
			'source'             => get_template_directory() . '/includes/plugins/envato-market.zip',
			'required'           => false,
			'version'            => '1.0.0-beta',
			'force_activation'   => false,
			'force_deactivation' => false,
            'external_url'       => 'http://envato.github.io/wp-envato-market/'
		),
		array(
			'name'               => 'Uni Custom Post Types and Taxonomies',
			'slug'               => 'uni-cpt-and-tax',
			'source'             => get_template_directory() . '/includes/plugins/uni-cpt-and-tax.zip',
			'required'           => true,
			'version'            => '1.2.8',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => '',
		),
		array(
			'name'               => 'Uni Events Calendars Manager',
			'slug'               => 'uni-events-calendar',
			'source'             => get_template_directory() . '/includes/plugins/uni-events-calendar.zip',
			'required'           => true,
			'version'            => '1.0.9',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => '',
		),
		array(
			'name'               => 'Uni User Avatar',
			'slug'               => 'uni-user-avatar',
			'source'             => get_template_directory() . '/includes/plugins/uni-user-avatar.zip',
			'required'           => true,
			'version'            => '1.6.4',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => 'http://codecanyon.net/item/uni-avatar-wp-avatar-manager-plugin/10751977',
		),
		array(
			'name'               => 'Uni Woo Wish & Bridal Lists',
			'slug'               => 'uni-woo-wishlist',
			'source'             => get_template_directory() . '/includes/plugins/uni-woo-wishlist.zip',
			'required'           => false,
			'version'            => '1.1.1',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => '',
		),
		array(
			'name'               => 'Revolution Slider',
			'slug'               => 'revslider',
			'source'             => get_template_directory() . '/includes/plugins/revslider.zip',
			'required'           => true,
			'version'            => '5.1.6',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => 'http://themeforest.net/item/slider-revolution-responsive-wordpress-plugin/2751380',
		),
		array(
			'name'               => 'Uni Sortable Users',
			'slug'               => 'uni-sortable-users',
			'source'             => get_template_directory() . '/includes/plugins/uni-sortable-users.zip',
			'required'           => false,
			'version'            => '1.0.0',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => '',
		),
        array(
            'name'      => 'WooCommerce - excelling eCommerce',
            'slug'      => 'woocommerce',
            'required'  => false,
        ),
        array(
            'name'      => 'Ecwid Shopping Cart',
            'slug'      => 'ecwid-shopping-cart',
            'required'  => false,
        ),
        array(
            'name'      => 'Contact Form 7',
            'slug'      => 'contact-form-7',
            'required'  => false,
        ),
        array(
            'name'      => 'Intuitive Custom Post Order',
            'slug'      => 'intuitive-custom-post-order',
            'required'  => false,
        ),
        array(
            'name'      => 'Shortcodes Ultimate',
            'slug'      => 'shortcodes-ultimate',
            'required'  => false,
        ),
		array(
			'name'               => 'Uni Woo Custom Product Options',
			'slug'               => 'uni-woo-custom-product-options',
			'source'             => '',
			'required'           => false,
			'version'            => '2.0.2',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => 'http://codecanyon.net/item/uni-cpo-price-calculation-formulas-for-woocommerce/9333768',
		),
		array(
			'name'               => 'WooCommerce Subscriptions',
			'slug'               => 'woocommerce-subscriptions',
			'source'             => '',
			'required'           => false,
			'version'            => '2.0.7',
			'force_activation'   => false,
			'force_deactivation' => false,
			'external_url'       => 'https://www.woothemes.com/products/woocommerce-subscriptions/',
		)
    );

    /**
     * Array of configuration settings. Amend each line as needed.
     * If you want the default strings to be available under your own theme domain,
     * leave the strings uncommented.
     * Some of the strings are added into a sprintf, so see the comments at the
     * end of each line for what each argument will be.
     */
    $config = array(
        'default_path' => '',                      // Default absolute path to pre-packaged plugins.
        'menu'         => 'tgmpa-install-plugins', // Menu slug.
        'has_notices'  => true,                    // Show admin notices or not.
        'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
        'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
        'is_automatic' => false,                   // Automatically activate plugins after installation or not.
        'message'      => '<div id="setting-error-tgmpa" class="updated settings-error notice is-dismissible"><p>'.esc_html__('Important: "Uni Woo Custom Product Options" is NOT bundled with the theme and CANNOT be installed and activated if you have not bought and uploaded it additionally!', 'asana').'</p></div>',
        'strings'      => array(
            'page_title'                      => __( 'Install Required Plugins', 'asana' ),
            'menu_title'                      => __( 'Install Plugins', 'asana' ),
            'installing'                      => __( 'Installing Plugin: %s', 'asana' ), // %s = plugin name.
            'oops'                            => __( 'Something went wrong with the plugin API.', 'asana' ),
            'notice_can_install_required'     => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'asana' ), // %1$s = plugin name(s).
            'notice_can_install_recommended'  => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'asana' ), // %1$s = plugin name(s).
            'notice_cannot_install'           => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'asana' ), // %1$s = plugin name(s).
            'notice_can_activate_required'    => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'asana' ), // %1$s = plugin name(s).
            'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'asana' ), // %1$s = plugin name(s).
            'notice_cannot_activate'          => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'asana' ), // %1$s = plugin name(s).
            'notice_ask_to_update'            => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'asana' ), // %1$s = plugin name(s).
            'notice_cannot_update'            => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'asana' ), // %1$s = plugin name(s).
            'install_link'                    => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'asana' ),
            'activate_link'                   => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'asana' ),
            'return'                          => __( 'Return to Required Plugins Installer', 'asana' ),
            'plugin_activated'                => __( 'Plugin activated successfully.', 'asana' ),
            'complete'                        => __( 'All plugins installed and activated successfully. %s', 'asana' ), // %s = dashboard link.
            'nag_type'                        => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
        )
    );

    tgmpa( $plugins, $config );

}

// Load necessary theme scripts and styles
function uni_theme_scripts() {
    // bxSlider
    wp_register_script('jquery-bxslider', get_template_directory_uri() . '/js/jquery.bxslider.min.js', array('jquery'), '4.2.3' );
    wp_enqueue_script('jquery-bxslider');
    // jscrollpane
    wp_register_script('jquery-jscrollpane', get_template_directory_uri() . '/js/jquery.jscrollpane.min.js', array('jquery'), '4.2.3' );
    wp_enqueue_script('jquery-jscrollpane');
    // mousewheel
    wp_register_script('jquery-mousewheel', get_template_directory_uri() . '/js/jquery.mousewheel.js', array('jquery'), '4.2.3' );
    wp_enqueue_script('jquery-mousewheel');
    // dotdotdot
    wp_register_script('jquery-dotdotdot', get_template_directory_uri() . '/js/jquery.dotdotdot.min.js', array('jquery'), '4.2.3' );
    wp_enqueue_script('jquery-dotdotdot');
    // jquery.selectric.min
    wp_register_script('jquery-selectric', get_template_directory_uri() . '/js/jquery.selectric.min.js', array('jquery'), '1.8.7' );
    wp_enqueue_script('jquery-selectric');
    // jquery.infinitescroll
    wp_register_script('jquery-infinitescroll', get_template_directory_uri() . '/js/jquery.infinitescroll.min.js', array('jquery'), '2.1.0' );
    wp_enqueue_script('jquery-infinitescroll');
    // jquery.fancybox.pack
    wp_register_script('jquery-fancybox', get_template_directory_uri() . '/js/jquery.fancybox.pack.js', array('jquery'), '2.1.5' );
    wp_enqueue_script('jquery-fancybox');
    // jquery.blockUI
    wp_register_script('jquery-blockui', get_template_directory_uri() . '/js/jquery.blockUI.js', array('jquery'), '2.70.0' );
    wp_enqueue_script('jquery-blockui');
    // js cookie
    wp_register_script('js-cookie', get_template_directory_uri() . '/js/js.cookie.js', array('jquery'), '2.0.3' );
    wp_enqueue_script('js-cookie');
    // parsley localization
    $sLocale = get_locale();
    $aLocale = explode('_',$sLocale);
    $sLangCode = $aLocale[0];
    if ( file_exists( get_stylesheet_directory() . '/js/parsley/i18n/'.$sLangCode.'.js' ) ) {
        wp_register_script('parsley-localization', get_stylesheet_directory_uri() . '/js/parsley/i18n/'.$sLangCode.'.js', array('jquery'), '2.2.0' );
        wp_enqueue_script('parsley-localization');
    } else if ( file_exists( get_template_directory() . '/js/parsley/i18n/'.$sLangCode.'.js' ) ) {
        wp_register_script('parsley-localization', get_template_directory_uri() . '/js/parsley/i18n/'.$sLangCode.'.js', array('jquery'), '2.2.0' );
        wp_enqueue_script('parsley-localization');
    } else {
        $sLangCode = 'en';
        wp_register_script('parsley-localization', get_template_directory_uri() . '/js/parsley/i18n/'.$sLangCode.'.js', array('jquery'), '2.2.0' );
        wp_enqueue_script('parsley-localization');
    }
    // parsley
    wp_register_script('jquery-parsley', get_template_directory_uri() . '/js/parsley.min.js', array('jquery'), '2.2.0' );
    wp_enqueue_script('jquery-parsley');
    // Asana scripts
    wp_register_script('uni-script', get_template_directory_uri() . '/js/script.js', array('jquery', 'jquery-parsley', 'parsley-localization',
    'jquery-blockui', 'jquery-fancybox', 'jquery-infinitescroll', 'jquery-selectric', 'jquery-dotdotdot', 'jquery-mousewheel', 'jquery-jscrollpane',
    'jquery-bxslider'), '1.6.2' );
    wp_enqueue_script('uni-script');
    // Google Maps API
    if ( is_page_template('templ-contact.php') || is_singular('uni_event') ) {
        wp_register_script('maps.googleapis', 'https://maps.googleapis.com/maps/api/js?sensor=false' );
        wp_enqueue_script('maps.googleapis');
    }

    $sPageHeaderImage = '';
    $iShopAttachId  = ( ot_get_option( 'uni_shop_header_bg' ) ) ? ot_get_option( 'uni_shop_header_bg' ) : '';
    if ( !empty($iShopAttachId) ) {
        $aPageHeaderImage = wp_get_attachment_image_src( $iShopAttachId, 'full' );
        $sPageHeaderImage = $aPageHeaderImage[0];
    } else {
        $sPageHeaderImage = get_template_directory_uri().'/images/placeholders/pageheader-shop.jpg';
    }

    if ( is_home() ) {
        $params = array(
            'site_url'      => esc_url( home_url() ),
		    'ajax_url' 		=> esc_url( admin_url('admin-ajax.php') ),
            'is_home'       => 'yes',
            'locale'        => $sLangCode,
            'white_nav'     => ( ( ot_get_option('uni_nav_white_enable') && ot_get_option('uni_nav_white_enable') == 'on' ) ? true : false ),
            'lazy_load_on_products'  => ( ( ot_get_option('uni_ajax_scroll_enable_products') == 'on' ) ? true : false ),
            'lazy_load_on_posts'  => ( ( ot_get_option('uni_ajax_scroll_enable_posts') == 'on' ) ? true : false ),
            'lazy_load_on_events'  => ( ( ot_get_option('uni_ajax_scroll_enable_events') == 'on' ) ? true : false ),
            'lazy_load_end' => esc_html__( 'You have reached the end', 'asana' ),
            'lazy_loader'   => get_template_directory_uri().'/images/lazy_loader.png',
            'shop_text'     => ( ( ot_get_option( 'uni_shop_header_title' ) ) ? esc_html( ot_get_option( 'uni_shop_header_title' ) ) : esc_html__('ONLINE BOUTIQUE', 'asana') ),
            'shop_text_color' => ( ot_get_option( 'uni_shop_header_title_color' ) ) ? ot_get_option( 'uni_shop_header_title_color' ) : '#ffffff',
            'shop_image'    => esc_url( $sPageHeaderImage )
	    );
    } else {
        $params = array(
            'site_url'      => esc_url( home_url() ),
		    'ajax_url' 		=> esc_url( admin_url('admin-ajax.php') ),
            'is_home'       => 'no',
            'locale'        => $sLangCode,
            'white_nav'     => ( ( ot_get_option('uni_nav_white_enable') && ot_get_option('uni_nav_white_enable') == 'on' ) ? true : false ),
            'lazy_load_on_products'  => ( ( ot_get_option('uni_ajax_scroll_enable_products') == 'on' ) ? true : false ),
            'lazy_load_on_posts'  => ( ( ot_get_option('uni_ajax_scroll_enable_posts') == 'on' ) ? true : false ),
            'lazy_load_on_events'  => ( ( ot_get_option('uni_ajax_scroll_enable_events') == 'on' ) ? true : false ),
            'lazy_load_end' => esc_html__( 'You have reached the end', 'asana' ),
            'lazy_loader'   => get_template_directory_uri().'/images/lazy_loader.png',
            'shop_text'     => ( ( ot_get_option( 'uni_shop_header_title' ) ) ? esc_html( ot_get_option( 'uni_shop_header_title' ) ) : esc_html__('ONLINE BOUTIQUE', 'asana') ),
            'shop_text_color' => ( ot_get_option( 'uni_shop_header_title_color' ) ) ? ot_get_option( 'uni_shop_header_title_color' ) : '#ffffff',
            'shop_image'    => esc_url( $sPageHeaderImage )
	    );
    }

	wp_localize_script( 'uni-script', 'unithemeparams', $params );

}
add_action('wp_enqueue_scripts', 'uni_theme_scripts');

// Enqueue style.css (default WordPress stylesheet)
function uni_theme_style() {

    wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css' );

    $ot_set_google_fonts  = get_theme_mod( 'ot_set_google_fonts', array() );

    if ( !ot_get_option('uni_google_fonts') || empty($ot_set_google_fonts) ) {
        wp_enqueue_style( 'unitheme-fonts', unitheme_fonts_url(), array(), null );
    }

    wp_register_style( 'bxslider-styles', get_template_directory_uri() . '/css/bxslider.css', '4.2.3' );
    wp_enqueue_style( 'bxslider-styles');

    wp_register_style( 'ball-clip-rotate-styles', get_template_directory_uri() . '/css/ball-clip-rotate.css', '0.1.0' );
    wp_enqueue_style( 'ball-clip-rotate-styles');

    wp_register_style( 'fancybox-styles', get_template_directory_uri() . '/css/fancybox.css', '2.1.5' );
    wp_enqueue_style( 'fancybox-styles');

    wp_register_style( 'jscrollpane-styles', get_template_directory_uri() . '/css/jscrollpane.css', '2.1.5' );
    wp_enqueue_style( 'jscrollpane-styles');

    wp_register_style( 'selectric-styles', get_template_directory_uri() . '/css/selectric.css', '2.1.5' );
    wp_enqueue_style( 'selectric-styles' );

    wp_register_style( 'unitheme-styles', get_template_directory_uri() . '/style.css', array('bxslider-styles', 'ball-clip-rotate-styles', 'fancybox-styles',
    'jscrollpane-styles', 'selectric-styles'), '1.6.2', 'all' );
    wp_enqueue_style( 'unitheme-styles' );

    if( class_exists( 'WooCommerce' ) ) {
        wp_register_style( 'asana-woocommerce-styles', get_template_directory_uri() . '/css/woocommerce-store.css', '1.6.2' );
        wp_enqueue_style( 'asana-woocommerce-styles' );
    }

    if( function_exists( 'ecwid_check_version' ) ) {
        wp_register_style( 'asana-ecwid-styles', get_template_directory_uri() . '/css/ecwid-store.css', '1.6.2' );
        wp_enqueue_style( 'asana-ecwid-styles' );
    }

    if ( !ot_get_option( 'uni_color_schemes' ) ) {
        wp_register_style( 'unitheme-asana-scheme', get_template_directory_uri() . '/css/scheme-default.css', array('unitheme-styles'), '1.6.2', 'screen' );
        wp_enqueue_style( 'unitheme-asana-scheme' );
    } else {
        $sColourScheme = ot_get_option( 'uni_color_schemes' );
        wp_register_style( 'unitheme-asana-scheme', get_template_directory_uri() . '/css/scheme-'.$sColourScheme.'.css', array('unitheme-styles'), '1.6.2', 'screen' );
        wp_enqueue_style( 'unitheme-asana-scheme' );
    }

    wp_register_style( 'unitheme-adaptive', get_template_directory_uri() . '/css/adaptive.css', array('unitheme-styles'), '1.6.2', 'screen' );
    wp_enqueue_style( 'unitheme-adaptive' );
}
add_action( 'wp_enqueue_scripts', 'uni_theme_style' );

//
function unitheme_fonts_url() {
    $fonts_url = '';

    $ot_set_google_fonts  = get_theme_mod( 'ot_set_google_fonts', array() );

    if ( empty($ot_set_google_fonts) ) {
        $font_families = array();
        $font_families[] = 'Lato:300,300italic,regular';
        $font_families[] = 'Montserrat:700,regular';

        $query_args = array(
            'family' => urlencode( implode( '|', $font_families ) ),
            'subset' => urlencode( 'latin,latin-ext' ),
        );

        $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    }
    return esc_url_raw( $fonts_url );
}

// custom fonts
add_action('wp_head', 'unitheme_custom_fonts_customization');
function unitheme_custom_fonts_customization(){
    // helps customize fonts
    if ( ot_get_option('uni_google_fonts')  ) {
    $aCustomFonts           = ot_get_option('uni_google_fonts');
    $ot_google_fonts        = get_theme_mod( 'ot_google_fonts', array() );
    $ot_set_google_fonts    = get_theme_mod( 'ot_set_google_fonts', array() );
    $sFontNameOne = $sFontNameTwo = '';
    if ( !empty($ot_set_google_fonts) ) {
        if ( isset($aCustomFonts) && !empty($aCustomFonts[0]) ) $sFontNameOne = $ot_google_fonts[$aCustomFonts[0]["family"]]['family'];
        if ( isset($aCustomFonts) && !empty($aCustomFonts[1]) ) $sFontNameTwo = $ot_google_fonts[$aCustomFonts[1]["family"]]['family'];

        if ( $sFontNameOne != 'Lato' || $sFontNameTwo != 'Montserrat' ) {
    ?>
<style type="text/css">
/* regular text */
body, table, input, textarea, select, li, button, p, blockquote, ol, dl, form, pre, th, td, a,
.uni-bridallist-title, .postItemV2 h3 a, .postItemV2 h3 a:visited,
.postItemV2 p, .ecwid-shopping-cart .singleTitle,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser-auth .ecwid-productBrowser-auth-signInLink:active,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser-auth .ecwid-productBrowser-auth-signInLink,
.uni-bridallist-title-wrapper .uni-bridallist-title.uni-bridallist-editable input,
.mainMenu ul li ul li a,
.footerSubscribe input[type="text"],
.pageHeader h1,
.contactInfo h3, .storyDesc h3,
.contactInfo p, .storyDesc p,
.teamItemNameWrap h3,
.teamItem .overlay p,
.teamItemDesc h3,
.teamItemDesc p,
.ourValues .wrapper p,
.sbi_header_link,
.blog section.uni-container, .blogCategoryList ul li a, .blogCategoryList ul li a:visited,
.singleTitle, .singlePostWrap h6,
.singlePostWrap h1, .singlePostWrap h2,
.singlePostWrap h3, .singlePostWrap h4, .singlePostWrap h5,
.singlePostWrap h6 a, .singlePostWrap h6 a:visited,
.singlePostWrap h5 a, .singlePostWrap h5 a:visited,
.singlePostWrap h4 a, .singlePostWrap h4 a:visited,
.singlePostWrap h3 a, .singlePostWrap h3 a:visited,
.singlePostWrap h2 a, .singlePostWrap h2 a:visited,
.singlePostWrap table th,
.singlePostWrap table th a, .singlePostWrap table th a:visited,
.singlePostWrap table td,
.singlePostWrap table td a, .singlePostWrap table td a:visited,
.singlePostWrap p,
.singlePostWrap,
.singlePostWrap dt a, .singlePostWrap dt a:visited,
.singlePostWrap dd a, .singlePostWrap dd a:visited,
.singlePostWrap p a, .singlePostWrap p a:visited,
.singlePostWrap dt,
.singlePostWrap dd,
.singlePostWrap > ul li, .singlePostWrap > ol li,
.singlePostWrap > ol li:before,
.singlePostWrap p a, .singlePostWrap p a:visited, .singlePostWrap > ul li a, .singlePostWrap > ul li a:visited,
.singlePostWrap > ol li a, .singlePostWrap > ol li a:visited,
.singlePostWrap address,
.singlePostWrap blockquote p,
.singlePostWrap blockquote p a, .singlePostWrap blockquote p a:visited,
.singlePostTags,
.singleLinkPages a, .singleLinkPages a:visited, .singlePostTags a, .singlePostTags a:visited,
.singlePostWrap .su-list ul li,
.singlePostWrap .su-tabs-nav span,
.singlePostWrap .su-tabs-pane,
.singlePostWrap .su-label,
.logged-in-as,
.bypostauthor .comment-wrapper .uni-post-author,
.comment-metadata time,
.comment-content p, .comment-awaiting-moderation,
.comment-content p a, .comment-content p a:visited,
#commentform input[type="text"],
#commentform textarea,
.contactForm h3,
.contactFormDesc,
.contactForm .form-row input[type="text"], .contactForm .form-row input[type="email"], .contactForm .form-row textarea,
.contactForm .wpcf7-form p,
.wpcf7-form .wpcf7-quiz,
.wpcf7-form .wpcf7-text,
.wpcf7-form .wpcf7-range,
.wpcf7-form .wpcf7-date,
.wpcf7-form textarea,
.wpcf7-form select,
.miniCart span,
.miniCartItem h3 a, .miniCartItem h3 a:visited,
.miniCartItem .price,
.miniCartItem .quantity span,
.miniCartItem .quantity input[type="text"],
.miniCartSubTotal,
.miniCartItem dt,
.miniCartItem dd,
.miniCartEmpty p,
.pageTitle,
.sortingList span, .categoryList span,
.sortingList ul li a, .sortingList ul li a:visited,
.categoryList ul li a, .categoryList ul li a:visited,
.eventItemDesc h3 a, .eventItemDesc h3 a:visited,
.eventItemDesc p,
.subscribeBox h3,
.subscribeBox p,
.backToBtn, .backToBtn:visited,
.nextEventBox h3,
.eventDetailItem p,
.eventRegistrationWrap h3,
.eventRegistrationForm .form-row input[type="text"],
.eventRegistrationForm .form-row input[type="email"],
.eventRegistrationForm .form-row textarea,
.cartPage table th,
.cartPage table td,
.cartProduct h4 a, .cartProduct h4 a:visited,
.cartPage .quantity input[type="number"],
.cartPage .woocommerce td.product-name dl.variation dt,
.cartPage .woocommerce td.product-name dl.variation dd p,
.coupon label,
.coupon input[type="text"],
.woocommerce-page .cart-collaterals .cart_totals h2,
.woocommerce-cart .cart-collaterals .cart_totals tr th,
.woocommerce-cart .cart-collaterals .cart_totals tr td,
.shipping-calculator-form .selectric p,
.shipping-calculator-form p input[type="text"],
.page.woocommerce-cart .cart-empty, .uni-wishlist-empty,
table.uni-wishlist-table td,
.uni-wishlist-item-title a, .uni-wishlist-item-title a:visited,
.uni-wishlist-item-availability span,
.uni-wishlist-item-title dl.variation dt,
.uni-wishlist-item-title dl.variation dd,
.checkoutPage h3,
.checkoutPage p .selectric p,
.checkoutPage .mcell p label,
.checkoutPage .fcell p label,
.checkoutPage .fcell p input[type="tel"],
.checkoutPage .fcell p input[type="email"],
.checkoutPage .fcell p input[type="password"],
.checkoutPage .mcell p textarea,
.checkoutPage .mcell p input[type="text"],
.checkoutPage .fcell p input[type="text"],
.checkoutPage .woocommerce .scell table.shop_table tfoot th,
.checkoutPage .woocommerce .scell table.shop_table tfoot td,
.cartItem h4 a, .cartItem h4 a:visited,
.cartItem p,
.payment_methods li label,
body .woocommerce form.checkout_coupon p.form-row input.input-text,
body .woocommerce form.login p.form-row input.input-text,
body.page.woocommerce-account .singlePostWrap address,
.page.woocommerce-account form label,
.page.woocommerce-account form p.form-row input.input-text,
.page.woocommerce-account form p.form-row textarea,
.page.woocommerce-account form p.form-row .selectric p,
.productDesc h1,
.productDesc p.price,
.productDesc p,
.productDesc .product_meta > span,
.productDesc .product_meta > span span,
.productDesc .product_meta > span a, .productDesc .product_meta > span a:visited,
.uni_cpo_fields_label,
.uni_cpo_fields_container .selectric p,
.productDesc table.variations .selectric p,
.uni_cpo_fields_container .selectric .button,
.productDesc table.variations .selectric .button,
.variations select,
form.woocommerce-ordering select,
.single-product .woocommerce-tabs #tab-reviews p,
.single-product .woocommerce-tabs #tab-description p,
.woocommerce #tab-reviews #reviews #comments ol.commentlist li .comment-text p.meta strong,
.woocommerce-review-link, .woocommerce-review-link:hover,
.woocommerce #tab-additional_information table.shop_attributes th,
.woocommerce #tab-additional_information table.shop_attributes td,
.uni-wishlist-link, .uni-wishlist-link:visited,
.classesCallendar .fc-toolbar h2,
.classesCallendar .fc-day-header,
.classesCallendar .fc-event,
.classesCallendar td.fc-time,
.classesDescPopup h3,
.classesDescWrap p,
.classesInstructorWrap h4,
.page404Wrap p,
.thankYouBox h3,
.thankYouWrap .order_details li,
.thankYouWrap h2,
.thankYouWrap .order_details thead th,
.thankYouWrap .order_details tbody td,
.thankYouWrap .order_details tbody td strong, .thankYouWrap .order_details tbody td a, .thankYouWrap .order_details tbody td a:visited,
.thankYouWrap .order_details tfoot th, .thankYouWrap .order_details tfoot td,
.thankYouWrap .order_details tbody td .variation dt, .thankYouWrap .order_details tbody td .variation dd,
.customer_details dt,
.customer_details dd,
.thankYouWrap .col2-set.addresses h3,
.thankYouWrap .col2-set.addresses address,
.membershipCardItem h3, .ecwid-SearchPanel-field,
.membershipCard, .checkoutPage .woocommerce .scell table.shop_table tbody td.product-name > p, .checkoutPage .scell label[for="payment_method_paypal"] a,
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-categoryPath, html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-categoryPath,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser-categoryPath span.gwt-InlineLabel,
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-categoryPath a,
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-categoryPath a:active,
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-categoryPath a:visited, 
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-productNameLink a, 
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-productNameLink a:active, 
html#ecwid_html body#ecwid_body.chameleon div.ecwid-productBrowser-productNameLink a:visited,
html#ecwid_html body#ecwid_body .ecwid a.ecwid-poweredBy,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser-details-rightPanel div.ecwid-productBrowser-sku,
html#ecwid_html body#ecwid_body .ecwid span.ecwid-productBrowser-price-value,
html#ecwid_html body#ecwid_body .ecwid span.gwt-InlineLabel,
html#ecwid_html body#ecwid_body td.ecwid-productBrowser-cart-itemsTable-headerCell,
html#ecwid_html body#ecwid_body .ecwid-responsive div.ecwid-productBrowser-cart .ecwid-productBrowser-cart-itemsTable-cell-descr div.ecwid-productBrowser-sku,
html#ecwid_html body#ecwid_body div.ecwid-results-topPanel-sortByPanel select.gwt-ListBox,
html#ecwid_html body#ecwid_body div.ecwid-results-topPanel div.ecwid-results-topPanel-itemsCountLabel,
html#ecwid_html body#ecwid_body div.ecwid-results-topPanel div .ecwid-results-topPanel-viewAsPanel,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser-productsList-details div.ecwid-productBrowser-sku,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser-productsList-details div.ecwid-productBrowser-price-list, .rssSummary, .widget_rss ul li cite,
.relatedPostsItemV2, .relatedPostsItemV2 h4 a, .relatedPostsItemV2 h4 a:visited,
.sidebar-widget li, .sidebar-widget li a, .sidebar-widget li a:visited, #wp-calendar caption, #wp-calendar tbody td, #wp-calendar tfoot td a, #wp-calendar tfoot td a:visited,
.membershipCardItem p {font-family: '<?php echo esc_attr( $sFontNameOne ); ?>'!important;}

.woocommerce-breadcrumb,
.woocommerce-breadcrumb a, .woocommerce-breadcrumb a:visited,
.checkoutPage .woocommerce .scell table.shop_table tbody td.product-name,
.checkoutPage .woocommerce .scell table.shop_table tbody td.product-total,
.checkoutPage .woocommerce .scell table.shop_table tbody td .variation dd,
.checkoutPage .woocommerce .scell table.shop_table tbody td .variation dt,
#review_form #commentform p label,
#uni_popup, .contactForm .wpcf7-validation-errors,
.wpcf7-response-output.wpcf7-mail-sent-ok,
.woocommerce .woocommerce-info, .woocommerce .woocommerce-error, .woocommerce .woocommerce-message,
.woocommerce .woocommerce-message .button.wc-forward,
.woocommerce .woocommerce-info a, .woocommerce .woocommerce-info a:visited,
.woocommerce .woocommerce-message a, .woocommerce .woocommerce-message a:visited,
.woocommerce .woocommerce-error li {font-family: '<?php echo esc_attr( $sFontNameOne ); ?>'!important;}

/* headings */
.uni-bridallist-title-wrapper .uni-bridallist-title.uni-bridallist-editable button[type="submit"],
.uni-bridallist-title-wrapper .uni-bridallist-title.uni-bridallist-editable button[type="cancel"],
html#ecwid_html body#ecwid_body.chameleon .ecwid-btn--secondary, #wp-calendar thead th, a.rsswidget,
html#ecwid_html body#ecwid_body div.ecwid-productBrowser .ecwid-btn--primary, .sidebar-widget .search-form .search-field,
.postPrev, .postNext, .relatedPostsV2 h3, .categoryLink, .categoryLink:visited,
html#ecwid_html body#ecwid_body.ecwid-shopping-cart .ecwid-SearchPanel .ecwid-SearchPanel-button,
.mainMenu > ul > li a,
.mainMenu > ul > li a:visited,
.learnMore, .learnMore:visited,
.mainItemDesc .viewMore, .mainItemDesc .viewMore:visited,
.gridItemDesc .viewMore,
.postItemTime,
.classesCategory,
.viewClasses, .viewClasses:visited,
.loadMoreItems, .loadMoreItems:visited,
.showAllItems, .showAllItems:visited,
.pagination ul li a, .pagination ul li a:visited,
.pagination ul li.current, .woocommerce-pagination ul li span.current,
.footerMenu li a, .footerMenu li a:visited,
.singleLinkPages,
.singlePostTags span,
.singlePostWrap .su-quote-cite a,
.singlePostWrap .su-divider a,
.singlePostWrap .su-heading-style-default .su-heading-inner,
.singlePostWrap .su-service-title,
.singlePostWrap .su-spoiler-title,
.singlePostWrap .su-carousel .su-carousel-slide-title,
.singlePostWrap .su-slider-slide-title,
.commentsBox h2, .commentsBox h3,
.commentsBox h3 a, .commentsBox h3 a:visited,
.comment-edit-link, .comment-edit-link:visited, .comment-reply-link, .comment-reply-link:visited,
.logged-in-as a, .logged-in-as a:visited,
.comment-wrapper cite,
.comment-wrapper cite a,
#commentform #submit,
.submitContactFormBtn,
.wpcf7-form input[type="submit"],
.productFilter li a, .productFilter li a:visited,
.miniCartPopupHead h3,
.btnViewCart, .btnViewCart:visited,
.btnCheckout, .btnCheckout:visited,
.eventItemTime,
.eventLearnMore, .eventLearnMore:visited,
.showMoreEvents, .showMoreEvents:visited,
.subscribeBox form input[type="text"],
.subscribeSubmit,
.nextEventBtn, .nextEventBtn:visited,
.singleEventJoinBtnWrap a, .singleEventJoinBtnWrap a:visited,
.submitEventRegistrationBtn,
.woocommerce-cart .wc-proceed-to-checkout .checkout-button,
.updateCartBtn,
.page.woocommerce-cart .return-to-shop a.button,
.page-template-templ-wishlist .return-to-shop a.button,
.button.product_type_, .button.add_to_cart_button,
#place_order,
body .woocommerce form.checkout_coupon p.form-row input.button,
body .woocommerce form.login p.form-row input.button,
body.page.woocommerce-account .shop_table.shop_table_responsive.my_account_orders .button.view,
.page.woocommerce-account form p input.button,
.productDesc form.cart .single_add_to_cart_button,
.page404Wrap a.homePage, .page404Wrap a.homePage:visited,
.postItemV2ReadMoreWrap a, .postItemV2ReadMoreWrap a:visited,
.sidebar-widget .widgettitle, .sidebar-widget select,
.membership-card-order, .membership-card-order:visited {font-family: '<?php echo esc_attr( $sFontNameTwo ); ?>'!important;}

.woocommerce-pagination ul li a, .woocommerce-pagination ul li a:visited,
.pagination ul li.threeDot,
.coupon input[name="apply_coupon"],
.actions input[name="update_cart"],
.shipping-calculator-form p button,
.single-product .woocommerce-tabs .tabs li a,
.single-product .woocommerce-tabs .tabs li a:visited,
#tab-additional_information h2,
#review_form_wrapper .comment-reply-title,
.single-product .woocommerce-tabs #tab-reviews h2,
.single-product .woocommerce-tabs #tab-description h2,
.woocommerce #tab-reviews #reviews #comments ol.commentlist li .comment-text p.meta time,
#review_form #commentform #submit {font-family: '<?php echo esc_attr( $sFontNameTwo ); ?>'!important;}
</style>
    <?php
        }
    }
    }
}

// customization of sticky header
add_action('wp_head', 'unitheme_custom_styles_sticky_header');
function unitheme_custom_styles_sticky_header(){
    if ( ot_get_option('uni_nav_white_enable') && ot_get_option('uni_nav_white_enable') == 'on'
        && ( ot_get_option('uni_sticky_nav_white_enable') || ot_get_option('uni_sticky_nav_link_color') || ot_get_option('uni_sticky_nav_link_hover_color') ) ) { ?>
    <style type="text/css">
        html body.fixedMainMenu #header .headerWrap {background: <?php echo ( ot_get_option('uni_sticky_nav_bg_color') ) ? ot_get_option('uni_sticky_nav_bg_color') : '#ffffff' ?>!important;}
        html body.fixedMainMenu #header .mainMenu ul li a {color: <?php echo ( ot_get_option('uni_sticky_nav_link_color') ) ? ot_get_option('uni_sticky_nav_link_color') : '#7f7f7f' ?>;}
        html body.fixedMainMenu #header .mainMenu ul li.current-menu-item a,
        html body.fixedMainMenu #header .mainMenu ul li a:hover {color: <?php echo ( ot_get_option('uni_sticky_nav_link_hover_color') ) ? ot_get_option('uni_sticky_nav_link_hover_color') : '#333333' ?>;}
    </style>
    <?php }
}

// customization of floating header
add_action('wp_head', 'unitheme_custom_styles_floating_header');
function unitheme_custom_styles_floating_header(){
    // in transparent state
    if ( ot_get_option('uni_nav_white_enable') && ot_get_option('uni_nav_white_enable') == 'off'
        && ot_get_option('uni_nav_floating_custom_styles_enable') && ot_get_option('uni_nav_floating_custom_styles_enable') == 'on'
        && ( ot_get_option('uni_floating_nav_bg_color_transparent') || ot_get_option('uni_floating_nav_border_transparent')
            || ot_get_option('uni_floating_nav_link_color_transparent') || ot_get_option('uni_floating_nav_link_hover_color_transparent') ) ) { ?>
    <style type="text/css">
        #header .headerWrap {background: <?php echo ( ot_get_option('uni_floating_nav_bg_color_transparent') ) ? ot_get_option('uni_floating_nav_bg_color_transparent') : 'rgba(255,255,255,0.01)' ?>;border-bottom: 1px solid <?php echo ( ot_get_option('uni_floating_nav_border_transparent') ) ? ot_get_option('uni_floating_nav_border_transparent') : 'rgba(255,255,255,0.2)' ?>;}
        .mainMenu > ul > li a, .mainMenu > ul > li a:visited {color: <?php echo ( ot_get_option('uni_floating_nav_link_color_transparent') ) ? ot_get_option('uni_floating_nav_link_color_transparent') : '#ffffff' ?>;}
        .mainMenu > ul > li a:hover {color: <?php echo ( ot_get_option('uni_floating_nav_link_hover_color_transparent') ) ? ot_get_option('uni_floating_nav_link_hover_color_transparent') : '#ffffff' ?>;}
    </style>
    <?php }

    // in non-transparent state
    if ( ot_get_option('uni_nav_white_enable') && ot_get_option('uni_nav_white_enable') == 'off'
        && ot_get_option('uni_nav_floating_custom_styles_enable') && ot_get_option('uni_nav_floating_custom_styles_enable') == 'on'
        && ( ot_get_option('uni_floating_nav_bg_color') || ot_get_option('uni_floating_nav_link_color')
            || ot_get_option('uni_floating_nav_link_hover_color') ) ) { ?>
    <style type="text/css">
        #header .headerWrap.is-sticky,
        html body.home-slider-disabled #header .headerWrap {background: <?php echo ( ot_get_option('uni_floating_nav_bg_color') ) ? ot_get_option('uni_floating_nav_bg_color') : '#ffffff' ?>;}
        .page-template-templ-blog #header .headerWrap, .page-template-templ-blog-with-sidebar #header .headerWrap, .blog #header .headerWrap,
        .search #header .headerWrap, .archive.category #header .headerWrap, .archive.date #header .headerWrap, .archive.tag #header .headerWrap, .archive.author #header .headerWrap,
        .single-post #header .headerWrap, .single-post-with-sidebar #header .headerWrap,
        .page.page-template-default:not(.ecwid-shopping-cart) #header .headerWrap,
        .page.woocommerce-account #header .headerWrap, .error404 #header .headerWrap {background: <?php echo ( ot_get_option('uni_floating_nav_bg_color') ) ? ot_get_option('uni_floating_nav_bg_color') : '#ffffff' ?>;}

        #header .headerWrap.is-sticky .mainMenu > ul > li a, #header .headerWrap.is-sticky .mainMenu > ul > li a:visited,
        html body.home-slider-disabled #header .headerWrap .mainMenu > ul > li a, html body.home-slider-disabled #header .headerWrap .mainMenu > ul > li a:visited,
        .page-template-templ-blog .mainMenu > ul > li a, .page-template-templ-blog .mainMenu > ul > li a:visited,
        .page-template-templ-blog-with-sidebar .mainMenu > ul > li a, .page-template-templ-blog-with-sidebar .mainMenu > ul > li a:visited,
        .blog .mainMenu > ul > li a, .blog .mainMenu > ul > li a:visited,
        .search .mainMenu > ul > li a, .search .mainMenu > ul > li a:visited,
        .archive.category .mainMenu > ul > li a, .archive.category .mainMenu > ul > li a:visited,
        .archive.date .mainMenu > ul > li a, .archive.date .mainMenu > ul > li a:visited,
        .archive.tag .mainMenu > ul > li a, .archive.tag .mainMenu > ul > li a:visited,
        .archive.author .mainMenu > ul > li a, .archive.author .mainMenu > ul > li a:visited,
        .single-post .mainMenu > ul > li a, .single-post .mainMenu > ul > li a:visited,
        .single-post-with-sidebar .mainMenu > ul > li a, .single-post-with-sidebar .mainMenu > ul > li a:visited,
        .page.page-template-default:not(.ecwid-shopping-cart) .mainMenu > ul > li a, .page.page-template-default:not(.ecwid-shopping-cart) .mainMenu > ul > li a:visited,
        .page.woocommerce-account .mainMenu > ul > li a, .page.woocommerce-account .mainMenu > ul > li a:visited,
        .error404 .mainMenu > ul > li a, .error404 .mainMenu > ul > li a:visited {color: <?php echo ( ot_get_option('uni_floating_nav_link_color') ) ? ot_get_option('uni_floating_nav_link_color') : '#ffffff' ?>;}

        #header .headerWrap.is-sticky .mainMenu > ul > li.current-menu-item a, #header .headerWrap.is-sticky .mainMenu > ul > li a:hover,
        html body.home-slider-disabled #header .headerWrap .mainMenu > ul > li.current-menu-item a, html body.home-slider-disabled #header .headerWrap .mainMenu > ul > li a:hover,
        .page-template-templ-blog .mainMenu > ul > li.current-menu-item a, .page-template-templ-blog .mainMenu > ul > li a:hover,
        .page-template-templ-blog-with-sidebar .mainMenu > ul > li.current-menu-item a, .page-template-templ-blog-with-sidebar .mainMenu > ul > li a:hover,
        .blog .mainMenu > ul > li.current-menu-item a, .blog .mainMenu > ul > li a:hover,
        .search .mainMenu > ul > li.current-menu-item a, .search .mainMenu > ul > li a:hover,
        .archive.category .mainMenu > ul > li.current-menu-item a, .archive.category .mainMenu > ul > li a:hover,
        .archive.date .mainMenu > ul > li.current-menu-item a, .archive.date .mainMenu > ul > li a:hover,
        .archive.tag .mainMenu > ul > li.current-menu-item a, .archive.tag .mainMenu > ul > li a:hover,
        .archive.author .mainMenu > ul > li.current-menu-item a, .archive.author .mainMenu > ul > li a:hover,
        .single-post .mainMenu > ul > li.current-menu-item a, .single-post .mainMenu > ul > li a:hover,
        .single-post-with-sidebar .mainMenu > ul > li.current-menu-item a, .single-post-with-sidebar .mainMenu > ul > li a:hover,
        .page.page-template-default:not(.ecwid-shopping-cart) .mainMenu > ul > li.current-menu-item a, .page.page-template-default:not(.ecwid-shopping-cart) .mainMenu > ul > li a:hover,
        .page.woocommerce-account .mainMenu > ul > li.current-menu-item a, .page.woocommerce-account .mainMenu > ul > li a:hover,
        .error404 .mainMenu > ul > li.current-menu-item a, .error404 .mainMenu > ul > li a:hover {color: <?php echo ( ot_get_option('uni_floating_nav_link_hover_color') ) ? ot_get_option('uni_floating_nav_link_hover_color') : '#ffffff' ?>;}
    </style>
    <?php }
}

//
add_action('admin_enqueue_scripts', 'uni_admin_script', 10, 1);
function uni_admin_script( $hook ) {
    if( $hook == 'user-edit.php' || $hook == 'profile.php' ) {
        wp_enqueue_script('bootstrap', '//netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js');
        wp_enqueue_script('juery-fontawesome-iconpicker', get_template_directory_uri() . '/js/fontawesome-iconpicker.min.js', array('jquery'), '1.6.2');
    }

    wp_enqueue_script( 'unitheme-admin-script', get_template_directory_uri() . '/js/uni-admin.js', array('jquery'), '1.6.2' );

    if( $hook == 'user-edit.php' || $hook == 'profile.php' ) {
        wp_register_style( 'bootstrap-iso-style', get_template_directory_uri() . '/css/bootstrap-iso.css', array(), '1.6.2', 'screen' );
        wp_enqueue_style( 'bootstrap-iso-style' );
        wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css' );
        wp_register_style( 'fontawesome-iconpicker-style', get_template_directory_uri() . '/css/fontawesome-iconpicker.min.css', array(), '1.6.2', 'screen' );
        wp_enqueue_style( 'fontawesome-iconpicker-style' );
    }
}

// Add new image sizes
add_image_size( 'unithumb-contactgallery', 570, 405, true );
add_image_size( 'unithumb-relativepost', 260, 174, true );
add_image_size( 'unithumb-eventpost', 502, 342, true );
add_image_size( 'unithumb-blog', 408, 272, true );
add_image_size( 'unithumb-blogv2', 840, 560, true );
add_image_size( 'unithumb-homepostbig', 684, 684, true );
add_image_size( 'unithumb-homepostsmall', 342, 342, true );
add_image_size( 'unithumb-homeposthalf', 684, 342, true );
add_image_size( 'unithumb-minicartphoto', 52, 52, true );
add_image_size( 'unithumb-cartimage', 128, 128, true );
add_image_size( 'unithumb-attachment', 1170, 0, false );

// Register sidebar
add_action( 'widgets_init', 'unitheme_sidebars_init' );
function unitheme_sidebars_init() {
    register_sidebar( array(
        'name' => esc_html__( 'Sidebar', 'asana' ),
        'id' => 'sidebar-main',
        'description' => '',
        'before_widget' => '<div id="%1$s" class="sidebar-widget %2$s">',
	'after_widget'  => '</div>',
	'before_title'  => '<h3 class="widgettitle">',
	'after_title'   => '</h3>',
    ) );
}

// add the new role
add_action('after_switch_theme', 'uni_theme_activation_func', 10);
function uni_theme_activation_func() {
    add_role( 'instructor', esc_html__('Instructor', 'asana'), array('read' => true) );
	$instructor = get_role('instructor');
	$instructor->add_cap('read');
    $instructor->add_cap('edit_published_posts');
    $instructor->add_cap('upload_files');
    $instructor->add_cap('publish_posts');
    $instructor->add_cap('delete_published_posts');
    $instructor->add_cap('edit_posts');
    $instructor->add_cap('delete_posts');
    update_option('posts_per_page', 9);
    flush_rewrite_rules();
}

// remove the new role on theme deactivation
add_action('switch_theme', 'uni_theme_deactivation_func');
function uni_theme_deactivation_func() {
    remove_role( 'instructor' );
}

// Additional fields for user's profile
add_action( 'show_user_profile', 'uni_user_additional_fields_section' );
add_action( 'edit_user_profile', 'uni_user_additional_fields_section' );
function uni_user_additional_fields_section( $oUser ) {
    $aUserAdditionalData = ( get_user_meta( $oUser->ID, '_uni_user_data', true ) ) ? get_user_meta( $oUser->ID, '_uni_user_data', true ) : array();
    ?>

	<h3><?php esc_html_e( 'Asana: additional fields', 'asana' ); ?></h3>
	<table class="form-table">
		<tr>
			<th><label><?php esc_html_e( 'Profession', 'asana' ); ?></label></th>
			<td>
                <p><input type="text" class="regular-text" name="uni_user_data[profession]" value="<?php if ( !empty($aUserAdditionalData['profession']) ) echo esc_attr( $aUserAdditionalData['profession'] ) ?>" /></p>
            </td>
		</tr>
    </table>

	<h3><?php esc_html_e( 'Asana: social links', 'asana' ); ?></h3>
    <p><?php esc_html_e( 'You can display up to 5 social links! Please choose desired icons. An example of icon class to be added to the fields are "fa-apple" or "fa-facebook" etc. You can choose any icon from Fontawesome icons set (http://fontawesome.io/icons/).', 'asana' ); ?></p>
	<table class="form-table">
		<tr>
			<th><label><?php esc_html_e( 'Link #1', 'asana' ); ?></label></th>
			<td>
                <p> <label><?php esc_html_e( 'Icon class #1', 'asana' ); ?></label>
                <div class="bootstrap-iso">
                    <input type="text" class="regular-text uni-icp-auto" name="uni_user_data[social_link_icon_one]" value="<?php if ( !empty($aUserAdditionalData['social_link_icon_one']) ) echo esc_attr( $aUserAdditionalData['social_link_icon_one'] ) ?>" />
                </div>
                </p>
                <p> <label><?php esc_html_e( 'Link URI #1', 'asana' ); ?></label>
                    <input type="text" class="regular-text" name="uni_user_data[social_link_uri_one]" value="<?php if ( !empty($aUserAdditionalData['social_link_uri_one']) ) echo esc_url( $aUserAdditionalData['social_link_uri_one'] ) ?>" /></p>
            </td>
		</tr>
		<tr>
			<th><label><?php esc_html_e( 'Link #2', 'asana' ); ?></label></th>
			<td>
                <p> <label><?php esc_html_e( 'Icon class #2', 'asana' ); ?></label>
                <div class="bootstrap-iso">
                    <input type="text" class="regular-text uni-icp-auto" name="uni_user_data[social_link_icon_two]" value="<?php if ( !empty($aUserAdditionalData['social_link_icon_two']) ) echo esc_attr( $aUserAdditionalData['social_link_icon_two'] ) ?>" />
                </div>
                </p>
                <p> <label><?php esc_html_e( 'Link URI #2', 'asana' ); ?></label>
                    <input type="text" class="regular-text uni-icp-auto" name="uni_user_data[social_link_uri_two]" value="<?php if ( !empty($aUserAdditionalData['social_link_uri_two']) ) echo esc_url( $aUserAdditionalData['social_link_uri_two'] ) ?>" /></p>
            </td>
		</tr>
		<tr>
			<th><label><?php esc_html_e( 'Link #3', 'asana' ); ?></label></th>
			<td>
                <p> <label><?php esc_html_e( 'Icon class #3', 'asana' ); ?></label>
                <div class="bootstrap-iso">
                    <input type="text" class="regular-text uni-icp-auto" name="uni_user_data[social_link_icon_three]" value="<?php if ( !empty($aUserAdditionalData['social_link_icon_three']) ) echo esc_attr( $aUserAdditionalData['social_link_icon_three'] ) ?>" />
                </div>
                </p>
                <p> <label><?php esc_html_e( 'Link URI #3', 'asana' ); ?></label>
                    <input type="text" class="regular-text" name="uni_user_data[social_link_uri_three]" value="<?php if ( !empty($aUserAdditionalData['social_link_uri_three']) ) echo esc_url( $aUserAdditionalData['social_link_uri_three'] ) ?>" /></p>
            </td>
		</tr>
		<tr>
			<th><label><?php esc_html_e( 'Link #4', 'asana' ); ?></label></th>
			<td>
                <p> <label><?php esc_html_e( 'Icon class #4', 'asana' ); ?></label>
                <div class="bootstrap-iso">
                    <input type="text" class="regular-text uni-icp-auto" name="uni_user_data[social_link_icon_four]" value="<?php if ( !empty($aUserAdditionalData['social_link_icon_four']) ) echo esc_attr( $aUserAdditionalData['social_link_icon_four'] ) ?>" />
                </div>
                </p>
                <p> <label><?php esc_html_e( 'Link URI #4', 'asana' ); ?></label>
                    <input type="text" class="regular-text" name="uni_user_data[social_link_uri_four]" value="<?php if ( !empty($aUserAdditionalData['social_link_uri_four']) ) echo esc_url( $aUserAdditionalData['social_link_uri_four'] ) ?>" /></p>
            </td>
		</tr>
		<tr>
			<th><label><?php esc_html_e( 'Link #5', 'asana' ); ?></label></th>
			<td>
                <p> <label><?php esc_html_e( 'Icon class #5', 'asana' ); ?></label>
                <div class="bootstrap-iso">
                    <input type="text" class="regular-text uni-icp-auto" name="uni_user_data[social_link_icon_five]" value="<?php if ( !empty($aUserAdditionalData['social_link_icon_five']) ) echo esc_attr( $aUserAdditionalData['social_link_icon_five'] ) ?>" />
                </div>
                </p>
                <p> <label><?php esc_html_e( 'Link URI #5', 'asana' ); ?></label>
                    <input type="text" class="regular-text" name="uni_user_data[social_link_uri_five]" value="<?php if ( !empty($aUserAdditionalData['social_link_uri_five']) ) echo esc_url( $aUserAdditionalData['social_link_uri_five'] ) ?>" /></p>
            </td>
		</tr>
    </table>

    <?php
}

// save
add_action( 'personal_options_update', 'uni_user_additional_fields_save' );
add_action( 'edit_user_profile_update', 'uni_user_additional_fields_save' );
function uni_user_additional_fields_save( $iUserId ) {

	if ( !current_user_can( 'edit_user', $iUserId ) )
		return false;

    $aUniUserData = isset( $_POST['uni_user_data'] ) ? (array) $_POST['uni_user_data'] : array();
    if ( !empty($aUniUserData) ) {
        $aUniUserData = array_map( 'sanitize_text_field', $aUniUserData );
        update_user_meta($iUserId, '_uni_user_data', $aUniUserData);
    } else {
        delete_user_meta($iUserId, '_uni_user_data');
    }

}

//
function ot_type_uni_users_type_checkbox( $args = array() ) {

    /* turns arguments array into variables */
    extract( $args );

    /* verify a description */
    $has_desc = $field_desc ? true : false;

    /* format setting outer wrapper */
    echo '<div class="format-setting type-custom-post-type-checkbox type-checkbox ' . ( $has_desc ? 'has-desc' : 'no-desc' ) . '">';

      /* description */
      echo $has_desc ? '<div class="description">' . htmlspecialchars_decode( $field_desc ) . '</div>' : '';

      /* format setting inner wrapper */
      echo '<div class="format-setting-inner">';

        /* setup the role */
        $sRoleSlug = isset( $field_post_type ) ? $field_post_type : 'subscriber';

        /* query userss array */
        $oUserQuery = new WP_User_Query( array('role' => $sRoleSlug) );

        /* has posts */
        if ( ! empty( $oUserQuery->results ) ) {
          foreach ( $oUserQuery->results as $oUser ) {
            echo '<p>';
            echo '<input type="checkbox" name="' . esc_attr( $field_name ) . '[' . esc_attr( $oUser->ID ) . ']" id="' . esc_attr( $field_id ) . '-' . esc_attr( $oUser->ID ) . '" value="' . esc_attr( $oUser->ID ) . '" ' . ( isset( $field_value[$oUser->ID] ) ? checked( $field_value[$oUser->ID], $oUser->ID, false ) : '' ) . ' class="option-tree-ui-checkbox ' . esc_attr( $field_class ) . '" />';
            echo '<label for="' . esc_attr( $field_id ) . '-' . esc_attr( $oUser->ID ) . '">' . esc_attr($oUser->display_name) . '</label>';
            echo '</p>';
          }
        } else {
          echo '<p>' . sprintf( esc_html__( 'No users found with "%s" role', 'asana' ), $field_post_type) . '</p>';
        }

      echo '</div>';

    echo '</div>';

}

// Posts similar by tags with thumbnails
function uni_similar_posts_by_tags() {

    global $post;
    $oOriginalPost = $post;
    $aTags = wp_get_post_tags( $post->ID );

    if ( isset($aTags) ) {
        $aRelatedTagArray = array();
        foreach($aTags as $oTag)
            $aRelatedTagArray[] = $oTag->term_id;

        $aRelatedArgs = array(
            'post_type' => 'post',
            'tag__in' => $aRelatedTagArray,
            'post__not_in' => array($post->ID),
            'posts_per_page' => 3,
            'orderby' => 'rand',
            'ignore_sticky_posts' => 1
        );

        $oRelatedQuery = new wp_query( $aRelatedArgs );
        if( $oRelatedQuery->have_posts() ) {

        echo '<div class="relatedPostsV2">
                    <h3>'.esc_html__('Related Posts', 'asana').'</h3>
                    <div class="relatedPostsWrapV2 clear">';

        while( $oRelatedQuery->have_posts() ) {
        $oRelatedQuery->the_post();
        ?>
                        <div class="relatedPostsItemV2">
                            <a href="<?php the_permalink() ?>" class="relatedPostsThumbV2" title="<?php the_title_attribute() ?>">
                            <?php if ( has_post_thumbnail() ) { ?>
                                <?php the_post_thumbnail( 'unithumb-relativepost', array( 'alt' => the_title_attribute('echo=0') ) ); ?>
                            <?php } else { ?>
                                <img src="http://placehold.it/260x174" width="260" height="174" alt="<?php the_title_attribute() ?>" />
                            <?php } ?>
                            </a>
                            <h4><a href="<?php the_permalink() ?>" title="<?php the_title_attribute() ?>"><?php the_title() ?></a></h4>
        <?php
        $aCategories = wp_get_post_terms( $post->ID, 'category' );
        if ( $aCategories && !is_wp_error( $aCategories ) ) :
        $s = count($aCategories);
        $i = 1;
        foreach ( $aCategories as $oTerm ) {
            echo '<a href="'.esc_url( get_term_link( $oTerm->slug, 'category' ) ).'" class="categoryLink">'.esc_attr( $oTerm->name ).'</a>';
            if ($i < $s) echo ', ';
            $i++;
        }
        endif;
        ?>
                        </div>
        <?php }
        echo '</div>
                </div>';
        }
        }
        $post = $oOriginalPost;
        wp_reset_postdata();
}

//
function uni_pre_get_posts( $query ) {
    //global $wp_query;
    if ( !is_admin() && is_tax('uni_event_cat') && $query->is_main_query() ) {
        if ( isset($_GET['events_sort']) && $_GET['events_sort'] == 'newer' ) {
            $query->set('order', 'DESC');
            $query->set('orderby', 'meta_value');
            $query->set('meta_key', 'uni_event_date');
            $query->set('meta_type', 'DATE');
        } else if ( isset($_GET['events_sort']) && $_GET['events_sort'] == 'older' ) {
            $query->set('order', 'ASC');
            $query->set('orderby', 'meta_value');
            $query->set('meta_key', 'uni_event_date');
            $query->set('meta_type', 'DATE');
        }
    }
    return $query;
}
add_filter('pre_get_posts','uni_pre_get_posts');

// Related by tags posts with thumb
function uni_relative_posts_by_tags() {

    global $post;
    $oOriginalPost = $post;
    $aTags = wp_get_post_tags( $post->ID );

    if ( isset($aTags) ) {
        $aRelativeTagArray = array();
        foreach($aTags as $oTag)
            $aRelativeTagArray[] = $oTag->term_id;

        $aRelatedArgs = array(
            'post_type' => 'post',
            'tag__in' => $aRelativeTagArray,
            'post__not_in' => array($post->ID),
            'posts_per_page' => 3,
            'orderby' => 'rand',
            'ignore_sticky_posts' => 1
        );

        $oRelatedQuery = new wp_query( $aRelatedArgs );
        if( $oRelatedQuery->have_posts() ) {

        echo '<div class="relatedPosts">
			    <div class="blockTitle">'.esc_html__('Related posts', 'asana').'</div>
			    <div class="blogPostWrap">';

        while( $oRelatedQuery->have_posts() ) {
        $oRelatedQuery->the_post();
        ?>
				<div class="postItem">
					<a href="<?php the_permalink() ?>" class="postItemImg">
                        <?php if ( has_post_thumbnail() ) { ?>
                            <?php the_post_thumbnail( 'unithumb-blog', array( 'alt' => the_title_attribute('echo=0') ) ); ?>
                        <?php } else { ?>
                            <img src="http://placehold.it/408x272/5FC7AE/FFFFFF" width="408" height="272" alt="<?php the_title_attribute() ?>" />
                        <?php } ?>
					</a>
					<h4><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h4>
					<?php uni_excerpt(15, '', true) ?>
				</div>
        <?php }
        echo '</div>
				</div>';
        }
        }
        $post = $oOriginalPost;
        wp_reset_postdata();
}

// post navigation * deprecated! *
function uni_pagination($sPages = '', $sRange = 1) {
     echo 'This function is deprecated!';
}

// custom excerpt
function uni_excerpt( $iLength, $iPostId = '', $bEcho = false, $sMore = null ) {
    if ( !empty($iPostId) ) {
        $oPost = get_post( $iPostId );
    } else {
        global $post;
        $oPost = $post;
    }

	if ( null === $sMore )
		$sMore = esc_html__( '&hellip;', 'asana' );

    $sContent = $oPost->post_content;
	$sContent = wp_strip_all_tags( $sContent );
    $sContent = strip_shortcodes( $sContent );
	if ( 'characters' == _x( 'words', 'word count: words or characters?', 'asana' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
		$sContent = trim( preg_replace( "/[\n\r\t ]+/", ' ', $sContent ), ' ' );
		preg_match_all( '/./u', $sContent, $aWordsArray );
		$aWordsArray = array_slice( $aWordsArray[0], 0, $iLength + 1 );
		$sep = '';
	} else {
		$aWordsArray = preg_split( "/[\n\r\t ]+/", $sContent, $iLength + 1, PREG_SPLIT_NO_EMPTY );
		$sep = ' ';
	}

	if ( count( $aWordsArray ) > $iLength ) {
		array_pop( $aWordsArray );
		$sContent = implode( $sep, $aWordsArray );
        $sContent = $sContent . $sMore;
	} else {
		$sContent = implode( $sep, $aWordsArray );
	}
    if ( $bEcho ) {
        echo '<p>'.$sContent.'</p>';
    } else {
        return $sContent;
    }
}

//
function uni_allowed_html_wo_a() {
    $aAllowedHtml = array(
        'br' => array(),
        'em' => array(),
        'strong' => array(),
    );
    return $aAllowedHtml;
}

//
function uni_allowed_html_with_a() {
    $aAllowedHtml = array(
        'a' => array(
            'href' => array(),
            'title' => array(),
            'target' => array()
        ),
        'br' => array(),
        'em' => array(),
        'strong' => array(),
    );
    return $aAllowedHtml;
}

function new_excerpt_more( $more ) {
	return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

function uni_share_facebook() {
	return esc_url( 'https://www.facebook.com/dialog/share?app_id='.ot_get_option('uni_fb_app_id').'&href='.esc_url( get_permalink() ).'&redirect_uri='.esc_url( get_permalink() ) );
}

function uni_share_twitter() {
	return esc_url( 'http://twitter.com/share?text='.urlencode(get_the_title()).'&url='.esc_url( get_permalink() ) );
}

function uni_share_gplus() {
	return esc_url( 'https://plus.google.com/share?url='.esc_url( get_permalink() ) );
}

function uni_share_pinterest() {
    $aImage = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    $sImageUrl = '';
	if ( isset($aImage[0]) ) $sImageUrl = $aImage[0];
	if ( $sImageUrl == false ) {
		$sImageUrl = get_template_directory_uri() . '/images/placeholders/unithumb-portfolioone.png';
	}
	return esc_url( 'http://pinterest.com/pin/create/button/?url='.esc_url( get_permalink() )
            .'&media='.esc_url( $sImageUrl ).'&description='.urlencode(get_the_title()) );
}

// comments
function uni_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;
    global $post;
	?>
	<li id="comment-<?php comment_ID(); ?>" <?php comment_class(empty($args['has_children']) ? '' : 'parent'); ?>>
	<a id="view-comment-<?php comment_ID(); ?>" class="comment-anchor"></a>
	<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
		<footer class="comment-meta">
			<div class="comment-author vcard">
				<?php if (0 != $args['avatar_size']) echo get_avatar($comment, $args['avatar_size']); ?>
			</div><!-- .comment-author -->

			<div class="reply">
				<?php comment_reply_link(array_merge($args, array(
					'add_below' => 'div-comment',
					'depth' => $depth,
					'max_depth' => $args['max_depth'],
					'before' => '<div>',
					'after' => '</div>'
				))); ?>
			</div><!-- .reply -->
		</footer><!-- .comment-meta -->

		<div class="comment-wrapper">
			<?php
            if ( $comment->user_id === $post->post_author ) {
                printf('<cite class="fn">%s</cite><span class="uni-post-author">%s</span>', get_comment_author_link(), esc_html__('post author', 'asana'));
            } else {
                printf('<cite class="fn">%s</cite>', get_comment_author_link());
            }
            ?>

			<span class="comment-metadata">
				<a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?>">
					<time datetime="<?php comment_time('c'); ?>">
						<?php printf(_x('%1$s at %2$s', '1: date, 2: time', 'asana'), get_comment_date(), get_comment_time()); ?>
					</time>
				</a>
				<?php edit_comment_link(esc_html__('Edit', 'asana'), '<span class="separator">&middot;</span> <span class="edit-link">', '</span>'); ?>
			</span><!-- .comment-metadata -->

			<?php if ('0' == $comment->comment_approved): ?>
				<p class="comment-awaiting-moderation"><?php esc_html_e('Your comment is awaiting moderation.', 'asana'); ?></p>
			<?php endif; ?>

			<div class="comment-content">
				<?php comment_text(); ?>
			</div><!-- .comment-content -->
		</div>
	</article><!-- .comment-body -->
<?php
}

// popup messages
if ( !function_exists('uni_add_js_message_div') ) {
    function uni_add_js_message_div() {
        echo '<div id="uni_popup"></div>';
    }
    add_action('wp_footer', 'uni_add_js_message_div');
}

// Ajax contact form - processing
function uni_contact_form(){

        $aResult               = array();
        $aResult['message']    = esc_html__('Error!', 'asana');
        $aResult['status']     = 'error';

        $sCustomerName          = ( ( isset($_POST['uni_contact_name']) ) ? esc_sql($_POST['uni_contact_name']) : '' );
        $sCustomerEmail         = ( ( isset($_POST['uni_contact_email']) ) ? esc_sql($_POST['uni_contact_email']) : '' );
        $sCustomerSubject       = ( ( isset($_POST['uni_contact_subject']) ) ? esc_sql($_POST['uni_contact_subject']) : '' );
        $sCustomerMsg           = ( ( isset($_POST['uni_contact_msg']) ) ? esc_sql($_POST['uni_contact_msg']) : '' );
        $iPageId                = ( ( isset($_POST['page_id']) ) ? esc_sql(intval($_POST['page_id'])) : '' );
        $sNonce                 = $_POST['uni_contact_nonce'];
        $sAntiCheat             = $_POST['cheaters_always_disable_js'];

        if ( ( empty($sAntiCheat) || $sAntiCheat != 'true_bro' ) || !wp_verify_nonce( $_POST['uni_contact_nonce'], 'uni_nonce' ) ) {
            wp_send_json( $aResult );
        }

        if ( $sCustomerName && $sCustomerEmail && $sCustomerSubject && $sCustomerMsg ) {

            if ( !empty($iPageId) ) {
                $aPostCustom = get_post_custom( $iPageId );
                if ( !empty($aPostCustom['uni_contact_email'][0]) ) {
                    $sToEmail = sanitize_email( $aPostCustom['uni_contact_email'][0] );
                } else if ( ot_get_option( 'uni_email' ) && empty($aPostCustom['uni_contact_email'][0]) ) {
                    $sToEmail = sanitize_email( ot_get_option( 'uni_email' ) );
                } else {
                    $sToEmail = esc_attr( get_bloginfo('admin_email') );
                }
            } else {
                $sToEmail 		= ( ot_get_option( 'uni_email' ) ) ? ot_get_option( 'uni_email' ) : get_bloginfo('admin_email');
            }
            $sFromEmail         = $sCustomerEmail;
            $sHeadersText       = "$sCustomerName <$sFromEmail>";
	        $sSubjectText 		= $sCustomerSubject;

            $sBlogName          = get_bloginfo('name');

            $sMessage           =
                    "<h3>".sprintf( esc_html__('You have a new message sent from "%s"!', 'asana'), $sBlogName )."</h3>
                    <p></p>
                    <p><strong>".esc_html__('Contact information', 'asana').":</strong><br>
                    ".sprintf( esc_html__('Name: %s', 'asana'), $sCustomerName )."
                    <br>
                    ".sprintf( esc_html__('Email: %s', 'asana'), $sCustomerEmail )."
                    <br>
                    ".esc_html__('Message', 'asana').":
                    <br>$sCustomerMsg
                    </p>";
            $sMessage = stripslashes_deep( $sMessage );

            uni_send_email_wrapper( $sToEmail, $sHeadersText, $sSubjectText, false, array(), $sMessage );

            $aResult['status']     = 'success';
            $aResult['message']    = esc_html__('Thanks! You message has been sent!', 'asana');

        } else {
            $aResult['message']    = esc_html__('All fields are required!', 'asana');
        }

	    wp_send_json( $aResult );
}
add_action('wp_ajax_uni_contact_form', 'uni_contact_form');
add_action('wp_ajax_nopriv_uni_contact_form', 'uni_contact_form');

// join event form - processing
function uni_join_event_form(){

        $aResult               = array();
        $aResult['message']    = esc_html__('Error!', 'asana');
        $aResult['status']     = 'error';

        $sCustomerFName         = ( !empty($_POST['uni_contact_firstname']) ) ? esc_sql($_POST['uni_contact_firstname']) : '';
        $sCustomerLName         = ( !empty($_POST['uni_contact_lastname']) ) ? esc_sql($_POST['uni_contact_lastname']) : '';
        $sCustomerEmail         = ( !empty($_POST['uni_contact_email']) ) ? esc_sql($_POST['uni_contact_email']) : '';
        $sCustomerPhone         = ( !empty($_POST['uni_contact_phone']) ) ? esc_sql($_POST['uni_contact_phone']) : '';
        $sCustomerMsg           = ( !empty($_POST['uni_contact_msg']) ) ? stripslashes_deep( strip_tags( $_POST['uni_contact_msg'] ) ) : '';
        $iEventId               = absint( esc_sql($_POST['event_id']) );
        $sNonce                 = $_POST['uni_contact_nonce'];
        $sAntiCheat             = $_POST['cheaters_always_disable_js'];

        if ( ( empty($sAntiCheat) || $sAntiCheat != 'true_bro' ) || !wp_verify_nonce( $_POST['uni_contact_nonce'], 'uni_nonce' ) ) {
            wp_send_json( $aResult );
        }

        if ( $sCustomerFName && $sCustomerLName && $sCustomerEmail && $sCustomerPhone && $sCustomerMsg ) {

            $sAdminEmail        = ( ot_get_option( 'uni_email' ) ) ? ot_get_option( 'uni_email' ) : get_bloginfo('admin_email');
            $sEventTitle        = esc_attr( get_the_title( $iEventId ) );
            $aCustomData        = get_post_custom( $iEventId );
            $sEventDate         = ( !empty($aCustomData['uni_event_date'][0]) ) ? esc_html( $aCustomData['uni_event_date'][0] ) : esc_html__('- not specified -', 'asana');
            $sEventTime         = ( !empty($aCustomData['uni_event_time'][0]) ) ? esc_html( $aCustomData['uni_event_time'][0] ) : esc_html__('- not specified -', 'asana');
            $sEventLocation     = ( !empty($aCustomData['uni_event_address'][0]) ) ? esc_html( $aCustomData['uni_event_address'][0] ) : esc_html__('- not specified -', 'asana');
            $sEventPrice        = ( !empty($aCustomData['uni_event_price'][0]) ) ? esc_html( $aCustomData['uni_event_price'][0] ) : esc_html__('- not specified -', 'asana');
            $sPhone             = ( ot_get_option( 'uni_phone' ) ) ? esc_html( ot_get_option( 'uni_phone' ) ) : '+88 (0) 101 0000 000';
            $sEmail             = ( ot_get_option( 'uni_email' ) ) ? esc_html( ot_get_option( 'uni_email' ) ) : esc_html( get_bloginfo('admin_email') );

            // send an email to the client
            $sBlogName          = get_bloginfo('name');
            $sHeadersText       = esc_attr($sBlogName)." "."<$sAdminEmail>";
            $sSubjectText 		= sprintf( esc_html__( 'Successful registration for %s', 'asana'), $sEventTitle );
            $sEmailTemplateName = apply_filters( 'uni_asana_event_email_filter', 'email/event-guest.php', 'guest' );
            $aMailVars = array( '$sEventTitle' => '"'.$sEventTitle.'"', '$sEventDate' => $sEventDate, '$sEventTime' => $sEventTime,
                                '$sEventLocation' => $sEventLocation, '$sEventPrice' => $sEventPrice, '$sPhone' => $sPhone, '$sEmail' => $sEmail );

            uni_send_email_wrapper( $sCustomerEmail, $sHeadersText, $sSubjectText, $sEmailTemplateName, $aMailVars, '' );

            // send an email to the admin
            $sHeadersText       = "$sCustomerFName $sCustomerLName <$sCustomerEmail>";
            $sSubjectText 		= sprintf( esc_html__( 'A new registration for %s', 'asana'), $sEventTitle );
            $sClientName        = $sCustomerFName.' '.$sCustomerLName;
            $sClientTel         = $sCustomerPhone;
            $sClientEmail       = $sCustomerEmail;
            $sClientMsg         = $sCustomerMsg;
            $sEmailTemplateName = apply_filters( 'uni_asana_event_email_filter', 'email/event-admin.php', 'admin' );
            $aMailVars = array( '$sEventTitle' => '"'.$sEventTitle.'"', '$sEventDate' => $sEventDate, '$sClientName' => $sClientName,
                                '$sClientTel' => $sClientTel, '$sClientEmail' => $sClientEmail, '$sClientMsg' => $sClientMsg );

            uni_send_email_wrapper( $sAdminEmail, $sHeadersText, $sSubjectText, $sEmailTemplateName, $aMailVars, '' );

            $aResult['status']     = 'success';
            $aResult['message']    = esc_html__('Thanks! You have successfully registered!', 'asana');

        } else {
            $aResult['message']    = esc_html__('All fields are required!', 'asana');
        }

	    wp_send_json( $aResult );
}
add_action('wp_ajax_uni_join_event_form', 'uni_join_event_form');
add_action('wp_ajax_nopriv_uni_join_event_form', 'uni_join_event_form');

// price form - processing
function uni_price_form(){

        $aResult               = array();
        $aResult['message']    = esc_html__('Error!', 'asana');
        $aResult['status']     = 'error';

        $sCustomerFName         = ( !empty($_POST['uni_contact_firstname']) ) ? esc_sql($_POST['uni_contact_firstname']) : '';
        $sCustomerLName         = ( !empty($_POST['uni_contact_lastname']) ) ? esc_sql($_POST['uni_contact_lastname']) : '';
        $sCustomerEmail         = ( !empty($_POST['uni_contact_email']) ) ? esc_sql($_POST['uni_contact_email']) : '';
        $sCustomerPhone         = ( !empty($_POST['uni_contact_phone']) ) ? esc_sql($_POST['uni_contact_phone']) : '';
        $sCustomerMsg           = ( !empty($_POST['uni_contact_msg']) ) ? stripslashes_deep( strip_tags( $_POST['uni_contact_msg'] ) ) : '';
        $iPriceId               = absint( esc_sql($_POST['uni_price_id']) );
        $sNonce                 = $_POST['uni_contact_nonce'];
        $sAntiCheat             = $_POST['cheaters_always_disable_js'];

        if ( ( empty($sAntiCheat) || $sAntiCheat != 'true_bro' ) || !wp_verify_nonce( $_POST['uni_contact_nonce'], 'uni_nonce' ) ) {
            wp_send_json( $aResult );
        }

        if ( $sCustomerFName && $sCustomerLName && $sCustomerEmail && $sCustomerPhone && $sCustomerMsg ) {

            $sAdminEmail        = ( ot_get_option( 'uni_email' ) ) ? ot_get_option( 'uni_email' ) : get_bloginfo('admin_email');
            $sPriceTitle        = esc_attr( get_the_title( $iPriceId ) );
            $aCustomData        = get_post_custom( $iPriceId );
            $sPriceCurrency     = ( !empty($aCustomData['uni_currency'][0]) ) ? esc_html( $aCustomData['uni_currency'][0] ) : esc_html__('- not specified -', 'asana');
            $sPriceVal          = ( !empty($aCustomData['uni_price_val'][0]) ) ? esc_html( $aCustomData['uni_price_val'][0] ) : esc_html__('- not specified -', 'asana');
            $sPricePeriod       = ( !empty($aCustomData['uni_period'][0]) ) ? esc_html( $aCustomData['uni_period'][0] ) : esc_html__('- not specified -', 'asana');
            $sPhone             = ( ot_get_option( 'uni_phone' ) ) ? esc_html( ot_get_option( 'uni_phone' ) ) : '+88 (0) 101 0000 000';
            $sEmail             = ( ot_get_option( 'uni_email' ) ) ? esc_html( ot_get_option( 'uni_email' ) ) : esc_html( get_bloginfo('admin_email') );

            // send an email to the client
            $sBlogName          = get_bloginfo('name');
            $sHeadersText       = esc_attr($sBlogName)." "."<$sAdminEmail>";
            $sSubjectText 		= sprintf( esc_html__( 'Successful request for %s', 'asana'), $sPriceTitle );
            $sEmailTemplateName = apply_filters( 'uni_asana_price_email_filter', 'email/price-guest.php', 'guest' );
            $aMailVars = array( '$sPriceTitle' => '"'.$sPriceTitle.'"', '$sPriceCurrency' => $sPriceCurrency, '$sPriceVal' => $sPriceVal,
                                '$sPricePeriod' => $sPricePeriod, '$sPhone' => $sPhone, '$sEmail' => $sEmail );

            uni_send_email_wrapper( $sCustomerEmail, $sHeadersText, $sSubjectText, $sEmailTemplateName, $aMailVars, '' );

            // send an email to the admin
            $sHeadersText       = "$sCustomerFName $sCustomerLName <$sCustomerEmail>";
            $sSubjectText 		= sprintf( esc_html__( 'A new request for %s', 'asana'), $sPriceTitle );
            $sClientName        = $sCustomerFName.' '.$sCustomerLName;
            $sClientTel         = $sCustomerPhone;
            $sClientEmail       = $sCustomerEmail;
            $sClientMsg         = $sCustomerMsg;
            $sEmailTemplateName = apply_filters( 'uni_asana_price_email_filter', 'email/price-admin.php', 'admin' );
            $aMailVars = array( '$sPriceTitle' => '"'.$sPriceTitle.'"', '$sPricePeriod' => $sPricePeriod, '$sClientName' => $sClientName,
                                '$sClientTel' => $sClientTel, '$sClientEmail' => $sClientEmail, '$sClientMsg' => $sClientMsg );

            uni_send_email_wrapper( $sAdminEmail, $sHeadersText, $sSubjectText, $sEmailTemplateName, $aMailVars, '' );

            $aResult['status']     = 'success';
            $aResult['message']    = esc_html__('Thanks! You request is successfully sent!', 'asana');

        } else {
            $aResult['message']    = esc_html__('All fields are required!', 'asana');
        }

	    wp_send_json( $aResult );
}
add_action('wp_ajax_uni_price_form', 'uni_price_form');
add_action('wp_ajax_nopriv_uni_price_form', 'uni_price_form');

// mailchimp subscribe user
function uni_mailchimp_subscribe_user(){

    $aResult                = array();
    $aResult['message']     = esc_html__('Error!', 'asana');
    $aResult['status']      = 'error';

    $sEmail                 = $_POST['uni_input_email'];
    $sAntiCheat             = $_POST['cheaters_always_disable_js'];

    if ( empty($sAntiCheat) || $sAntiCheat != 'true_bro' ) {
        wp_send_json( $aResult );
    }

    $sApiKey            = ot_get_option( 'uni_mailchimp_api_key' );
    $sListId            = ot_get_option( 'uni_mailchimp_list_id' );

    if ( !empty($sApiKey) && !empty($sListId) ) {

        $oUniMailchimp = Uni_Mailchimp_Universal( $sApiKey, $sListId );
        $aResponse = $oUniMailchimp->call_lists_members( 'lists/members', 'POST', array('email_address' => $sEmail, 'status' => 'pending') );

        if ( $aResponse['status'] == 'success' ) {
            $aResult['message']     = esc_html__('Success!', 'asana');
            $aResult['status']      = 'success';
        } else {
            $aResult['message']     = ( isset($aResponse['response']->detail) && !empty($aResponse['response']->detail) ) ? $aResponse['response']->detail : $aResponse['message'];
        }

    } else {
        $aResult['message']     = esc_html__('No API key and/or List ID is/are specified!', 'asana');
    }

    wp_send_json( $aResult );
}
add_action('wp_ajax_uni_mailchimp_subscribe_user', 'uni_mailchimp_subscribe_user');
add_action('wp_ajax_nopriv_uni_mailchimp_subscribe_user', 'uni_mailchimp_subscribe_user');

// body classes
function asana_body_classes( $classes ) {
    if ( class_exists('Woocommerce') ) {
        if ( is_cart() || is_checkout() ) {
            foreach ( $classes as $sKey => $sClass ) {
                if ( $sClass == 'page-template-default' ) {
                    unset($classes[$sKey]);
                }
            }
        }
    }
    if ( ot_get_option('uni_nav_white_enable') && ot_get_option('uni_nav_white_enable') == 'on' ) {
        $classes[] = 'fixedMainMenu';
    }
    if ( ( ( is_home() || is_front_page() ) && ( ot_get_option('uni_home_rev_slider_enable') && ot_get_option('uni_home_rev_slider_enable') == 'off' && ot_get_option('uni_home_slider_enable') && ot_get_option('uni_home_slider_enable') == 'off' ) )
        || ( ( is_home() || is_front_page() ) && !ot_get_option('uni_home_rev_slider_enable') && !ot_get_option('uni_home_slider_enable') ) ) {
        $classes[] = 'home-slider-disabled';
    }
	return $classes;
}
add_filter( 'body_class', 'asana_body_classes' );

//
function uni_send_email_wrapper( $sEmailTo, $sEmailFrom, $sSubjectText, $sEmailTemplateName, $aMailVars = array(), $sEmailText = '' ) {

	    $sCharset = 'UTF-8';
	    mb_internal_encoding($sCharset);

	    $sSubject           = mb_convert_encoding($sSubjectText, $sCharset, 'auto');
	    $sSubject           = mb_encode_mimeheader($sSubjectText, $sCharset, 'B');
        $sHeaders 			= "From: $sEmailFrom\r\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";

        if ( $sEmailTemplateName != false ) {
            $sMailContent   = uni_get_email_content_html( $sEmailTemplateName, $aMailVars );
        } else {
            $sMailContent   = $sEmailText;
        }

        wp_mail($sEmailTo, $sSubject, $sMailContent, $sHeaders);

}

//
function uni_get_email_content_html( $sEmailTemplateName, $aMailVars = array() ) {
		ob_start();
		uni_get_template( $sEmailTemplateName );
		$sMailContent = ob_get_clean();
        if ( !empty($aMailVars) ) {
            foreach ( $aMailVars as $sVarName => $sVarValue ) {
                $sMailContent = str_replace($sVarName, $sVarValue, $sMailContent);
            }
        }
        return $sMailContent;
}

//
function uni_get_template( $sEmailTemplateName, $args = array() ) {
	if ( $args && is_array( $args ) ) {
		extract( $args );
	}

    if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $sEmailTemplateName ) ) {
        $sTemplatePath = trailingslashit( get_stylesheet_directory() ) . $sEmailTemplateName;
    } else if ( file_exists( trailingslashit( get_template_directory() ) . $sEmailTemplateName ) ) {
        $sTemplatePath = trailingslashit( get_template_directory() ) . $sEmailTemplateName;
    } else {
		return;
	}

	include( $sTemplatePath );
}

//*********** WooCommerce ****************************************************************
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50);

add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 5);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 15);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50);

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);

remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
//remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);

remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);

add_action( 'woocommerce_before_main_content', 'uni_woo_output_content_wrapper', 10);
//add_action( 'woocommerce_before_main_content', 'uni_woo_search_form', 20);
//add_action( 'woocommerce_before_main_content', 'uni_woocommerce_breadcrumb', 30);
add_action( 'woocommerce_after_main_content', 'uni_woo_output_content_wrapper_end', 10);

// Display 12 products per page.
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );

add_filter( 'woocommerce_currency_symbol', 'uni_currency_symbol_markup', 2, 10 );
function uni_currency_symbol_markup($sCurrencySymbol, $currency) {
    return '<span>'.$sCurrencySymbol.'</span>';
}

function uni_woo_output_content_wrapper() {
    // if this is single product page
    if ( is_singular('product') ) {
        $iShopAttachId  = ( ot_get_option( 'uni_shop_header_bg' ) ) ? ot_get_option( 'uni_shop_header_bg' ) : '';
        $sTitleColor    = ( ot_get_option( 'uni_shop_header_title_color' ) ) ? ot_get_option( 'uni_shop_header_title_color' ) : '#ffffff';
        if ( !empty($iShopAttachId) ) {
            $aPageHeaderImage = wp_get_attachment_image_src( $iShopAttachId, 'full' );
            $sPageHeaderImage = $aPageHeaderImage[0];
        } else {
            $sPageHeaderImage = get_template_directory_uri().'/images/placeholders/pageheader-shop.jpg';
        }
        $sOutput = '<section class="uni-container">
		    <div class="pageHeader" style="background-image: url('.esc_url( $sPageHeaderImage ).');">';
		    if ( ot_get_option( 'uni_shop_header_title' ) ) {
                $sOutput .= '<h1>'.esc_html( ot_get_option( 'uni_shop_header_title' ) ).'</h1>';
            } else {
			    $sOutput .= '<h1>'.esc_html__('ONLINE BOUTIQUE', 'asana').'</h1>';
            }
	    $sOutput .= '</div>';
        $sOutput .= '<style>.pageHeader h1 {color:'.$sTitleColor.';}</style>';
		$sOutput .= '<div class="contentWrap">';
    // other pages
    } else {
        $iShopAttachId  = ( ot_get_option( 'uni_shop_header_bg' ) ) ? ot_get_option( 'uni_shop_header_bg' ) : '';
        $sTitleColor    = ( ot_get_option( 'uni_shop_header_title_color' ) ) ? ot_get_option( 'uni_shop_header_title_color' ) : '#ffffff';
        if ( !empty($iShopAttachId) ) {
            $aPageHeaderImage = wp_get_attachment_image_src( $iShopAttachId, 'full' );
            $sPageHeaderImage = $aPageHeaderImage[0];
        } else {
            $sPageHeaderImage = get_template_directory_uri().'/images/placeholders/pageheader-shop.jpg';
        }
        $sOutput = '<section class="uni-container">
		    <div class="pageHeader" style="background-image: url('.esc_url( $sPageHeaderImage ).');">';
            if ( is_shop() ) {
		        if ( ot_get_option( 'uni_shop_header_title' ) ) {
                    $sOutput .= '<h1>'.esc_html( ot_get_option( 'uni_shop_header_title' ) ).'</h1>';
                } else {
			        $sOutput .= '<h1>'.esc_html__('ONLINE BOUTIQUE', 'asana').'</h1>';
                }
            } else {
                $sOutput .= '<h1 class="page-title">'.woocommerce_page_title( false ).'</h1>';
            }
	    $sOutput .= '</div>';
        $sOutput .= '<style>.pageHeader h1 {color:'.$sTitleColor.';}</style>';
		$sOutput .= '<div class="contentWrap">';
    }

    echo $sOutput;
}

function uni_woo_output_content_wrapper_end() {
  echo '<div class="overlay"></div>
		</div>
	</section>';
}

//
function uni_woo_get_formatted_price( $sPrice ) {

	$num_decimals    = absint( get_option( 'woocommerce_price_num_decimals' ) );
	$currency        = isset( $args['currency'] ) ? $args['currency'] : '';
	$currency_symbol = get_woocommerce_currency_symbol($currency);
	$decimal_sep     = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ), ENT_QUOTES );
	$thousands_sep   = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES );

	$price           = apply_filters( 'raw_woocommerce_price', floatval( $sPrice ) );
	$price           = apply_filters( 'formatted_woocommerce_price', number_format( $price, $num_decimals, $decimal_sep, $thousands_sep ), $price, $num_decimals, $decimal_sep, $thousands_sep );
    return sprintf( get_woocommerce_price_format(), $currency_symbol, $price );
}

//
function uni_woo_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0, $iPostId ) {
         if ( has_post_thumbnail($iPostId) )
             return get_the_post_thumbnail( $iPostId, $size );
         elseif ( wc_placeholder_img_src() )
             return uni_woo_placeholder_img( $placeholder_width, $placeholder_height );
}

//
function uni_woo_placeholder_img( $sWidth = 100, $sHeight = 100 ) {
     return '<img src="' . wc_placeholder_img_src() . '" alt="' . esc_html__( 'Placeholder', 'woocommerce' ) . '" width="' . esc_attr( $sWidth ) . '" class="woocommerce-placeholder wp-post-image" height="' . esc_attr( $sHeight ) . '" />';
}

function uni_minicart_content() {
    global $woocommerce;

    ?>
			<div class="miniCartPopup">
				<div class="miniCartPopupHead">
					<h3><?php esc_html_e('YOUR CART', 'asana'); ?></h3>
					<span class="closeCartPopup"></span>
				</div>

                <?php if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) : ?>
                    <div class="miniCartItemWrap">
                <?php
                    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                        $_product     = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
                        $product_id     = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
					    $product_name   = apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key );
  					    $thumbnail      = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
                        $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
                        //$product_price = $cart_item['data']->price * $cart_item['quantity'];
                ?>
    					<div class="miniCartItem" data-product_id="<?php echo $product_id ?>"<?php if ( !empty($cart_item['_uni_cpo_cart_item_id']) ) { ?> data-cart_item_id="<?php echo esc_attr( $cart_item['_uni_cpo_cart_item_id'] ) ?>"<?php } ?>>
    						<a href="<?php echo esc_url( $_product->get_permalink( $cart_item ) ); ?>" class="miniCartItemImg">
    							<?php echo uni_woo_get_product_thumbnail('unithumb-minicartphoto', 52, 52, $product_id) ?>
    						</a>
    						<h3>
    							<a href="<?php echo esc_url( $_product->get_permalink( $cart_item ) ); ?>"><?php echo $product_name; ?></a>
    						</h3>
    						<p class="price"><?php
                            echo $product_price;
                            //echo uni_woo_get_formatted_price( $product_price ); ?></p>
    						<div class="quantity clear">
    							<span><?php esc_html_e('Quantity:', 'asana'); ?></span>
    							<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s', $cart_item['quantity'] ) . '</span>', $cart_item, $cart_item_key ); ?>
    						</div>
                            <?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="remove removeMiniCartItem" title="%s"></a>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), esc_html__( 'Remove this item', 'woocommerce' ) ), $cart_item_key ); ?>
                            <?php echo WC()->cart->get_item_data( $cart_item ); ?>
    					</div>
                        <?php } ?>
    					<div class="miniCartSubTotal">
    						<?php esc_html_e( 'Subtotal', 'woocommerce' ); ?>
    						<span><?php echo WC()->cart->get_cart_subtotal(); ?></span>
    					</div>
    					<a href="<?php echo WC()->cart->get_cart_url(); ?>" class="btnViewCart"><?php esc_html_e('view cart', 'asana'); ?></a>
    					<a href="<?php echo WC()->cart->get_checkout_url(); ?>" class="btnCheckout"><?php esc_html_e('checkout', 'asana'); ?></a>
                    
                <?php else: ?>
                    <div class="miniCartEmpty">
                        <i></i>
                        <p><?php esc_html_e( 'Your cart is empty', 'woocommerce' ); ?></p>
                    </div>
                <?php endif; ?>
				</div>
			</div>
    <?php
}

// Related products by product tags with thumb
function uni_relative_products_by_tags() {

    global $post;
    $oOriginalPost = $post;
    $aTags = wp_get_object_terms( $post->ID, 'product_tag' );

    if ( isset($aTags) ) {
        $aRelativeTagArray = array();
        foreach($aTags as $oTag)
            $aRelativeTagArray[] = $oTag->term_id;

        $aRelatedArgs = array(
            'post_type' => 'product',
            'tax_query' => array(
		        array(
			        'taxonomy' => 'product_tag',
			        'field'    => 'id',
			        'terms'    => $aRelativeTagArray,
		        ),
	        ),
            'post__not_in' => array($post->ID),
            'posts_per_page' => 5,
            'orderby' => 'rand',
            'ignore_sticky_posts' => 1
        );

        $oRelatedQuery = new wp_query( $aRelatedArgs );

        if( $oRelatedQuery->have_posts() ) {

        echo '<div class="relatedProducts">
				<div class="blockTitle">'.esc_html__('Related products', 'asana').'</div>
				<div class="shopItems">
					<ul class="shopItemsWrap">';

        while($oRelatedQuery->have_posts()) : $oRelatedQuery->the_post();

            wc_get_template_part( 'content', 'product' );

        endwhile;

                echo '</ul>
				</div>
			</div>';

        }

        }
        $post = $oOriginalPost;
        wp_reset_postdata();
}

// wishlist filters
add_filter( 'uni_wc_wishlist_table_image_size', 'uni_asana_wishlist_table_image_size', 10, 1 );
function uni_asana_wishlist_table_image_size( $sImageSize ) {
    return 'unithumb-cartimage';
}

function uni_order_by_rating_post_clauses( $args ) {

    global $wpdb;

    $args['fields'] .= ", AVG( $wpdb->commentmeta.meta_value ) as average_rating ";

    $args['where'] .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";

    $args['join'] .= "
			LEFT OUTER JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID)
			LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)
		";

    $args['orderby'] = "average_rating DESC, $wpdb->posts.post_date DESC";

    $args['groupby'] = "$wpdb->posts.ID";

    return $args;
}

//
header("X-XSS-Protection: 0");
?>