<?php

/*  CONSTANTAS
/*======================*/

    define( 'THEBUILDERS_NINZIO_TEMPPATH', get_template_directory_uri());
    define( 'THEBUILDERS_NINZIO_IMAGES', THEBUILDERS_NINZIO_TEMPPATH. "/images");

    // WPML CONSTANTAS
    define('ICL_DONT_LOAD_NAVIGATION_CSS', true);
    define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);

    function thebuilders_ninzio_global_variables(){
        global $thebuilders_ninzio, $woocommerce, $post, $product,$wp_query, $query_string;
    }

/*  HANDLE EXTERNAL PLUGINS
/*======================*/
    
    add_action( 'tgmpa_register', 'thebuilders_ninzio_register_required_plugins' );
    function thebuilders_ninzio_register_required_plugins() {

        $plugins = array(

            array(
                'name'      => esc_html__('Contact Form 7', 'thebuilders'),
                'slug'      => 'contact-form-7',
                'required'  => true,
                'dismissable' => true
            ),

            array(
                'name'        => esc_html__('Woocommerce', 'thebuilders'),
                'slug'        => 'woocommerce',
                'required'    => false,
                'dismissable' => true
            ),

            array(
                'name'      => esc_html__('One Click Demo Import', 'thebuilders'),
                'slug'      => 'one-click-demo-import',
                'required'  => true
            ),

            array(
                'name'      => esc_html__('Regenerate Thumbnails', 'thebuilders'),
                'slug'      => 'regenerate-thumbnails',
                'required'  => true,
                'dismissable' => true
            ),

            array(
                'name'      => esc_html__('Widgets in Menu for WordPress', 'thebuilders'),
                'slug'      => 'widgets-in-menu',
                'required'  => false,
                'dismissable' => true
            ),

            array(
                'name'      => esc_html__('Envato market master', 'thebuilders'),
                'slug'      => 'wp-envato-market-master',
                'source'    => get_template_directory() . '/plugins/wp-envato-market-master.zip',
                'required'  => true,
                'force_activation' => false,
                'force_deactivation' => false,
                'external_url' => '',
                'dismissable' => true
            ),

            array(
                'name'      => esc_html__('WPBakery Visual Composer', 'thebuilders'),
                'slug'      => 'js_composer',
                'source'    => get_template_directory() . '/plugins/js_composer.zip',
                'required'  => true,
                'force_activation' => false,
                'force_deactivation' => false,
                'external_url' => ''
            ),

            array(
                'name'      => esc_html__('Ninzio add-ons', 'thebuilders'),
                'slug'      => 'ninzio-addons',
                'source'    => get_template_directory() . '/plugins/ninzio-addons.zip',
                'required'  => true,
                'force_activation' => false,
                'force_deactivation' => false,
                'external_url' => ''
            ),

            array(
                'name'      => esc_html__('Revolution slider', 'thebuilders'),
                'slug'      => 'revslider',
                'source'    => get_template_directory() . '/plugins/revslider.zip',
                'required'  => true,
                'force_activation' => false,
                'force_deactivation' => false,
                'external_url' => '',
                'dismissable' => true
            )

        );

        $config = array(
            'id'                => 'thebuilders',
            'default_path'      => '',                          // Default absolute path to pre-packaged plugins
            'parent_slug'       => 'themes.php',                // Default parent menu slug
            'capability'        => 'edit_theme_options',
            'menu'              => 'install-required-plugins',  // Menu slug
            'has_notices'       => true,                        // Show admin notices or not
            'dismissable'       => false,
            'is_automatic'      => false,                       // Automatically activate plugins after installation or not
            'message'           => '',                          // Message to output right before the plugins table
            'strings'           => array(
                'page_title'                                => esc_html__( 'Install Required Plugins', 'thebuilders' ),
                'menu_title'                                => esc_html__( 'Install Plugins', 'thebuilders' ),
                'installing'                                => esc_html__( 'Installing Plugin: %s', 'thebuilders' ), // %1$s = plugin name
                'oops'                                      => esc_html__( 'Something went wrong with the plugin API.', 'thebuilders' ),
                'notice_can_install_required'               => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'thebuilders' ), // %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.', 'thebuilders' ), // %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.', 'thebuilders' ), // %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.', 'thebuilders' ), // %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.', 'thebuilders' ), // %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.', 'thebuilders' ), // %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.', 'thebuilders' ), // %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.', 'thebuilders' ), // %1$s = plugin name(s)
                'install_link'                              => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'thebuilders' ),
                'activate_link'                             => _n_noop( 'Activate installed plugin', 'Activate installed plugins', 'thebuilders' ),
                'return'                                    => esc_html__( 'Return to Required Plugins Installer', 'thebuilders' ),
                'plugin_activated'                          => esc_html__( 'Plugin activated successfully.', 'thebuilders' ),
                'complete'                                  => esc_html__( 'All plugins installed and activated successfully. %s', 'thebuilders' ), // %1$s = dashboard link
                'nag_type'                                  => 'updated' // Determines admin notice type - can only be 'updated' or 'error'
            )
        );

        tgmpa( $plugins, $config );

    }

