<div class="theme-offer">
	<?php
        // Check if the demo import has been completed
        $electronics_marketplace_demo_import_completed = get_option('electronics_marketplace_demo_import_completed', false);

        // If the demo import is completed, display the "View Site" button
        if ($electronics_marketplace_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'electronics-marketplace') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'electronics-marketplace') . '</a></span>';
        }

		//POST and update the customizer and other related data
        if (isset($_POST['submit'])) {

            // Check if Contact Form 7 is installed and activated
            if (!is_plugin_active('woocommerce/woocommerce.php')) {
              // Install the plugin if it doesn't exist
              $electronics_marketplace_plugin_slug = 'woocommerce';
              $electronics_marketplace_plugin_file = 'woocommerce/woocommerce.php';

              // Check if plugin is installed
              $electronics_marketplace_installed_plugins = get_plugins();
              if (!isset($electronics_marketplace_installed_plugins[$electronics_marketplace_plugin_file])) {
                  include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
                  include_once(ABSPATH . 'wp-admin/includes/file.php');
                  include_once(ABSPATH . 'wp-admin/includes/misc.php');
                  include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');

                  // Install the plugin
                  $electronics_marketplace_upgrader = new Plugin_Upgrader();
                  $electronics_marketplace_upgrader->install('https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip');
              }
              // Activate the plugin
              activate_plugin($electronics_marketplace_plugin_file);
            }

            // ------- Create Nav Menu --------
            $electronics_marketplace_menuname = 'Primary Menu';
            $electronics_marketplace_bpmenulocation = 'primary';
            $electronics_marketplace_menu_exists = wp_get_nav_menu_object($electronics_marketplace_menuname);

            if (!$electronics_marketplace_menu_exists) {
                $electronics_marketplace_menu_id = wp_create_nav_menu($electronics_marketplace_menuname);

                // Create Home Page
                $electronics_marketplace_home_title = 'Home';
                $electronics_marketplace_home = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $electronics_marketplace_home_id = wp_insert_post($electronics_marketplace_home);
                // Assign Home Page Template
                add_post_meta($electronics_marketplace_home_id, '_wp_page_template', 'page-template/home-page.php');
                // Update options to set Home Page as the front page
                update_option('page_on_front', $electronics_marketplace_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'electronics-marketplace'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $electronics_marketplace_about_title = 'About Us';
                $electronics_marketplace_about_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam...<br>
                Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br>
                There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text.<br>
                All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.';
                $electronics_marketplace_about = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_about_title,
                    'post_content' => $electronics_marketplace_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $electronics_marketplace_about_id = wp_insert_post($electronics_marketplace_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'electronics-marketplace'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                // Create Mobile Page with Dummy Content
                $electronics_marketplace_mobile_title = 'Mobile';
                $electronics_marketplace_mobile_content = '
                Explore our latest mobile collection.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_mobile = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_mobile_title,
                    'post_content' => $electronics_marketplace_mobile_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'mobile'
                );
                $electronics_marketplace_mobile_id = wp_insert_post($electronics_marketplace_mobile);
                // Add Mobile Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Mobile', 'electronics-marketplace'),
                    'menu-item-classes' => 'mobile',
                    'menu-item-url' => home_url('/mobile/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_mobile_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Headphone Page with Dummy Content
                $electronics_marketplace_headphone_title = 'Headphone';
                $electronics_marketplace_headphone_content = '
                Find the best headphones here.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_headphone = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_headphone_title,
                    'post_content' => $electronics_marketplace_headphone_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'headphone'
                );
                $electronics_marketplace_headphone_id = wp_insert_post($electronics_marketplace_headphone);
                // Add Headphone Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Headphone', 'electronics-marketplace'),
                    'menu-item-classes' => 'headphone',
                    'menu-item-url' => home_url('/headphone/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_headphone_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Clothes Page with Dummy Content
                $electronics_marketplace_clothes_title = 'Clothes';
                $electronics_marketplace_clothes_content = '
                Browse our clothing collection.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_clothes = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_clothes_title,
                    'post_content' => $electronics_marketplace_clothes_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'clothes'
                );
                $electronics_marketplace_clothes_id = wp_insert_post($electronics_marketplace_clothes);
                // Add Clothes Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Clothes', 'electronics-marketplace'),
                    'menu-item-classes' => 'clothes',
                    'menu-item-url' => home_url('/clothes/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_clothes_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
            // Create Shoes Page with Dummy Content
                $electronics_marketplace_shoes_title = 'Shoes';
                $electronics_marketplace_shoes_content = 'Discover top-quality shoes.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_shoes = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_shoes_title,
                    'post_content' => $electronics_marketplace_shoes_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'shoes'
                );
                $electronics_marketplace_shoes_id = wp_insert_post($electronics_marketplace_shoes);
                // Add Shoes Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Shoes', 'electronics-marketplace'),
                    'menu-item-classes' => 'shoes',
                    'menu-item-url' => home_url('/shoes/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_shoes_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                // Create Watches Page with Dummy Content
                $electronics_marketplace_watches_title = 'Watches';
                $electronics_marketplace_watches_content = 'Explore our watch collection.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_watches = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_watches_title,
                    'post_content' => $electronics_marketplace_watches_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'watches'
                );
                $electronics_marketplace_watches_id = wp_insert_post($electronics_marketplace_watches);
                // Add Watches Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Watches', 'electronics-marketplace'),
                    'menu-item-classes' => 'watches',
                    'menu-item-url' => home_url('/watches/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_watches_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                 // Create Blog Page 
                $electronics_marketplace_blog_page_title = 'Blog';
                $electronics_marketplace_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($electronics_marketplace_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$electronics_marketplace_blog_page_query->have_posts()) {
                    $electronics_marketplace_blog_page = array(
                    'post_type'   => 'page',
                    'post_title'  => $electronics_marketplace_blog_page_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    );
                    $electronics_marketplace_blog_page_id = wp_insert_post($electronics_marketplace_blog_page);
                    update_option('page_for_posts', $electronics_marketplace_blog_page_id);
                    wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title'      => __('Blog', 'electronics-marketplace'),
                    'menu-item-url'        => get_permalink($electronics_marketplace_blog_page_id),
                    'menu-item-status'     => 'publish',
                    'menu-item-object-id'  => $electronics_marketplace_blog_page_id,
                    'menu-item-object'     => 'page',
                    'menu-item-type'       => 'post_type',
                   ));
                }

                // Create Contact Us Page with Dummy Content
                $electronics_marketplace_contact_title = 'Contact Us';
                $electronics_marketplace_contact_content = 'Get in touch with us.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_contact = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_contact_title,
                    'post_content' => $electronics_marketplace_contact_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'contact-us'
                );
                $electronics_marketplace_contact_id = wp_insert_post($electronics_marketplace_contact);
                // Add Contact Us Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_menu_id, 0, array(
                    'menu-item-title' => __('Contact Us', 'electronics-marketplace'),
                    'menu-item-classes' => 'contact-us',
                    'menu-item-url' => home_url('/contact-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_contact_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                // Set the menu location if it's not already set
                if (!has_nav_menu($electronics_marketplace_bpmenulocation)) {
                    $electronics_marketplace_locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                    if (empty($electronics_marketplace_locations)) {
                        $electronics_marketplace_locations = array();
                    }
                    $electronics_marketplace_locations[$electronics_marketplace_bpmenulocation] = $electronics_marketplace_menu_id;
                    set_theme_mod('nav_menu_locations', $electronics_marketplace_locations);
                }
            }

            // ------- Create Top Menu --------
            $electronics_marketplace_topmenuname = 'Top Menu';
            $electronics_marketplace_topbpmenulocation = 'topmenus';
            $electronics_marketplace_topmenu_exists = wp_get_nav_menu_object($electronics_marketplace_topmenuname);

            if (!$electronics_marketplace_topmenu_exists) {
                $electronics_marketplace_topmenu_id = wp_create_nav_menu($electronics_marketplace_topmenuname);

                // Create Headphone Page with Dummy Content
                $electronics_marketplace_support_title = 'Support';
                $electronics_marketplace_support_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_support = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_support_title,
                    'post_content' => $electronics_marketplace_support_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'support'
                );
                $electronics_marketplace_topsupport_id = wp_insert_post($electronics_marketplace_support);
                // Add Headphone Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_topmenu_id, 0, array(
                    'menu-item-title' => __('Support', 'electronics-marketplace'),
                    'menu-item-classes' => 'support',
                    'menu-item-url' => home_url('/support/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_topsupport_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Headphone Page with Dummy Content
                $electronics_marketplace_store_title = 'Store Locator';
                $electronics_marketplace_store_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_store = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_store_title,
                    'post_content' => $electronics_marketplace_store_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'store'
                );
                $electronics_marketplace_topstore_id = wp_insert_post($electronics_marketplace_store);
                // Add Headphone Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_topmenu_id, 0, array(
                    'menu-item-title' => __('Store Locator', 'electronics-marketplace'),
                    'menu-item-classes' => 'store',
                    'menu-item-url' => home_url('/store/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_topstore_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Headphone Page with Dummy Content
                $electronics_marketplace_free_title = 'Free Shipping';
                $electronics_marketplace_free_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
                $electronics_marketplace_free = array(
                    'post_type' => 'page',
                    'post_title' => $electronics_marketplace_free_title,
                    'post_content' => $electronics_marketplace_free_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'free'
                );
                $electronics_marketplace_topfree_id = wp_insert_post($electronics_marketplace_free);
                // Add Headphone Page to Menu
                wp_update_nav_menu_item($electronics_marketplace_topmenu_id, 0, array(
                    'menu-item-title' => __('Free Shipping', 'electronics-marketplace'),
                    'menu-item-classes' => 'free',
                    'menu-item-url' => home_url('/free/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $electronics_marketplace_topfree_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));


                // Set the menu location if it's not already set
                if (!has_nav_menu($electronics_marketplace_topbpmenulocation)) {
                    $electronics_marketplace_locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                    if (empty($electronics_marketplace_locations)) {
                        $electronics_marketplace_locations = array();
                    }
                    $electronics_marketplace_locations[$electronics_marketplace_topbpmenulocation] = $electronics_marketplace_topmenu_id;
                    set_theme_mod('nav_menu_locations', $electronics_marketplace_locations);
                }
            }

            // Set the demo import completion flag
    		update_option('electronics_marketplace_demo_import_completed', true);
    		// Display success message and "View Site" button
    		echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'electronics-marketplace') . '</p>';
    		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'electronics-marketplace') . '</a></span>';
            //end

            // Top Bar //
            set_theme_mod( 'ecommerce_solution_phone_number', '+123-456-7890' );

            // slider section start //
            set_theme_mod( 'ecommerce_solution_slider_hide', true );
            set_theme_mod( 'ecommerce_solution_slider_button_text', 'READ MORE' );
            set_theme_mod( 'ecommerce_solution_topbar_btn_link', '#' );

            $ecommerce_solution_slider_titles = array(
                'Build Your Online Store with Ease', 
                'Seamless Shopping Experience for Customers', 
                'Boost Sales with a Powerful E-Commerce Platform', 
                'Sell Anything, Anywhere with Flexible Solutions'
            );                    
            for ($ecommerce_solution_i = 0; $ecommerce_solution_i < 4; $ecommerce_solution_i++) {
                // Get the slider title and content
                $ecommerce_solution_slider_title = $ecommerce_solution_slider_titles[$ecommerce_solution_i];
                $ecommerce_solution_slider_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s.';
            
                // Create post object
                $ecommerce_solution_my_post = array(
                    'post_title'    => wp_strip_all_tags($ecommerce_solution_slider_title),
                    'post_content'  => $ecommerce_solution_slider_content,
                    'post_status'   => 'publish',
                    'post_type'     => 'page',
                );
            
                // Insert the post into the database
                $ecommerce_solution_post_id = wp_insert_post($ecommerce_solution_my_post);
            
                if ($ecommerce_solution_post_id) {
                    // Set the theme mod for the slider page
                    set_theme_mod('ecommerce_solution_slider_setting' . ($ecommerce_solution_i + 1), $ecommerce_solution_post_id);
            
                    // Set the slider image URL for each index
                    $ecommerce_solution_image_url = get_theme_file_uri() . '/images/slider' . ($ecommerce_solution_i + 1) . '.png';
            
                    // Download the image and set it as the featured image
                    $ecommerce_solution_image_id = media_sideload_image($ecommerce_solution_image_url, $ecommerce_solution_post_id, null, 'id');
            
                    if (!is_wp_error($ecommerce_solution_image_id)) {
                        // Set the downloaded image as the post's featured image
                        set_post_thumbnail($ecommerce_solution_post_id, $ecommerce_solution_image_id);
                    }
                }
            }

            // new collection
            set_theme_mod('ecommerce_solution_show_new_collection_section', true );
            set_theme_mod('ecommerce_solution_bestseller_section_title', 'Shop New Collection' );
            $ecommerce_solution_title_array = array(
                "Product Title 1",
                "Product Title 2",
                "Product Title 3",
                "Product Title 4",
            );
            
            for ($ecommerce_solution_i = 0; $ecommerce_solution_i < 4; $ecommerce_solution_i++) {
                // Create product content
                $ecommerce_solution_title = $ecommerce_solution_title_array[$ecommerce_solution_i];
                $ecommerce_solution_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s...';
            
                // Create product post object
                $ecommerce_solution_my_post = array(
                    'post_title'    => wp_strip_all_tags($ecommerce_solution_title),
                    'post_content'  => $ecommerce_solution_content,
                    'post_status'   => 'publish',
                    'post_type'     => 'product', // Post type set to 'product'
                );
                // Insert the product into the database
                $ecommerce_solution_post_id = wp_insert_post($ecommerce_solution_my_post);
                if (is_wp_error($ecommerce_solution_post_id)) {
                    error_log('Error creating product: ' . $ecommerce_solution_post_id->get_error_message());
                    continue; // Skip to the next product if creation fails
                }
            
                // Assign product to the 'Uncategorized' category
                wp_set_object_terms($ecommerce_solution_post_id, 'uncategorized', 'product_cat');
            
                // Store the product ID in the theme mod settings
                set_theme_mod('ecommerce_solution_product_setting_' . $ecommerce_solution_i, $ecommerce_solution_post_id);
                update_post_meta($ecommerce_solution_post_id, '_regular_price', '50'); // Regular price
                update_post_meta($ecommerce_solution_post_id, '_sale_price', '49.99'); // Sale price
                update_post_meta($ecommerce_solution_post_id, '_price', '49.99'); // Active price
            
                // Handle the featured image using media_sideload_image
                $ecommerce_solution_image_url = get_template_directory_uri() . '/images/product' . ($ecommerce_solution_i + 1) . '.png';
                $ecommerce_solution_image_id = media_sideload_image($ecommerce_solution_image_url, $ecommerce_solution_post_id, null, 'id');
            
                if (is_wp_error($ecommerce_solution_image_id)) {
                    error_log('Error downloading image: ' . $ecommerce_solution_image_id->get_error_message());
                    continue; // Skip to the next product if image download fails
                }
                // Assign featured image to product
                set_post_thumbnail($ecommerce_solution_post_id, $ecommerce_solution_image_id);
            }
            
            $ecommerce_solution_page_query = new WP_Query(array(
                'post_type' => 'page',
                'title' => 'Products',
                'post_status' => 'publish',
                'posts_per_page' => 1
            ));
            
            if (!$ecommerce_solution_page_query->have_posts()) {
                $ecommerce_solution_page_title = 'SHOP NEW COLLECTION';
                $ecommerce_solution_productpage = '[products limit="4" columns="4"]';
            
                // Append the WooCommerce products shortcode to the content
                $ecommerce_solution_content = '';
                $ecommerce_solution_content .= do_shortcode($ecommerce_solution_productpage);
            
                // Create the new page
                $ecommerce_solution_page = array(
                    'post_type'    => 'page',
                    'post_title'   => $ecommerce_solution_page_title,
                    'post_content' => $ecommerce_solution_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'products'
                );
                // Insert the page and get its ID
                $ecommerce_solution_page_id = wp_insert_post($ecommerce_solution_page);
            
                // Store the page URL and ID in theme mod
                if (!is_wp_error($ecommerce_solution_page_id)) {
                    $ecommerce_solution_page_url = get_permalink($ecommerce_solution_page_id);
                    set_theme_mod('ecommerce_solution_product_settings', $ecommerce_solution_page_id); // Store ID instead of URL
                }
            }        

            //Copyright Text
            set_theme_mod( 'ecommerce_solution_footer_text', 'By Buywptemplate' );
        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=electronics-marketplace-guide-page" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('electronics_marketplace_demo_import_completed')) : ?>
        <div class="demo-btn">
        <h3><?php esc_html_e( 'Click the below run importer button to import demo content', 'electronics-marketplace' ); ?></h3>
        <form method="post">
            <input class= "run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer','electronics-marketplace'); ?>" class="button button-primary button-large">
        </form>
        </div>
    <?php endif; ?>
    </form>
	<script type="text/javascript">
		function validate(valid) {
			if ( confirm("Do you really want to import the theme demo content?")) {
                // Show loader
                document.getElementById('demo-import-loader').style.display = 'block';
                
                // Submit form
                document.forms[0].submit();
            } else {
                return false;
            }
		}
	</script>
</div>
