Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter rawahapool

    (@rawahapool)

    I did a clean WordPress Install from the backup I made before installing Litespeed cache and it worked.

    Thread Starter rawahapool

    (@rawahapool)

    my site link is huellandina.com

    Thread Starter rawahapool

    (@rawahapool)

    Ok , so this code worked for me :

    add_filter('wpcf7_form_elements', 'custom_wpcf7_form_elements');
    
    function custom_wpcf7_form_elements($form)
    
    {
    
      global $post;
    
      global $wpdb;
    
      if ($post && 'product' === $post->post_type) {
    
        $productID = $post->ID;
    
      }
    
      $selection_name = get_post_meta(
    
        $productID,
    
        'checklist_selection',
    
        true
    
      );
    
      $database_table_name = $wpdb->prefix . 'selected_posts';
    
      // Prepare the query with proper variable escaping
    
      $selected_row = $wpdb->get_row(
    
        $wpdb->prepare(
    
          "SELECT * FROM $database_table_name WHERE selection_name = %s LIMIT 1",
    
          $selection_name
    
        )
    
      );
    
      if ($selected_row) {
    
        $chosen_items = $selected_row->selected_post_id;
    
        $chosen_ids_array = explode(',', $chosen_items); // Convert the string to an array of IDs
    
        $checklist_posts = array(
    
          'post_type' => 'checklist',
    
          'post_status' => 'publish',
    
          'posts_per_page' => -1, // Retrieve all posts
    
          'post__in' => $chosen_ids_array, // Filter by the chosen IDs
    
        );
    
        $checklist_query = new WP_Query($checklist_posts);
    
        $options = array();
    
        if ($checklist_query->have_posts()) {
    
          while ($checklist_query->have_posts()) {
    
            $checklist_query->the_post();
    
            $title = get_the_title();
    
            $options[] = $title;
    
          }
    
        }
    
        // Restore the global post data
    
        wp_reset_postdata();
    
      }
    
      // Create a new DOMDocument object
    
      $dom = new DOMDocument();
    
      $dom->loadHTML($form);
    
      // Find the specific HTML code block using XPath
    
      $xpath = new DOMXPath($dom);
    
      $elements = $xpath->query('//span[@class="wpcf7-list-item first last"]/label/span[text()="option 1"]/parent::*/parent::*');
    
      // Remove the found elements
    
      foreach ($elements as $element) {
    
        $element->parentNode->removeChild($element);
    
      }
    
      // Get the updated form HTML code
    
      $form = $dom->saveHTML();
    
      $itemToReplace = '<span class="wpcf7-form-control-wrap" data-name="checkbox-591"><span class="wpcf7-form-control wpcf7-checkbox" id="hidden-item"></span></span>';
    
      $form = str_replace($itemToReplace, $itemToReplace, $form);
    
      foreach ($options as $option) {
    
        $itemToConcatenate = '<span class="wpcf7-list-item"><input type="checkbox" name="checkbox-591[]" value="' . $option . '"><label><span class="wpcf7-list-item-label">' . $option . '</span></label></span><br>';
    
        $form = str_replace($itemToReplace, $itemToReplace . $itemToConcatenate, $form);
    
      }
    
      return $form;
    
    }
    Thread Starter rawahapool

    (@rawahapool)

    There are no extra files except this, and no extra code, thanks, waiting for response

    Thread Starter rawahapool

    (@rawahapool)

    Just in case if whole plugin file code is needed , here it is :

    <?php
    
    /*
    
    Plugin Name: Custom Script
    
    Description: custom script for products
    
    Version: 2.2.0
    
    Author: Rawaha
    
    */
    
    // Schedule the function to run every 1 minute and 10 seconds
    
    add_action('my_plugin_cron_event', 'my_plugin_page_callback');
    
    function schedule_my_plugin_cron_event()
    
    {
    
        if (!wp_next_scheduled('my_plugin_cron_event')) {
    
            wp_schedule_event(time(), 'custom_interval', 'my_plugin_cron_event');
    
        }
    
    }
    
    add_action('wp', 'schedule_my_plugin_cron_event');
    
    // Register custom cron interval of 1 minute and 10 seconds
    
    add_filter('cron_schedules', 'add_custom_cron_interval');
    
    function add_custom_cron_interval($schedules)
    
    {
    
        $schedules['custom_interval'] = array(
    
            'interval' => 70, // 70 seconds
    
            'display'  => __('Every 1 Minute and 10 Seconds')
    
        );
    
        return $schedules;
    
    }
    
    function my_plugin_activation_function()
    
    {
    
        $localFilePath = plugin_dir_path(__FILE__) . 'file.xml';
    
        if (!is_file($localFilePath)) {
    
            $url = 'https://download.falk-ross.eu/ws/falkross-stylelist.xml'; // Replace with your XML file URL
    
            // Get the contents of the XML file
    
            $xmlContent = file_get_contents($url);
    
            // Save the XML content to a local file
    
            file_put_contents($localFilePath, $xmlContent);
    
        }
    
    }
    
    register_activation_hook(__FILE__, 'my_plugin_activation_function');
    
    function my_plugin_menu_page()
    
    {
    
        add_menu_page(
    
            'Custom Script', // Page title
    
            'Custom Script', // Menu title
    
            'manage_options', // Capability required to access the page
    
            'custom-script-page', // Page slug
    
            'my_plugin_page_callback', // Callback function to render the page content
    
            'dashicons-admin-plugins', // Icon URL or Dashicon class
    
            4 // Position in the menu
    
        );
    
        add_submenu_page(
    
            'custom-script-page',     // Parent menu slug
    
            'Delete Page',    // Page title
    
            'Delete Page',       // Menu title
    
            'manage_options',     // Capability required to access the page
    
            'delete-page',    // Menu slug
    
            'custom_delete_callback'  // Callback function to render the page content
    
        );
    
        add_submenu_page(
    
            'custom-script-page',     // Parent menu slug
    
            'Without Image',    // Page title
    
            'Without Image',       // Menu title
    
            'manage_options',     // Capability required to access the page
    
            'without-image-page',    // Menu slug
    
            'without_image_callback'  // Callback function to render the page content
    
        );
    
    }
    
    function without_image_callback()
    
    {
    
        // Include WordPress dependencies
    
        require_once(get_home_path() . 'wp-load.php');
    
        // Query WooCommerce products without a featured image
    
        $args = array(
    
            'post_type'      => 'product',
    
            'post_status'    => 'publish',
    
            'posts_per_page' => -1,
    
            'meta_query'     => array(
    
                array(
    
                    'key'     => '_thumbnail_id',
    
                    'compare' => 'NOT EXISTS',
    
                ),
    
            ),
    
        );
    
        $products = new WP_Query($args);
    
        // Loop through products and delete them
    
        if ($products->have_posts()) {
    
            while ($products->have_posts()) {
    
                $products->the_post();
    
                $product_id = get_the_ID();
    
                // Delete product using its ID
    
                wp_delete_post($product_id, true);
    
            }
    
            // Reset post data
    
            wp_reset_postdata();
    
        }
    
    }
    
    function custom_delete_callback()
    
    {
    
        // global $wpdb;
    
        // $wpdb->query("DELETE FROM {$wpdb->prefix}posts WHERE post_type = 'product'");
    
    }
    
    function upload_product_image($image_url)
    
    {
    
        $upload_dir = wp_upload_dir();
    
        if (empty($image_url)) {
    
            return false;
    
        }
    
        $image_data = file_get_contents($image_url);
    
        $filename   = basename($image_url);
    
        if (empty($filename)) {
    
            return false;
    
        }
    
        if (wp_mkdir_p($upload_dir['path'])) {
    
            $file = $upload_dir['path'] . '/' . $filename;
    
        } else {
    
            $file = $upload_dir['basedir'] . '/' . $filename;
    
        }
    
        file_put_contents($file, $image_data);
    
        $wp_filetype = wp_check_filetype($filename, null);
    
        $attachment = array(
    
            'post_mime_type' => $wp_filetype['type'],
    
            'post_title'     => sanitize_file_name($filename),
    
            'post_content'   => '',
    
            'post_status'    => 'inherit',
    
            // 'post_author'    => get_user_by('login', 'admin')->ID,
    
            // Set the author as 'admin'
    
        );
    
        $attachment_id = wp_insert_attachment($attachment, $file);
    
        if (!is_wp_error($attachment_id)) {
    
            require_once get_home_path() . 'wp-admin/includes/image.php';
    
            $attachment_data = wp_generate_attachment_metadata($attachment_id, $file);
    
            wp_update_attachment_metadata($attachment_id, $attachment_data);
    
            return $attachment_id;
    
        }
    
        return false;
    
    }
    
    // Callback function to render the page content
    
    function my_plugin_page_callback()
    
    {
    
        // error_reporting(0);
    
        // @ini_set('display_errors', 0);
    
        $localFilePath = plugin_dir_path(__FILE__) . 'file.xml';
    
        $usedUrlsFilePath = plugin_dir_path(__FILE__) . 'Used-URLS.php';
    
        if (!is_file($localFilePath)) {
    
            $url = 'https://download.falk-ross.eu/ws/falkross-stylelist.xml'; // Replace with your XML file URL
    
            // Get the contents of the XML file
    
            $xmlContent = file_get_contents($url);
    
            // Save the XML content to a local file
    
            file_put_contents($localFilePath, $xmlContent);
    
        }
    
        $xml = simplexml_load_file($localFilePath);
    
        $urls = [];
    
        foreach ($xml->style as $style) {
    
            $urlStyleJson = (string) $style->url_style_json;
    
            if (str_ends_with($urlStyleJson, '.json')) {
    
                $urls[] = $urlStyleJson;
    
            }
    
        }
    
        // Create the Used-URLS.php file if it doesn't exist
    
        if (!is_file($usedUrlsFilePath)) {
    
            touch($usedUrlsFilePath);
    
        }
    
        // Load used URLs from file
    
        $usedUrls = file($usedUrlsFilePath, FILE_IGNORE_NEW_LINES);
    
        // Fetch and display JSON from the first two URLs
    
        $counter = 0;
    
        foreach ($urls as $url) {
    
            // Check if URL is already used
    
            if (in_array($url, $usedUrls)) {
    
                continue; // Skip the current iteration if URL is already used
    
            }
    
            $jsonContent = file_get_contents($url);
    
            if ($jsonContent !== false) {
    
                $jsonData = json_decode($jsonContent, true);
    
                if ($jsonData !== null) {
    
                    global $wpdb;
    
                    $product_name = $jsonData['style_list']['style']['style_name']['language']['de']['$t'];
    
                    // Query to check if the product exists
    
                    $query = $wpdb->prepare("
    
                        SELECT COUNT(*) AS count
    
                    FROM {$wpdb->posts}
    
                    WHERE post_type = 'product'
    
                    AND post_title = %s
    
                    AND post_status = 'publish'
    
                    ", $product_name);
    
                    $product_count = $wpdb->get_var($query);
    
                    // Check if the product exists
    
                    if (
    
                        $product_count > 0
    
                    ) {
    
                        echo 'Product exists.';
    
                        // You can exit the script here or perform any other actions you need.
    
                        continue;
    
                    } else {
    
                        echo 'Product does not exist.';
    
                    }
    
                    $brand_code = $jsonData['style_list']['style']['brand_code']['$t'];
    
                    $product_group = isset($jsonData['style_list']['style']['style_filter_list']['style_product_group_list']['style_product_group'])
    
                        ? $jsonData['style_list']['style']['style_filter_list']['style_product_group_list']['style_product_group']
    
                        : null;
    
                    $product_group_result = '';
    
                    if ($product_group !== null) {
    
                        foreach ($product_group as $product_group_string) {
    
                            // echo $product_group_string['$t'];
    
                            $product_group_result .= $product_group_string['$t'] . ', '; // Concatenate each value with a comma separator
    
                            echo '<br>';
    
                        }
    
                    }
    
                    //LinkTo
    
                    $product_link_array = $jsonData['style_list']['style']['style_link_list']['style_link_to'];
    
                    $product_link_to = '';
    
                    foreach ($product_link_array as $index => $product_link) {
    
                        $product_links = $product_link['style']['$t'];
    
                        $product_link_to  .= $product_links . ',';
    
                    }
    
                    //long sleeve
    
                    $product_sleeve_group = isset($jsonData['style_list']['style']['style_filter_list']['style_product_group_list']['style_product_group'])
    
                        ? $jsonData['style_list']['style']['style_filter_list']['style_sleeve_group_list']['style_sleeve_group']['$t']
    
                        : null;
    
                    //gender
    
                    $product_gender_group = isset($jsonData['style_list']['style']['style_filter_list']['style_product_group_list']['style_product_group'])
    
                        ? $jsonData['style_list']['style']['style_filter_list']['style_gender_group_list']['style_gender_group']['$t']
    
                        : null;
    
                    //weight
    
                    $product_weight_group = isset($jsonData['style_list']['style']['style_filter_list']['style_product_group_list']['style_product_group'])
    
                        ? $jsonData['style_list']['style']['style_filter_list']['style_weight_group_list']['style_weight_group']['$t']
    
                        : null;
    
                    $product_color_group = isset($jsonData['style_list']['style']['style_filter_list']['style_product_group_list']['style_product_group'])
    
                        ? $jsonData['style_list']['style']['style_filter_list']['style_color_group_list']['style_color_group']
    
                        : null;
    
                    $product_color_group_result = '';
    
                    if ($product_color_group !== null) {
    
                        foreach ($product_color_group as $product_color_group_string) {
    
                            // echo $product_group_string['$t'];
    
                            $product_color_group_result .= $product_color_group_string['$t'] . ', '; // Concatenate each value with a comma separator
    
                            echo '<br>';
    
                        }
    
                    }
    
                    $product_brand_name = isset($jsonData['style_list']['style']['brand_name']['$t'])
    
                        ? $jsonData['style_list']['style']['brand_name']['$t']
    
                        : null;
    
                    $product_catalog_page = isset($jsonData['style_list']['style']['style_catalog_page']['$t']) ? $jsonData['style_list']['style']['style_catalog_page']['$t'] : null;
    
                    $product_nr = isset($jsonData['style_list']['style']['style_nr']['$t']) ? $jsonData['style_list']['style']['style_nr']['$t'] : null;
    
                    $product_supplier_code = isset($jsonData['style_list']['style']['supplier_code']['$t']) ? $jsonData['style_list']['style']['supplier_code']['$t'] : null;
    
                    $product_tariff_nr = isset($jsonData['style_list']['style']['style_custom_tariff_nr']['$t']) ? $jsonData['style_list']['style']['style_custom_tariff_nr']['$t'] : null;
    
                    //categories
    
                    $product_sub_categories = '';
    
                    if (isset($jsonData['style_list']['style']['style_category_list']['style_category_main']['style_category_sub']['language']['de'])) {
    
                        $product_sub_categories =  $jsonData['style_list']['style']['style_category_list']['style_category_main']['style_category_sub']['language']['de']['$t'];
    
                    } else {
    
                        $styleCategorySub = $jsonData['style_list']['style']['style_category_list']['style_category_main']['style_category_sub'];
    
                        foreach ($styleCategorySub as $index => $subCategory) {
    
                            $languageValue = $subCategory['language']['de']['$t'];
    
                            $product_sub_categories .= $languageValue . ',';
    
                        }
    
                    }
    
                    //Images
    
                    $product_image_gallery_array = $jsonData['style_list']['style']['style_picture_list']['style_picture'];
    
                    $product_image_gallery = '';
    
                    foreach ($product_image_gallery_array as $index => $product_image) {
    
                        $product_image_url = $product_image['url']['$t'];
    
                        $product_image_gallery .= $product_image_url . ',';
    
                    }
    
                    //description
    
                    $product_description = isset($jsonData['style_list']['style']['style_description']['language']['de']['$t']) ? $jsonData['style_list']['style']['style_description']['language']['de']['$t'] : null;
    
                    //supplier code
    
                    $product_supplier_code = isset($jsonData['style_list']['style']['supplier_article_code']['$t']) ? $jsonData['style_list']['style']['supplier_article_code']['$t'] : null;
    
                    // Create product data
    
                    global $wpdb;
    
                    $product_data = array(
    
                        'post_title'    => $product_name,
    
                        'post_content'  => $product_description,
    
                        'post_status'   => 'publish',
    
                        'post_author'   => 1,
    
                        'post_type'     => 'product',
    
                        'product_type'  => 'variable',
    
                    );
    
                    // Insert the product
    
                    $product_id = wp_insert_post($product_data);
    
                    wp_set_object_terms($product_id, 'variable', 'product_type');
    
                    // Set product attributes
    
                    $product_attributes = array(
    
                        'brand_code' => $brand_code,
    
                        'product_link_to' => $product_link_to,
    
                        'product_gender_group' => $product_gender_group,
    
                        'product_weight_group' => $product_weight_group,
    
                        'product_color_group_result' => $product_color_group_result,
    
                        'product_brand_name' => $product_brand_name,
    
                        'product_catalog_page' => $product_catalog_page,
    
                        'product_nr' => $product_nr,
    
                        'product_supplier_code' => $product_supplier_code,
    
                        'product_tariff_nr' => $product_tariff_nr,
    
                    );
    
                    // Loop through attributes and add them to the product
    
                    foreach ($product_attributes as $attribute_key => $attribute_value) {
    
                        // Get or create the attribute
    
                        $attribute_taxonomy = wc_attribute_taxonomy_name($attribute_key);
    
                        if (!taxonomy_exists($attribute_taxonomy)) {
    
                            $attribute_id = wc_create_attribute(array(
    
                                'name'         => $attribute_key,
    
                                'slug'         => sanitize_title($attribute_key),
    
                                'type'         => 'select',
    
                                'order_by'     => 'menu_order',
    
                                'has_archives' => true,
    
                            ));
    
                            $attribute_taxonomy = wc_attribute_taxonomy_name($attribute_id);
    
                        } else {
    
                            $attribute_id = wc_attribute_taxonomy_id_by_name($attribute_taxonomy);
    
                        }
    
                        // Assign the attribute to the product
    
                        if ($attribute_id && !empty($attribute_value)) {
    
                            $term = term_exists($attribute_value, $attribute_taxonomy);
    
                            if (
    
                                $term !== 0 && $term !== null
    
                            ) {
    
                                wp_set_object_terms($product_id, $term['term_id'], $attribute_taxonomy, true);
    
                            } else {
    
                                $term = wp_insert_term($attribute_value, $attribute_taxonomy);
    
                                if (!is_wp_error($term)) {
    
                                    wp_set_object_terms($product_id, $term['term_id'], $attribute_taxonomy, true);
    
                                }
    
                            }
    
                        }
    
                    }
    
                    // Set product tags
    
                    if (!empty($product_group_result)) {
    
                        $tags = explode(
    
                            ',',
    
                            $product_group_result
    
                        );
    
                        wp_set_object_terms($product_id, $tags, 'product_tag');
    
                    }
    
                    if (!empty($product_sleeve_group)) {
    
                        $tags = explode(',', $product_sleeve_group);
    
                        wp_set_object_terms(
    
                            $product_id,
    
                            $tags,
    
                            'product_tag'
    
                        );
    
                    }
    
                    // Set product categories
    
                    if (!empty($product_sub_categories)) {
    
                        $categories = explode(',', $product_sub_categories);
    
                        wp_set_object_terms($product_id, $categories, 'product_cat');
    
                    }
    
                    // Add images to the product gallery
    
                    if (!empty($product_image_gallery)) {
    
                        $image_urls = explode(',', $product_image_gallery);
    
                        $gallery_ids = array();
    
                        foreach ($image_urls as $image_url) {
    
                            $image_url = trim($image_url); // Trim whitespace
    
                            if (!empty($image_url)) {
    
                                $attachment_id = upload_product_image($image_url);
    
                                if ($attachment_id) {
    
                                    $gallery_ids[] = $attachment_id;
    
                                }
    
                            }
    
                        }
    
                        if (!empty($gallery_ids)) {
    
                            // Check if the first image is empty, if so, use the next non-empty image
    
                            $featured_image = $gallery_ids[0];
    
                            if (empty($featured_image)) {
    
                                foreach ($gallery_ids as $image_id) {
    
                                    if (!empty($image_id)) {
    
                                        $featured_image = $image_id;
    
                                        break;
    
                                    }
    
                                }
    
                            }
    
                            // Update the product image gallery
    
                            update_post_meta($product_id, '_product_image_gallery', implode(',', $gallery_ids));
    
                            // Set the featured image
    
                            set_post_thumbnail($product_id, $featured_image);
    
                        }
    
                    }
    
                    // Define attributes
    
                    $attributes = array(
    
                        'color' => array(
    
                            'name'         => 'Color',
    
                            'value'        => 'Black',
    
                            'is_visible'   => true,
    
                            'is_variation' => true,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'size' => array(
    
                            'name'         => 'Size',
    
                            'value'        => 'M',
    
                            'is_visible'   => true,
    
                            'is_variation' => true,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-close-out' => array(
    
                            'name'         => 'sku-close-out',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-changed-date' => array(
    
                            'name'         => 'sku-changed-date',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-size-order' => array(
    
                            'name'         => 'sku-size-order',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-pieces-in-carton' => array(
    
                            'name'         => 'sku-pieces-in-carton',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-ean' => array(
    
                            'name'         => 'sku-ean',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-coo' => array(
    
                            'name'         => 'sku-coo',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-size-code' => array(
    
                            'name'         => 'sku-size-code',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-pieces-in-pack' => array(
    
                            'name'         => 'sku-pieces-in-pack',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku_weight' => array(
    
                            'name'         => 'sku_weight',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-artnum' => array(
    
                            'name'         => 'sku-artnum',
    
                            'value'        => '',
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                    );
    
                    // Attributes Creation
    
                    foreach ($attributes as $attribute_slug => $attribute_data) {
    
                        $attribute = wc_get_attribute($attribute_slug);
    
                        // Create attribute if it doesn't exist
    
                        if (!$attribute) {
    
                            $attribute_args = array(
    
                                'name'         => $attribute_data['name'],
    
                                'slug'         => $attribute_slug,
    
                                'type'         => 'text',
    
                                'order_by'     => 'menu_order',
    
                                'has_archives' => false,
    
                            );
    
                            $attribute_id = wc_create_attribute($attribute_args);
    
                            // Set the attribute to be used for variations
    
                            if ($attribute_id && $attribute_data['is_variation']) {
    
                                $attribute_taxonomy = wc_attribute_taxonomy_name($attribute_slug);
    
                                update_option('woocommerce_taxonomy_' . $attribute_taxonomy, '1');
    
                            }
    
                        }
    
                    }
    
                    $variation_list_arr = $jsonData['style_list']['style']['sku_list']['sku'];
    
                    $variation_string_sku_closeout = '';
    
                    $variation_string_sku_changed_date = '';
    
                    $variation_string_sku_size_name = '';
    
                    $variation_string_sku_size_order = '';
    
                    $variation_string_sku_pieces_in_carton = '';
    
                    $variation_string_sku_ean = '';
    
                    $variation_string_sku_coo = '';
    
                    $variation_string_sku_color_name = '';
    
                    $variation_string_sku_size_code = '';
    
                    $variation_string_sku_pieces_in_pack = '';
    
                    $variation_string_sku_weight = '';
    
                    $variation_string_sku_artnum = '';
    
                    foreach ($variation_list_arr as $index => $variation_list) {
    
                        if (isset($variation_list['sku_closeout']['$t'])) {
    
                            $sku_closeout = $variation_list['sku_closeout']['$t'];
    
                            $variation_string_sku_closeout .= $sku_closeout . '|';
    
                        }
    
                        if (isset($variation_list['sku_changed_date']['$t'])) {
    
                            $sku_changed_date = $variation_list['sku_changed_date']['$t'];
    
                            $variation_string_sku_changed_date .= $sku_changed_date . '|';
    
                        }
    
                        if (isset($variation_list['sku_color_code']['$t'])) {
    
                            $sku_color_code = $variation_list['sku_color_code']['$t'];
    
                            // $variation_string .= $sku_color_code . '|';
    
                        }
    
                        if (isset($variation_list['sku_size_name']['$t'])) {
    
                            $sku_size_name = $variation_list['sku_size_name']['$t'];
    
                            $variation_string_sku_size_name .= $sku_size_name . '|';
    
                        }
    
                        if (isset($variation_list['sku_size_order']['$t'])) {
    
                            $sku_size_order = $variation_list['sku_size_order']['$t'];
    
                            $variation_string_sku_size_order .= $sku_size_order . '|';
    
                        }
    
                        if (isset($variation_list['sku_pieces_in_carton']['$t'])) {
    
                            $sku_pieces_in_carton = $variation_list['sku_pieces_in_carton']['$t'];
    
                            $variation_string_sku_pieces_in_carton .= $sku_pieces_in_carton . '|';
    
                        }
    
                        if (isset($variation_list['sku_ean']['$t'])) {
    
                            $sku_ean = $variation_list['sku_ean']['$t'];
    
                            $variation_string_sku_ean .= $sku_ean . '|';
    
                        }
    
                        if (isset($variation_list['sku_color_swatch_url']['$t'])) {
    
                            $sku_color_swatch_url = $variation_list['sku_color_swatch_url']['$t'];
    
                            // $variation_string .= $sku_color_swatch_url . '|';
    
                        }
    
                        if (isset($variation_list['sku_coo']['$t'])) {
    
                            $sku_coo = $variation_list['sku_coo']['$t'];
    
                            $variation_string_sku_coo .= $sku_coo . '|';
    
                        }
    
                        if (isset($variation_list['sku_color_name']['$t'])) {
    
                            $sku_color_name = $variation_list['sku_color_name']['$t'];
    
                            $variation_string_sku_color_name .= $sku_color_name . '|';
    
                        }
    
                        if (isset($variation_list['sku_color_picture']['$t'])) {
    
                            $sku_color_picture = $variation_list['sku_color_picture']['$t'];
    
                            // $variation_string .= $sku_color_picture . '|';
    
                        }
    
                        if (isset($variation_list['sku_size_code']['$t'])) {
    
                            $sku_size_code = $variation_list['sku_size_code']['$t'];
    
                            $variation_string_sku_size_code .= $sku_size_code . '|';
    
                        }
    
                        if (isset($variation_list['sku_pieces_in_pack']['$t'])) {
    
                            $sku_pieces_in_pack = $variation_list['sku_pieces_in_pack']['$t'];
    
                            $variation_string_sku_pieces_in_pack .= $sku_pieces_in_pack . '|';
    
                        }
    
                        if (isset($variation_list['sku_color_picture_url']['$t'])) {
    
                            $sku_color_picture_url = $variation_list['sku_color_picture_url']['$t'];
    
                            // $variation_string .= $sku_color_picture_url . '|';
    
                        }
    
                        if (isset($variation_list['sku_weight']['$t'])) {
    
                            $sku_weight = $variation_list['sku_weight']['$t'];
    
                            $variation_string_sku_weight .= $sku_weight . '|';
    
                        }
    
                        if (isset($variation_list['sku_artnum']['$t'])) {
    
                            $sku_artnum = $variation_list['sku_artnum']['$t'];
    
                            $variation_string_sku_artnum .= $sku_artnum . '|';
    
                        }
    
                    }
    
                    // Define attributes
    
                    $attributes = array(
    
                        'color' => array(
    
                            'name'         => 'Color',
    
                            'value'        => $variation_string_sku_color_name,
    
                            'is_visible'   => false,
    
                            'is_variation' => true,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'size' => array(
    
                            'name'         => 'Size',
    
                            'value'        => $variation_string_sku_size_name,
    
                            'is_visible'   => false,
    
                            'is_variation' => true,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-close-out' => array(
    
                            'name'         => 'sku-close-out',
    
                            'value'        => $variation_string_sku_closeout,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-changed-date' => array(
    
                            'name'         => 'sku-changed-date',
    
                            'value'        => $variation_string_sku_changed_date,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-size-order' => array(
    
                            'name'         => 'sku-size-order',
    
                            'value'        => $variation_string_sku_size_order,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-pieces-in-carton' => array(
    
                            'name'         => 'sku-pieces-in-carton',
    
                            'value'        => $variation_string_sku_pieces_in_carton,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-ean' => array(
    
                            'name'         => 'sku-ean',
    
                            'value'        => $variation_string_sku_ean,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-coo' => array(
    
                            'name'         => 'sku-coo',
    
                            'value'        => $variation_string_sku_coo,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-size-code' => array(
    
                            'name'         => 'sku-size-code',
    
                            'value'        => $variation_string_sku_size_code,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-pieces-in-pack' => array(
    
                            'name'         => 'sku-pieces-in-pack',
    
                            'value'        => $variation_string_sku_pieces_in_pack,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku_weight' => array(
    
                            'name'         => 'sku_weight',
    
                            'value'        => $variation_string_sku_weight,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                        'sku-artnum' => array(
    
                            'name'         => 'sku-artnum',
    
                            'value'        => $variation_string_sku_artnum,
    
                            'is_visible'   => false,
    
                            'is_variation' => false,
    
                            'is_taxonomy'  => false,
    
                        ),
    
                    );
    
                    update_post_meta(
    
                        $product_id,
    
                        '_product_attributes',
    
                        $attributes
    
                    );
    
                    require_once(get_home_path() . '/wp-load.php');
    
                    require_once(get_home_path() . 'wp-admin/includes/post.php');
    
                    // Define variation data
    
                    foreach ($variation_list_arr as $index => $variation_list) {
    
                        if (isset($variation_list['sku_closeout']['$t'])) {
    
                            $sku_closeout = $variation_list['sku_closeout']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_changed_date']['$t'])) {
    
                            $sku_changed_date = $variation_list['sku_changed_date']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_color_code']['$t'])) {
    
                            $sku_color_code = $variation_list['sku_color_code']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_size_name']['$t'])) {
    
                            $sku_size_name = $variation_list['sku_size_name']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_size_order']['$t'])) {
    
                            $sku_size_order = $variation_list['sku_size_order']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_pieces_in_carton']['$t'])) {
    
                            $sku_pieces_in_carton = $variation_list['sku_pieces_in_carton']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_ean']['$t'])) {
    
                            $sku_ean = $variation_list['sku_ean']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_color_swatch_url']['$t'])) {
    
                            $sku_color_swatch_url = $variation_list['sku_color_swatch_url']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_coo']['$t'])) {
    
                            $sku_coo = $variation_list['sku_coo']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_color_name']['$t'])) {
    
                            $sku_color_name = $variation_list['sku_color_name']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_color_picture']['$t'])) {
    
                            $sku_color_picture = $variation_list['sku_color_picture']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_size_code']['$t'])) {
    
                            $sku_size_code = $variation_list['sku_size_code']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_pieces_in_pack']['$t'])) {
    
                            $sku_pieces_in_pack = $variation_list['sku_pieces_in_pack']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_color_picture_url']['$t'])) {
    
                            $sku_color_picture_url = $variation_list['sku_color_picture_url']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_weight']['$t'])) {
    
                            $sku_weight = $variation_list['sku_weight']['$t'];
    
                        }
    
                        if (isset($variation_list['sku_artnum']['$t'])) {
    
                            $sku_artnum = $variation_list['sku_artnum']['$t'];
    
                        }
    
                        require_once(get_home_path() . '/wp-load.php');
    
                        require_once(get_home_path() . 'wp-admin/includes/post.php');
    
                        // Define variation data
    
                        $variations = array(
    
                            array(
    
                                'attributes' => array(
    
                                    'color' => $sku_color_name,
    
                                    'size'  => $sku_size_name,
    
                                    'sku-close-out' => $sku_closeout,
    
                                    'sku-changed-date' => $sku_changed_date,
    
                                    'sku-size-order' => $sku_size_order,
    
                                    'sku-pieces-in-carton' => $sku_pieces_in_carton,
    
                                    'sku-ean' => $sku_ean,
    
                                    'sku-coo' => $sku_coo,
    
                                    'sku-size-code' => $sku_size_code,
    
                                    'sku-pieces-in-pack' => $sku_pieces_in_pack,
    
                                    'sku_weight' => $sku_weight,
    
                                    'sku-artnum' => $sku_artnum
    
                                ),
    
                                'regular_price' => '0.00',
    
                                'sale_price'    => '0.00',
    
                            ),
    
                        );
    
                        foreach ($variations as $variation_data) {
    
                            $variation = array(
    
                                'post_title'  => $product_name,
    
                                'post_name'   => $product_name,
    
                                'post_status' => 'publish',
    
                                'post_parent' => $product_id,
    
                                'post_type'   => 'product_variation',
    
                                'meta_input'  => array(
    
                                    '_regular_price' => $variation_data['regular_price'],
    
                                    '_sale_price'    => $variation_data['sale_price'],
    
                                    '_price'         => $variation_data['regular_price'],
    
                                    '_stock_status'  => 'instock',
    
                                    '_sku'           => $sku_artnum,
    
                                    '_manage_stock'  => 'no',
    
                                ),
    
                            );
    
                            $variation_id = wp_insert_post($variation);
    
                            //variation image
    
                            if (isset($sku_color_picture_url)) {
    
                                $image_url = $sku_color_picture_url;
    
                                $image_name = basename($image_url);
    
                                $upload_dir = wp_upload_dir();
    
                                $image_path = $upload_dir['path'] . '/' . $image_name;
    
                                // Download the image file
    
                                $image_contents = file_get_contents($image_url);
    
                                file_put_contents(
    
                                    $image_path,
    
                                    $image_contents
    
                                );
    
                                // Create attachment data
    
                                $attachment = array(
    
                                    'post_mime_type' => 'image/jpeg', // Adjust the mime type according to your image type
    
                                    'post_title'     => $image_name,
    
                                    'post_content'   => '',
    
                                    'post_status'    => 'inherit'
    
                                );
    
                                // Insert the attachment
    
                                $attachment_id = wp_insert_attachment($attachment, $image_path, $variation_id);
    
                                require_once(get_home_path() . 'wp-admin/includes/image.php');
    
                                $attachment_data = wp_generate_attachment_metadata($attachment_id, $image_path);
    
                                wp_update_attachment_metadata($attachment_id, $attachment_data);
    
                                // Set the variation's featured image
    
                                set_post_thumbnail($variation_id, $attachment_id);
    
                            }
    
                            // Set variation attributes
    
                            foreach ($variation_data['attributes'] as $attribute_name => $attribute_value) {
    
                                update_post_meta($variation_id, 'attribute_' . sanitize_title($attribute_name), $attribute_value);
    
                            }
    
                            //custom field ends
    
                            update_post_meta($variation_id, '_product_id', $product_id);
    
                            update_post_meta($variation_id, '_variation_id', $variation_id);
    
                            update_post_meta($variation_id, '_manage_stock', 'no');
    
                        }
    
                    }
    
                }
    
                // Refresh product's cached attributes
    
                wc_delete_product_transients($product_id);
    
                echo "<br>Product Successfully Imported with variations, Product ID is : " . $product_id . "<br>";
    
            }
    
            $counter++;
    
            if ($counter >= 4) {
    
                break;
    
            }
    
        }
    
    }
    
    // Hook into the admin menu initialization
    
    add_action('admin_menu', 'my_plugin_menu_page');
    Thread Starter rawahapool

    (@rawahapool)

    Let me know if any details needed, also I can see the images getting uploaded to media library, but not being attached to the products, when imported via cron

    Thread Starter rawahapool

    (@rawahapool)

    ok, can I ask in how much time they can work together ? like when do you think it will be possible?

    Thread Starter rawahapool

    (@rawahapool)

    please explain , how wpforms and e2pdf can work together

    Thread Starter rawahapool

    (@rawahapool)

    hi, how can I make it work with wp-forms, will it work same like, forminator,formidable etc

    Thread Starter rawahapool

    (@rawahapool)

    Hi , I pasted link and it is working. But the problem is it is showing this https:// how can I remove it?

    We received a request to reset the password for your account. If you
    made this request, click the link below to change your password:
    https://https://smtpfree.freecluster.eu/password-reset/?act=reset_password&hash=GUoHC6xspMfJJXG4kmew&user_id=18
    If you didn't make this request, ignore this email or report it to us.
    Thank you!
    The fi Team
    Thread Starter rawahapool

    (@rawahapool)

    I tried these methods, checking the link url in the settings>email> password reset template, but it isn’t working

    Thread Starter rawahapool

    (@rawahapool)

    Thank you! this was what I needed, you are really at our service!

    Thread Starter rawahapool

    (@rawahapool)

    In easy words how to display current user data in pdf?

    Thread Starter rawahapool

    (@rawahapool)

    thank you for your reply ! what I want to ask is, I have a login form with forminator, when someone login through that form, I just want his email to be displayed in the pdf , is this possible through e2pdf and forminator?

Viewing 14 replies - 1 through 14 (of 14 total)