/*  INCLUDES
/*======================*/

    if (!class_exists('TGM_Plugin_Activation') && file_exists( get_template_directory() . '/includes/class-tgm-plugin-activation.php' ) ) {
        require_once(get_template_directory() . '/includes/class-tgm-plugin-activation.php');
    }

    if (defined( 'WPB_VC_VERSION' ) && file_exists( get_template_directory() . '/plugins/js_composer.zip' ) ) {
        require_once(get_template_directory() . '/includes/ninzio_vc.php' );
    }

    require_once(get_template_directory() . '/includes/ninzio-functions.php');
    require_once(get_template_directory() . '/includes/custom-menu/custom-menu.php' );
    require_once(get_template_directory() . '/includes/dynamic-styles.php');
    require_once(get_template_directory() . '/includes/page-extended-options.php' );
    require_once(get_template_directory() . '/includes/post-extended-options.php' );

/*  THEME SUPPORTS
/*======================*/

    /*  Thumbnail support
    /*-------------------*/

        if ( function_exists( 'add_theme_support' ) ) {

            add_theme_support( 'post-thumbnails');
            add_image_size( 'Thebuilders-Ninzio-Half', 640, 520, true );           // Half
            add_image_size( 'Thebuilders-Ninzio-Square', 440, 400, true );         // Square
            add_image_size( 'Thebuilders-Ninzio-One-Third', 390, 300, true );      // One third
            add_image_size( 'Thebuilders-Ninzio-Two-Third', 780, 480, true );      // Two thirds
            add_image_size( 'Thebuilders-Ninzio-Three-Quarters', 870, 570, true ); // Two thirds
            add_image_size( 'Thebuilders-Ninzio-Whole', 1170, 570, true );         // Whole

        }

        function thebuilders_ninzio_custom_image_sizes( $sizes ) {
        
            $new_sizes = array();
            
            $added_sizes = get_intermediate_image_sizes();

            foreach( $added_sizes as $key => $value) {
                if($value != 'post-thumbnails' || $value != 'shop_thumbnail' || $value != 'shop_catalog' || $value != 'shop_single'){
                    $new_sizes[$value] = $value;
                }
            }

            $new_sizes = array_merge( $new_sizes, $sizes );
            
            return $new_sizes;
        }
        add_filter('image_size_names_choose', 'thebuilders_ninzio_custom_image_sizes', 11, 1);

    /*  Multiple post/projects thumbnails
    /*-------------------*/

        if (class_exists('MultiPostThumbnails')) {

            // MultiPostThumbnails for posts
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('2nd Featured Image', 'thebuilders'),
                    'id'        => 'feature-image-2',
                    'post_type' => 'post'
                )
            );
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('3rd Featured Image', 'thebuilders'),
                    'id'        => 'feature-image-3',
                    'post_type' => 'post'
                )
            );
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('4th Featured Image', 'thebuilders'),
                    'id'        => 'feature-image-4',
                    'post_type' => 'post'
                )
            );
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('5th Featured Image', 'thebuilders'),
                    'id'        => 'feature-image-5',
                    'post_type' => 'post'
                )
            );

            // MultiPostThumbnails for projects
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('2nd Featured Image', 'thebuilders'),
                    'id'        => 'project-feature-image-2',
                    'post_type' => 'projects'
                )
            );
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('3rd Featured Image', 'thebuilders'),
                    'id'        => 'project-feature-image-3',
                    'post_type' => 'projects'
                )
            );
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('4th Featured Image', 'thebuilders'),
                    'id'        => 'project-feature-image-4',
                    'post_type' => 'projects'
                )
            );
            new MultiPostThumbnails(
                array(
                    'label'     => esc_html__('5th Featured Image', 'thebuilders'),
                    'id'        => 'project-feature-image-5',
                    'post_type' => 'projects'
                )
            );
        }

    /*  HTML5 gallery and caption support (3.9 addition)
    /*-------------------*/

        add_theme_support( 'html5', array( 'gallery', 'caption' ) );

    /*  Content width
    /*-------------------*/

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

    /*  Enable excerpt for pages
    /*-------------------*/

        add_action('init', 'thebuilders_ninzio_page_excerpt');
        function thebuilders_ninzio_page_excerpt() {
            add_post_type_support( 'page', 'excerpt' );
        }

    /*  Enable post formats for posts
    /*-------------------*/

        add_theme_support( 'post-formats', array( 'aside', 'audio', 'video', 'gallery', 'link', 'quote', 'status', 'chat') );
        add_post_type_support( 'post', 'post-formats' );

    /*  Enable automatic feed links
    /*-------------------*/

        add_theme_support( 'automatic-feed-links' );

    /*  Languages
    /*-------------------*/

        add_action('after_setup_theme', 'thebuilders_ninzio_language_setup');
        function thebuilders_ninzio_language_setup(){
            load_theme_textdomain('thebuilders', get_template_directory() . '/languages');
        }

    /*  Menu
    /*-------------------*/

        function thebuilders_ninzio_register_menu() {

            register_nav_menus(
                array(
                  'header-menu-1'    => esc_html__( 'Header 2 menu left part', 'thebuilders' ),
                  'header-menu-2'    => esc_html__( 'Header 2 menu right part', 'thebuilders' ),
                  'header-menu'      => esc_html__( 'Header menu', 'thebuilders' ),
                  'header-top-menu'  => esc_html__( 'Header menu top navigation', 'thebuilders' ),
                  'one-page-bullets' => esc_html__( 'One page bullet navigation', 'thebuilders' ),
                  'footer-menu'      => esc_html__( 'Footer menu', 'thebuilders' ),
                )
            );

        }
        add_action( 'after_setup_theme', 'thebuilders_ninzio_register_menu' );

    /*  Sidebar
    /*-------------------*/

        add_action( 'widgets_init', 'thebuilders_ninzio_register_sidebars' );
        function thebuilders_ninzio_register_sidebars() {
            if ( function_exists( 'register_sidebar' ) ){

                register_sidebar( 
                    array (
                    'name'          => esc_html__( 'Blog sidebar', 'thebuilders'),
                    'id'            => 'blog-widget-area',
                    'description'   => esc_html__('Main widget area', 'thebuilders'),
                    'class'         => 'blog-widget-area',
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h6 class="widget_title">',
                    'after_title'   => '</h6>' )
                );

                register_sidebar( 
                    array (
                    'name'          => esc_html__( 'Blog sidebar single', 'thebuilders'),
                    'id'            => 'blog-widget-area-single',
                    'description'   => esc_html__('Blog widget area single', 'thebuilders'),
                    'class'         => 'blog-widget-area-single',
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h6 class="widget_title">',
                    'after_title'   => '</h6>' )
                );

                register_sidebar( 
                    array (
                    'name'          => esc_html__( 'Projects sidebar', 'thebuilders'),
                    'id'            => 'projects-widget-area',
                    'description'   => esc_html__('Projects widget area', 'thebuilders'),
                    'class'         => 'projects-widget-area',
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h6 class="widget_title">',
                    'after_title'   => '</h6>' )
                );

                register_sidebar( 
                    array (
                    'name'          => esc_html__( 'Shop sidebar', 'thebuilders'),
                    'id'            => 'shop-widget-area',
                    'description'   => esc_html__('Shop widget area', 'thebuilders'),
                    'class'         => 'shop-widget-area',
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h6 class="widget_title">',
                    'after_title'   => '</h6>' )
                );

                register_sidebar( 
                    array (
                    'name'          => esc_html__( 'Shop sidebar single product', 'thebuilders'),
                    'id'            => 'shop-widget-area-single',
                    'description'   => esc_html__('Shop widget area single', 'thebuilders'),
                    'class'         => 'shop-widget-area',
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h6 class="widget_title">',
                    'after_title'   => '</h6>' )
                );

                for ($i=1; $i < 4; $i++) { 
                    register_sidebar( 
                        array (
                        'name'          => esc_html__( 'Page sidebar #','thebuilders').$i,
                        'id'            => 'page-sidebar-'.$i,
                        'description'   => esc_html__('Page widget area', 'thebuilders'),
                        'class'         => 'page-widget-area',
                        'before_widget' => '<div id="%1$s" class="widget %2$s">',
                        'after_widget'  => '</div>',
                        'before_title'  => '<h6 class="widget_title">',
                        'after_title'   => '</h6>' )
                    );
                }

                register_sidebar( 
                    array (
                    'name'          => esc_html__( 'Footer sidebar', 'thebuilders'),
                    'id'            => 'footer-widget-area',
                    'description'   => esc_html__('Footer widget area', 'thebuilders'),
                    'class'         => 'footer-widget-area',
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h6 class="widget_title">',
                    'after_title'   => '</h6>' )
                );

            }   
        }

    /*  WooCommerce
    /*-------------------*/

        if (class_exists('Woocommerce')){

            thebuilders_ninzio_global_variables();

            if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) add_action( 'init', 'thebuilders_ninzio_woo_img', 1 );

            function thebuilders_ninzio_woo_img() {
                $catalog = array(
                    'width'     => '440',
                    'height'    => '440',
                    'crop'      => 0
                );
                $single = array(
                    'width'     => '570',
                    'height'    => '530',
                    'crop'      => 1
                );
                $thumbnail = array(
                    'width'     => '90',
                    'height'    => '90',
                    'crop'      => 1 
                );

                update_option( 'shop_catalog_image_size', $catalog );
                update_option( 'shop_single_image_size', $single );
                update_option( 'shop_thumbnail_image_size', $thumbnail );
            }

            //change the position of add to cart
            remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
            remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
            remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
            remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
            add_action('woocommerce_before_shop_loop_item', 'thebuilders_ninzio_product_thumb', 10 );
            add_action('woocommerce_after_shop_loop_item', 'thebuilders_ninzio_product_det', 10 );


            function thebuilders_ninzio_product_thumb() { ?>
                <?php 
                    global $post, $product;
                ?>
                <?php if ( $product->is_on_sale() ) : ?>
                    <?php
                    
                        $sale_price = get_post_meta( $product->id, '_price', true);
                        $regular_price = get_post_meta( $product->id, '_regular_price', true);

                        if (empty($regular_price)){ //then this is a variable product
                            $available_variations = $product->get_available_variations();
                            $variation_id=$available_variations[0]['variation_id'];
                            $variation= new WC_Product_Variation( $variation_id );
                            $regular_price = $variation ->regular_price;
                            $sale_price = $variation ->sale_price;
                        }
                        $sale = ceil(( ($regular_price - $sale_price) / $regular_price ) * 100);
                    ?>
                    <?php if ( !empty( $regular_price ) && !empty( $sale_price ) && $regular_price > $sale_price ) : ?>
                        <?php echo apply_filters( 'woocommerce_sale_flash', '<span class="product-status onsale">-' . $sale . '%</span>', $post, $product ); ?>
                    <?php endif ?>
                <?php endif; ?>
                <div class="nz-thumbnail">
                    <div class="ninzio-overlay">
                        <span class="nz-overlay-before"></span>
                    </div>
                    <?php echo woocommerce_get_product_thumbnail();?>
                </div>
                <div class="product-details">
            <?php }

            function thebuilders_ninzio_product_det() { ?>
                    <div class="cart-wrap nz-clearfix">
                        <?php woocommerce_template_loop_add_to_cart(); ?>
                        <div class="shop-loader">
                        </div>
                    </div>
                </div>
            <?php }

            //change the product-category structure
            add_action('woocommerce_before_subcategory_title', 'thebuilders_ninzio_procut_cat_thumb_start', 5 );
            add_action('woocommerce_before_subcategory_title', 'thebuilders_ninzio_procut_cat_thumb_end', 10 );
            add_action('woocommerce_after_subcategory_title', 'thebuilders_ninzio_procut_cat_thumb_end2', 10 );

            function thebuilders_ninzio_procut_cat_thumb_start() { ?>
                <div class="nz-thumbnail">
                    <div class="ninzio-overlay">
                        <span class="nz-overlay-before portfolio-link"></span>
                    </div>
            <?php 
            }

            function thebuilders_ninzio_procut_cat_thumb_end() { ?>
                </div>
                <div class="category-details">
            <?php 
            }

            function thebuilders_ninzio_procut_cat_thumb_end2() { ?>
                </div>
            <?php 
            }


            // Remove shop title
            add_filter( 'woocommerce_show_page_title' , 'thebuilders_ninzio_hide_page_title' );
            function thebuilders_ninzio_hide_page_title() {return false;}

            // Remove woocommerce breadcrumbs
            remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);

            // Ensure cart contents update when products are added to the cart via AJAX
            add_filter('add_to_cart_fragments', 'thebuilders_ninzio_add_to_cart');
            function thebuilders_ninzio_add_to_cart( $fragments ) {
                
                global $woocommerce;

                ob_start(); ?>
                <a class="cart-contents" href="<?php echo esc_url($GLOBALS['woocommerce']->cart->get_cart_url()); ?>" title="<?php echo esc_html__('View your shopping cart', 'thebuilders'); ?>">
                    <span class="cart-info"><?php echo esc_attr($GLOBALS['woocommerce']->cart->cart_contents_count); ?></span>
                    <span class="cart-info-2"><span class="my-cart"><?php echo esc_html__("My cart", 'thebuilders'); ?></span><span class="my-items"><?php echo sprintf(_n('%d item', '%d items', esc_attr($GLOBALS['woocommerce']->cart->cart_contents_count), 'thebuilders'), esc_attr($GLOBALS['woocommerce']->cart->cart_contents_count)); ?></span> / <?php echo $GLOBALS['woocommerce']->cart->get_cart_total(); ?></span>
                </a>
                <?php

                $fragments['a.cart-contents'] = ob_get_clean();
                return $fragments;

            }

            add_filter( 'woocommerce_single_product_image_html', 'thebuilders_ninzio_woocommerce_single_product_image_html', 10, 2 );
            function thebuilders_ninzio_woocommerce_single_product_image_html( $html, $post_id ) {
                global $post, $product, $woocommerce;

                $attachment_ids = $product->get_gallery_attachment_ids();
            ?>
                <div id="single-product-slider" class="slider flexslider">
                    <ul class="slides">
                        <li>
                        <?php if ( has_post_thumbnail() ): ?>
                            <?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
                            <div class="ninzio-zoom" data-zoom-image="<?php echo esc_url($large_image_url[0]); ?>">
                                <?php echo get_the_post_thumbnail($post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' )) ?>
                            </div>
                        <?php endif; ?>
                        </li>
                        <?php if ($attachment_ids): ?>
                            <?php foreach ( $attachment_ids as $attachment_id ) { ?>
                                <li>
                                    <?php $large_image_url2 = wp_get_attachment_image_src( $attachment_id, 'full' ); ?>
                                    <div class="ninzio-zoom" data-zoom-image="<?php echo esc_url($large_image_url2[0]); ?>">
                                        <?php echo wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' )); ?>
                                    </div>
                                </li>
                            <?php } ?>
                        <?php endif ?>
                    </ul>
                </div>
                <?php if ($attachment_ids): ?>
                    <div id="single-product-carousel" class="carousel flexslider">
                        <ul class="slides">
                            
                                <li>
                                    <?php if ( has_post_thumbnail() ): ?>
                                        <?php echo get_the_post_thumbnail($post->ID, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' )) ?>
                                    <?php endif; ?>
                                </li>
                                <?php foreach ( $attachment_ids as $attachment_id ){ ?>
                                    <li>
                                        <?php echo wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' )); ?>
                                    </li>
                                <?php } ?>
                        </ul>
                    </div>
                <?php endif ?>
            <?php }

            add_filter( 'woocommerce_single_product_image_thumbnail_html', 'thebuilders_ninzio_woocommerce_single_product_image_thumbnail_html', 10, 2 );
            function thebuilders_ninzio_woocommerce_single_product_image_thumbnail_html( $html, $post_id ) {
                return false;
            }

            //wrap single product image in column div
            remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
            add_action( 'woocommerce_before_single_product_summary', 'thebuilders_ninzio_column_open_div', 2);
            add_action( 'woocommerce_before_single_product_summary', 'thebuilders_ninzio_column_close_div', 20);
            add_action( 'woocommerce_after_single_product_summary',  'thebuilders_ninzio_clearfix_div', 2);

            function thebuilders_ninzio_column_open_div(){  ?>
      
                <div class="single-image-content nz-clearfix">
                <div class='single-product-image'>

                    <?php global $product,$post; if ( $product->is_on_sale() ) : ?>
                        <?php
                        
                            $sale_price = get_post_meta( $product->id, '_price', true);
                            $regular_price = get_post_meta( $product->id, '_regular_price', true);

                            if (empty($regular_price)){ //then this is a variable product
                                $available_variations = $product->get_available_variations();
                                $variation_id=$available_variations[0]['variation_id'];
                                $variation= new WC_Product_Variation( $variation_id );
                                $regular_price = $variation ->regular_price;
                                $sale_price = $variation ->sale_price;
                            }
                            $sale = ceil(( ($regular_price - $sale_price) / $regular_price ) * 100);
                        ?>
                        <?php if ( !empty( $regular_price ) && !empty( $sale_price ) && $regular_price > $sale_price ) : ?>
                            <?php echo apply_filters( 'woocommerce_sale_flash', '<span class="product-status onsale">-' . $sale . '%</span>', $post, $product ); ?>
                        <?php endif ?>
                    <?php endif; ?>
            <?php }
            function thebuilders_ninzio_column_close_div(){
                echo "</div><div class='single-product-summary'>"; ?>
            <?php }
            function thebuilders_ninzio_clearfix_div(){ ?>
                </div>
                </div>
            <?php }

            function thebuilders_ninzio_social_share( $content ) { 
                global $post;
            ?>
                <?php if ($post->post_excerpt): ?>
                    <div class="description"><?php echo esc_attr($post->post_excerpt); ?></div>
                <?php endif ?>
                <?php if (is_single()): ?>
                    <div class="post-social-share nz-clearfix">
                        <span><?php echo esc_html__("Share", 'thebuilders'); ?></span>
                        <div class="social-links left nz-clearfix">
                            <a title="<?php echo esc_html__("Share on Facebook", 'thebuilders'); ?>" class="post-facebook-share icon-facebook" target="_blank" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php the_title(); ?>"><span class="social-share-text"></span></a>
                            <a title="<?php echo esc_html__("Tweet this!", 'thebuilders'); ?>" class="post-twitter-share icon-twitter" target="_blank" href="http://twitter.com/home/?status=<?php the_title(); ?> - <?php the_permalink(); ?>"><span class="social-share-text"></span></a>
                            <a title="<?php echo esc_html__("Share on Pinterest", 'thebuilders'); ?>" class="post-pinterest-share icon-pinterest" target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo esc_url($url); ?>"><span class="social-share-text"></span></a>
                            <a title="<?php echo esc_html__("Share on LinkedIn", 'thebuilders'); ?>" class="post-linkedin-share icon-linkedin" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;title=<?php the_title(); ?>&amp;url=<?php the_permalink(); ?>"><span class="social-share-text"></span></a>
                            <a title="<?php echo esc_html__("Share on Google+", 'thebuilders'); ?>" class="post-google-share icon-googleplus" target="_blank" href="https://plus.google.com/share?url=<?php the_permalink(); ?>" onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><span class="social-share-text"></span></a>
                        </div>
                    </div>
                <?php endif ?>
            <?php }
            add_filter('woocommerce_short_description', 'thebuilders_ninzio_social_share', 10, 2);
                
            function thebuilders_ninzio_remove_pretty_photo(){
                wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
                wp_dequeue_style( 'woocommerce_chosen_styles' );
                wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
                wp_dequeue_script( 'prettyPhoto-init' );
                wp_dequeue_script( 'prettyPhoto' );
                wp_dequeue_script( 'wc-chosen' );
            }
            
            add_action( 'wp_enqueue_scripts', 'thebuilders_ninzio_remove_pretty_photo', 99 );

            if (isset($GLOBALS['thebuilders_ninzio']['shop-rp']) && $GLOBALS['thebuilders_ninzio']['shop-rp'] == 0) {
                // remove related products
                remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
            }

            // related products number
            function thebuilders_ninzio_remove_related_products( $args ) {
                return array();
            }
            add_filter('woocommerce_related_products_args','thebuilders_ninzio_remove_related_products', 10);
            
            add_theme_support( 'woocommerce' );

            add_filter( 'woocommerce_enqueue_styles', '__return_false' );

        }

    /*  Visual Composer
    /*-------------------*/

        if(function_exists('vc_set_as_theme')) vc_set_as_theme();

    /*  Title Tag
    /*-------------------*/

        add_action( 'after_setup_theme', 'thebuilders_ninzio_theme_slug_setup' );
        function thebuilders_ninzio_theme_slug_setup() {
            add_theme_support( 'title-tag' );
        }

    /*  Redux
    /*-------------------*/

        function thebuilders_ninzio_remove_redux_news() {
            remove_meta_box( 'redux_dashboard_widget', 'dashboard', 'side' );
        } 
        add_action('wp_dashboard_setup', 'thebuilders_ninzio_remove_redux_news' );

        function thebuilders_ninzio_redux_menu_page_removing() {
            remove_submenu_page( 'tools.php', 'redux-about' );
        }
        add_action( 'admin_menu', 'thebuilders_ninzio_redux_menu_page_removing' );

/*  SCRIPTS
/*======================*/

    function thebuilders_ninzio_script()
    {
        if(!is_admin())
        {
            global $thebuilders_ninzio;

            wp_enqueue_style( 'icomoon', THEBUILDERS_NINZIO_TEMPPATH . '/css/icomoon.css');
            wp_enqueue_style( 'header-im', THEBUILDERS_NINZIO_TEMPPATH . '/css/header-im.css');
            wp_enqueue_style( 'thebuilders-style', get_stylesheet_uri() );

            if ( is_singular() && get_option( 'thread_comments' ) ) {
                wp_enqueue_script( 'comment-reply' );
            }

            if (isset($GLOBALS['thebuilders_ninzio']['google-map-api']) && !empty($GLOBALS['thebuilders_ninzio']['google-map-api'])) {
                wp_enqueue_script( 'gmap', '//maps.google.com/maps/api/js?key='.$GLOBALS['thebuilders_ninzio']['google-map-api'], array(), false);
            } else {
                wp_enqueue_script( 'gmap', '//maps.google.com/maps/api/js', array(), false);
            }
            wp_enqueue_script( 'modernizr', THEBUILDERS_NINZIO_TEMPPATH . '/js/modernizr.js', array(), false);
            wp_enqueue_script( 'masonry', THEBUILDERS_NINZIO_TEMPPATH . '/js/masonry.pkgd.min.js', array('jquery'), '', true);
            wp_enqueue_script( 'shuffle', THEBUILDERS_NINZIO_TEMPPATH . '/js/jquery.shuffle.js', array('jquery'), '', true);
            wp_enqueue_script( 'elevateZoom', THEBUILDERS_NINZIO_TEMPPATH . '/js/elevateZoom.js', array('jquery'), '', true);
            wp_enqueue_script( 'controller', THEBUILDERS_NINZIO_TEMPPATH . '/js/controller.js', array('jquery'), '', true);
        

            if (is_page()) {


                $values          = get_post_custom( get_the_ID() );
                $one_page        = (isset($values["one_page"][0]) && $values["one_page"][0] == "true") ? "true" : "false";

                if ($one_page == "true") {
                   
                    $nz_one_page_speed  = ($thebuilders_ninzio['one-page-speed']) ? esc_js($thebuilders_ninzio['one-page-speed']) : 750;
                    $nz_one_page_hash   = ($thebuilders_ninzio['one-page-hash'] && $thebuilders_ninzio['one-page-hash'] == 1) ? 'true' : 'false';
                    $nz_one_page_nav    = ($thebuilders_ninzio['one-page-navigation']) ? $thebuilders_ninzio['one-page-navigation'] : 'side';
                    $nz_one_page_filter = (isset($thebuilders_ninzio['one-page-filter']) && $thebuilders_ninzio['one-page-filter']) ? explode(',',esc_attr($thebuilders_ninzio['one-page-filter'])) : '';
                    $nz_filter_array    = array();

                    $nz_offset = 0;

                    $nz_header_version  = (isset($GLOBALS['thebuilders_ninzio']['header-version']) && !empty($GLOBALS['thebuilders_ninzio']['header-version'])) ? $GLOBALS['thebuilders_ninzio']['header-version'] : 'version1';
                    $nz_h1_fixed_height = (isset($GLOBALS['thebuilders_ninzio']['h1-fixed-height']) && $GLOBALS['thebuilders_ninzio']['h1-fixed-height']) ? $GLOBALS['thebuilders_ninzio']['h1-fixed-height'] : "90";
                    $nz_h2_fixed_height = (isset($GLOBALS['thebuilders_ninzio']['h2-fixed-height']) && $GLOBALS['thebuilders_ninzio']['h2-fixed-height']) ? $GLOBALS['thebuilders_ninzio']['h2-fixed-height'] : "90";
                    $nz_h3_fixed_height = (isset($GLOBALS['thebuilders_ninzio']['h3-fixed-height']) && $GLOBALS['thebuilders_ninzio']['h3-fixed-height']) ? $GLOBALS['thebuilders_ninzio']['h3-fixed-height'] : "90";
                    $nz_h4_fixed_height = (isset($GLOBALS['thebuilders_ninzio']['h4-fixed-height']) && $GLOBALS['thebuilders_ninzio']['h4-fixed-height']) ? $GLOBALS['thebuilders_ninzio']['h4-fixed-height'] : "90";
                    $nz_h5_fixed_height = (isset($GLOBALS['thebuilders_ninzio']['h5-fixed-height']) && $GLOBALS['thebuilders_ninzio']['h5-fixed-height']) ? $GLOBALS['thebuilders_ninzio']['h5-fixed-height'] : "90";

                    $nz_h1_fixed = (isset($GLOBALS['thebuilders_ninzio']['h1-fixed']) && $GLOBALS['thebuilders_ninzio']['h1-fixed'] == 1) ? "true" : "false";
                    $nz_h2_fixed = (isset($GLOBALS['thebuilders_ninzio']['h2-fixed']) && $GLOBALS['thebuilders_ninzio']['h2-fixed'] == 1) ? "true" : "false";
                    $nz_h3_fixed = (isset($GLOBALS['thebuilders_ninzio']['h3-fixed']) && $GLOBALS['thebuilders_ninzio']['h3-fixed'] == 1) ? "true" : "false";
                    $nz_h4_fixed = (isset($GLOBALS['thebuilders_ninzio']['h4-fixed']) && $GLOBALS['thebuilders_ninzio']['h4-fixed'] == 1) ? "true" : "false";
                    $nz_h5_fixed = (isset($GLOBALS['thebuilders_ninzio']['h5-fixed']) && $GLOBALS['thebuilders_ninzio']['h5-fixed'] == 1) ? "true" : "false";

                    $nz_h1_header_top = (isset($GLOBALS['thebuilders_ninzio']['h1-header-top']) && $GLOBALS['thebuilders_ninzio']['h1-header-top'] == 1) ? "true" : "false";
                    $nz_h2_header_top = (isset($GLOBALS['thebuilders_ninzio']['h2-header-top']) && $GLOBALS['thebuilders_ninzio']['h2-header-top'] == 1) ? "true" : "false";
                    $nz_h5_header_top = (isset($GLOBALS['thebuilders_ninzio']['h5-header-top']) && $GLOBALS['thebuilders_ninzio']['h5-header-top'] == 1) ? "true" : "false";

                    switch ($nz_header_version) {
                        case 'version1':
                            $nz_offset = ($nz_h1_fixed == "true") ? ($nz_h1_header_top) ? ($nz_h1_fixed_height + 40) : $nz_h1_fixed_height : 0;
                            break;
                        case 'version2':
                            $nz_offset = ($nz_h2_fixed == "true") ? ($nz_h2_header_top) ? ($nz_h2_fixed_height + 40) : $nz_h2_fixed_height : 0;
                            break;
                        case 'version3':
                            $nz_offset = ($nz_h3_fixed == "true") ? $nz_h3_fixed_height : 0;
                            break;
                        case 'version4':
                            $nz_offset = ($nz_h4_fixed == "true") ? ($nz_h4_fixed_height + 40) : 0;
                            break;
                        case 'version5':
                            $nz_offset = ($nz_h5_fixed == "true") ? ($nz_h5_header_top) ? ($nz_h5_fixed_height + 40) : $nz_h5_fixed_height : 0;
                            break;
                    }

                    if (is_array($nz_one_page_filter)) {
                        foreach ($nz_one_page_filter as $filter) {
                            array_push($nz_filter_array, '#menu-item-'.$filter.' > a');
                        }
                    }

                    wp_enqueue_script( 'single-page-nav', THEBUILDERS_NINZIO_TEMPPATH.'/js/single-page-nav.js', array('jquery'), '', true);
                    wp_localize_script( 
                        'single-page-nav', 
                        'single_page_nav_opt', 
                        array(
                            'offset'      => $nz_offset,
                            'from'        => $nz_from,
                        )
                    );
                    wp_enqueue_script( 'thebuilders-one-page', THEBUILDERS_NINZIO_TEMPPATH.'/js/thebuilders-one-page.js', array('jquery'), '', true);
                    wp_localize_script( 
                        'thebuilders-one-page', 
                        'thebuilders_one_page_opt', 
                        array(
                            'navType'     => $nz_one_page_nav, 
                            'offset'      => $nz_offset,
                            'from'        => $nz_from,
                            'speed'       => $nz_one_page_speed,
                            'hash'        => $nz_one_page_hash,
                            'filterArray' => (!empty($nz_filter_array)) ? implode(', ', $nz_filter_array) : ''
                        )
                    );

                }
            }
        }

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

/* ADMIN STYLES/SCRIPTS
/*======================*/

    function thebuilders_admin_scripts_styles() {
        wp_enqueue_script( 'ninzio-admin', THEBUILDERS_NINZIO_TEMPPATH . '/js/admin-scripts.js', array('jquery'), '', true);
        wp_enqueue_style( 'admin-styles', THEBUILDERS_NINZIO_TEMPPATH . '/css/admin-styles.css', array(), '', 'all' );
        wp_enqueue_style( 'jquery-ui', THEBUILDERS_NINZIO_TEMPPATH . '/css/jquery-ui.css', array(), '', 'all' );
        wp_enqueue_style( 'wp-color-picker' );
        wp_enqueue_script( 'wp-color-picker' );
        wp_enqueue_script( 'jquery-ui-spinner' );
        wp_enqueue_script( 'jquery-ui-sortable' );
        wp_enqueue_script('jquery-ui-datepicker');
        wp_enqueue_style( 'thickbox' );
        wp_enqueue_script( 'thickbox' );
        wp_enqueue_media();

        return;
    }
    add_action('admin_enqueue_scripts','thebuilders_admin_scripts_styles');

?>