<?php
if ( ! function_exists( 'dxstore_lite_setup' ) ) :
function dxstore_lite_setup() {
	load_theme_textdomain( 'dxstore', get_template_directory() . '/languages' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'post-thumbnails' );
	register_nav_menus( array(
		'primary' => esc_html__( 'Primary', 'dxstore' ),
	) );
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );
	add_theme_support( 'post-formats', array(
		'aside',
		'image',
		'video',
		'quote',
		'link',
	) );
	add_theme_support( 'custom-background', apply_filters( 'dxstore_lite_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );
}
endif;
add_action( 'after_setup_theme', 'dxstore_lite_setup' );

function dxstore_lite_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'dxstore_lite_content_width', 640 );
}
add_action( 'after_setup_theme', 'dxstore_lite_content_width', 0 );
function dxstore_lite_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Left', 'dxstore' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Header', 'dxstore' ),
		'id'            => 'sidebar-2',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer 1', 'dxstore' ),
		'id'            => 'sidebar-3',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer 2', 'dxstore' ),
		'id'            => 'sidebar-4',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer 3', 'dxstore' ),
		'id'            => 'sidebar-5',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer 4', 'dxstore' ),
		'id'            => 'sidebar-6',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Demo1', 'dxstore' ),
		'id'            => 'sidebar-9',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Demo2', 'dxstore' ),
		'id'            => 'sidebar-10',
		'description'   => esc_html__( 'Add widgets here.', 'dxstore' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
}
add_action( 'widgets_init', 'dxstore_lite_widgets_init' );








// Add Menu and Bootstrap

function register_my_menu() {
  register_nav_menu('header-menu',__( 'Header Menu', 'dxstore-lite' ));
}
add_action( 'init', 'register_my_menu' );





function dxstore_lite_scripts() {
		wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css', array( ), false, 'all' );
		wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap-theme.css', array( ), false, 'all' );
		wp_enqueue_script('jquery');
		wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array( ), false, 'all' );
		wp_enqueue_style( 'dxstore-style', get_stylesheet_uri() );
		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'dxstore_lite_scripts' );


require get_template_directory() . '/inc/template-tags.php';
add_action( 'after_setup_theme', 'dxstore_lite_woocommerce_support' );
function dxstore_lite_woocommerce_support() {
    add_theme_support( 'woocommerce' );
}

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );
function woocommerce_output_related_products() {
    $args = array('posts_per_page' => 4, 'columns' => 4,'orderby' => 'rand' );
    woocommerce_related_products( apply_filters( 'woocommerce_output_related_products_args', $args ) );}



add_filter('add_to_cart_fragments', 'dxstore_lite_fragment');
function dxstore_fragment( $fragments ) {
    global $woocommerce;
    ob_start(); ?>
    <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'dxstore'); ?>"> <?php echo $woocommerce->cart->get_cart_total(); ?></a>
    <?php
    $fragments['a.cart-contents'] = ob_get_clean();
    return $fragments;
}


add_action( 'after_setup_theme', 'dxstore' );
 
function dxstore() {
    add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support( 'wc-product-gallery-lightbox' );
    add_theme_support( 'wc-product-gallery-slider' );
}


function dxstore_lite_menu() {
	add_theme_page('DxStore Lite Setup', 'Menu - Help', 'edit_theme_options', 'dxstore-lite', 'dxstore_lite_menu_page');
}
add_action('admin_menu', 'dxstore_lite_menu');
function dxstore_lite_menu_page() {
echo '
<br>
<center><h1 style="font-size:79px;">' . __( 'DxStore Lite', 'dxstore-lite' ) . '</h1></ceter>
<br><br><br>
	<center><h1>' . __( 'Max Mega Menu', 'dxstore-lite' ) . '</h1></ceter>
<br>
Installation:<br>
1. Go to the Plugins Menu in WordPress<br>
2. Search for "Max Mega Menu"<br>
3. Click "Install"<br><br>
<h2><center>' . __( 'Documentation', 'dxstore-lite' ) . '  <a href="https://www.megamenu.com/documentation/mega-menus/">' . __( 'https://www.megamenu.com/documentation/mega-menus/', 'dxstore-lite' ) . '</a></center></h2><br><br>
<center><img src="' . get_template_directory_uri() . '/images/max-mega-menu-1.jpg"></center>
<br><br>
<center><img src="' . get_template_directory_uri() . '/images/max-mega-menu-2.jpg"></center>
<br><br>
<center><img src="' . get_template_directory_uri() . '/images/max-mega-menu-3.jpg"></center>
<br><br>
<center><img src="' . get_template_directory_uri() . '/images/max-mega-menu-4.jpg"></center>
<br>
';
}