' . esc_html__('Your demo import has been completed successfully.', 'advance-ecommerce-store') . '
'; echo '' . esc_html__('VIEW SITE', 'advance-ecommerce-store') . ''; //end // Slider set_theme_mod( 'advance_ecommerce_store_slider_small_title', 'LOREM IPSUM' ); for($advance_ecommerce_store_i=1;$advance_ecommerce_store_i<=4;$advance_ecommerce_store_i++){ $advance_ecommerce_store_slider_title = 'LOREM IPSUM IS SIMPLY'; $advance_ecommerce_store_slider_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam laoreet purus placerat leo egestas, sit amet tempus nibh tempus.'; // Create post object $advance_ecommerce_store_my_post = array( 'post_title' => wp_strip_all_tags( $advance_ecommerce_store_slider_title ), 'post_content' => $advance_ecommerce_store_slider_content, 'post_status' => 'publish', 'post_type' => 'page', ); // Insert the post into the database $advance_ecommerce_store_post_id = wp_insert_post( $advance_ecommerce_store_my_post ); if ($advance_ecommerce_store_post_id) { // Set the theme mod for the slider page set_theme_mod('advance_ecommerce_store_slider_page' . $advance_ecommerce_store_i, $advance_ecommerce_store_post_id); $advance_ecommerce_store_image_url = get_template_directory_uri().'/images/slider'.$advance_ecommerce_store_i.'.png'; $advance_ecommerce_store_image_id = media_sideload_image($advance_ecommerce_store_image_url, $advance_ecommerce_store_post_id, null, 'id'); if (!is_wp_error($advance_ecommerce_store_image_id)) { // Set the downloaded image as the post's featured image set_post_thumbnail($advance_ecommerce_store_post_id, $advance_ecommerce_store_image_id); } } } // Products Service set_theme_mod( 'advance_ecommerce_store_product_service', 'category1' ); // Define post category names and post titles $advance_ecommerce_store_category_names = array('category1', 'category2', 'category3'); $advance_ecommerce_store_title_array = array( array("MONEY BACK", "FREE SHIPPING", "SPECIAL SALE"), array("MONEY BACK", "FREE SHIPPING", "SPECIAL SALE"), array("MONEY BACK", "FREE SHIPPING", "SPECIAL SALE") ); foreach ($advance_ecommerce_store_category_names as $advance_ecommerce_store_index => $advance_ecommerce_store_category_name) { // Create or retrieve the post category term ID $advance_ecommerce_store_term = term_exists($advance_ecommerce_store_category_name, 'category'); if ($advance_ecommerce_store_term === 0 || $advance_ecommerce_store_term === null) { // If the term does not exist, create it $advance_ecommerce_store_term = wp_insert_term($advance_ecommerce_store_category_name, 'category'); } if (is_wp_error($advance_ecommerce_store_term)) { error_log('Error creating category: ' . $advance_ecommerce_store_term->get_error_message()); continue; // Skip to the next iteration if category creation fails } for ($advance_ecommerce_store_i = 0; $advance_ecommerce_store_i < 3; $advance_ecommerce_store_i++) { // Create post content $advance_ecommerce_store_title = $advance_ecommerce_store_title_array[$advance_ecommerce_store_index][$advance_ecommerce_store_i]; $advance_ecommerce_store_content = '30 Days Money Back Guarantee'; // Create post post object $advance_ecommerce_store_my_post = array( 'post_title' => wp_strip_all_tags($advance_ecommerce_store_title), 'post_content' => $advance_ecommerce_store_content, 'post_status' => 'publish', 'post_type' => 'post', // Post type set to 'post' ); // Insert the post into the database $advance_ecommerce_store_post_id = wp_insert_post($advance_ecommerce_store_my_post); if (is_wp_error($advance_ecommerce_store_post_id)) { error_log('Error creating post: ' . $advance_ecommerce_store_post_id->get_error_message()); continue; // Skip to the next post if creation fails } // Assign the category to the post wp_set_post_categories($advance_ecommerce_store_post_id, array((int)$advance_ecommerce_store_term['term_id'])); // Handle the featured image using media_sideload_image $advance_ecommerce_store_image_url = get_template_directory_uri() . '/images/image' . ($advance_ecommerce_store_i + 1) . '.png'; $advance_ecommerce_store_image_id = media_sideload_image($advance_ecommerce_store_image_url, $advance_ecommerce_store_post_id, null, 'id'); if (is_wp_error($advance_ecommerce_store_image_id)) { error_log('Error downloading image: ' . $advance_ecommerce_store_image_id->get_error_message()); continue; // Skip to the next post if image download fails } // Assign featured image to post set_post_thumbnail($advance_ecommerce_store_post_id, $advance_ecommerce_store_image_id); } } // Define category names $advance_ecommerce_store_category_array = array( "CLOTHING", "ELECTRONICS", "SHOES", "WATCHES", "JEWELLERY", "HEALTH AND BEAUTY" ); // Define product titles (one for each category) $advance_ecommerce_store_product_titles = array( "Product Name Here", "Product Name Here", "Product Name Here", "Product Name Here", "Product Name Here", "Product Name Here" ); // Define prices for the products (one for each category) $advance_ecommerce_store_product_prices = array( 49.99, 199.99, 79.99, 149.99, 99.99, 29.99 ); // Loop to create categories and one product per category foreach ($advance_ecommerce_store_category_array as $index => $category_name) { // Create or retrieve the category term $advance_ecommerce_store_category = term_exists($category_name, 'product_cat'); if ($advance_ecommerce_store_category === 0 || $advance_ecommerce_store_category === null) { $advance_ecommerce_store_category = wp_insert_term($category_name, 'product_cat'); } if (is_wp_error($advance_ecommerce_store_category)) { error_log('Error creating category: ' . $advance_ecommerce_store_category->get_error_message()); continue; // Skip to the next category if creation fails } // Get the term ID of the category $advance_ecommerce_store_category_id = (int) $advance_ecommerce_store_category['term_id']; // Create the product associated with this category $advance_ecommerce_store_product_title = $advance_ecommerce_store_product_titles[$index]; $advance_ecommerce_store_my_post = array( 'post_title' => wp_strip_all_tags($advance_ecommerce_store_product_title), 'post_content' => 'This is a sample product description for ' . $category_name, 'post_status' => 'publish', 'post_type' => 'product', ); // Insert the product into the database $advance_ecommerce_store_post_id = wp_insert_post($advance_ecommerce_store_my_post); if (is_wp_error($advance_ecommerce_store_post_id)) { error_log('Error creating product: ' . $advance_ecommerce_store_post_id->get_error_message()); continue; // Skip to the next product if creation fails } wp_set_object_terms($advance_ecommerce_store_post_id, $advance_ecommerce_store_category_id, 'product_cat'); $advance_ecommerce_store_image_url = get_template_directory_uri() . '/images/product' . ($index + 1) . '.png'; $advance_ecommerce_store_image_id = media_sideload_image($advance_ecommerce_store_image_url, $advance_ecommerce_store_post_id, null, 'id'); if (!is_wp_error($advance_ecommerce_store_image_id)) { // Assign the downloaded image as the product's featured image set_post_thumbnail($advance_ecommerce_store_post_id, $advance_ecommerce_store_image_id); } else { error_log('Error downloading image: ' . $advance_ecommerce_store_image_id->get_error_message()); } // Add price meta fields to the product $product_price = $advance_ecommerce_store_product_prices[$index]; update_post_meta($advance_ecommerce_store_post_id, '_price', $product_price); update_post_meta($advance_ecommerce_store_post_id, '_regular_price', $product_price); } // Product Page $advance_ecommerce_store_page_query = new WP_Query(array( 'post_type' => 'page', 'title' => 'Products', 'post_status' => 'publish', 'posts_per_page' => 1 )); if (!$advance_ecommerce_store_page_query->have_posts()) { $advance_ecommerce_store_page_title = 'Products'; $productpage = '[products limit="3" columns="3"]'; // Append the WooCommerce products shortcode to the content $advance_ecommerce_store_content = ''; $advance_ecommerce_store_content .= do_shortcode($productpage); // Create the new page $advance_ecommerce_store_page = array( 'post_type' => 'page', 'post_title' => $advance_ecommerce_store_page_title, 'post_content' => $advance_ecommerce_store_content, 'post_status' => 'publish', 'post_author' => 1, 'post_slug' => 'products' ); // Insert the page and get its ID $advance_ecommerce_store_page_id = wp_insert_post($advance_ecommerce_store_page); // Store the page ID in theme mod if (!is_wp_error($advance_ecommerce_store_page_id)) { set_theme_mod('advance_ecommerce_store_product_page', $advance_ecommerce_store_page_id); } } } ?>