Home Forums WoodMart support forum I am having trouble importing variation images

I am having trouble importing variation images

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #471256

    Alex
    Participant

    I am unable to import variations images, I have tried both “Parent product meta” and “Variations products meta” for the data storage method, I am using WP all import.

    Can you help me out?

    I have also contacted WP all import support in parallel since it is a bit of both.

    Attachments:
    You must be logged in to view attached files.
    #471311

    Artem Temos
    Keymaster

    Hello,

    You need to select the “Variations products meta” variant. Variations images ids are stored as meta for each variation post in the database. So you need to format your import file properly. Please, refer to the plugin’s documentation or contacts its developers for help on this matter.

    Kind Regards

    #474869

    Alex
    Participant

    Select the variations products meta and then paste this code into the custom function field for anyone who has the same issue:

    // WoodMart variation gallery
    function gallery_ids_in_string($post_id, $att_id, $filepath, $is_keep_existing_images = ”){
    // The custom field used by gallery.
    $key = ‘wd_additional_variation_images_data’;

    // The separator to use between each ID.
    $separator = “,”;

    // Retrieve the current values in the gallery field.
    $gallery = get_post_meta($post_id, $key, true);

    // Ensure gallery is valid.
    if (is_string($gallery) || is_empty($gallery) || ($gallery == false)) {

    // Split value into array.
    $gallery = explode($separator, $gallery);

    // Add image if it’s not in the gallery.
    if (!in_array($att_id, $gallery)) {

    // Ensure array doesn’t start with empty value.
    if ($gallery[0] == ”) unset($gallery[0]);

    // Add image ID to array.
    $gallery[] = $att_id;

    // Save updated gallery field.
    update_post_meta($post_id, $key, implode($separator, $gallery));

    }
    }
    }

    add_action(‘pmxi_gallery_image’, ‘gallery_ids_in_string’, 10, 4);

    // Remove first image from gallery
    function import_remove_featured_image_from_gallery($post_id, $xml_node) {
    $thumbnail = get_post_meta($post_id, “_thumbnail_id”, true);
    $gallery = get_post_meta($post_id, “wd_additional_variation_images_data”, true);
    $gallery_array = explode(“,”, $gallery);

    $check_thumbnail = array_search($thumbnail,$gallery_array);

    if( $check_thumbnail !== false ) {
    unset($gallery_array[$check_thumbnail]);
    }

    $gallery = implode(“,”, $gallery_array);

    update_post_meta($post_id, “wd_additional_variation_images_data”, $gallery);
    }

    add_action(‘pmxi_saved_post’, ‘import_remove_featured_image_from_gallery’, 10, 2);

    #475049

    Artem Temos
    Keymaster

    Thank you very much for posting your solution here. It will be useful for other WoodMart users.

    Kind Regards

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘I am having trouble importing variation images’ is closed to new replies.