Home › Forums › WoodMart support forum › Import Linked Variations with WP All Import
Import Linked Variations with WP All Import
- This topic has 8 replies, 2 voices, and was last updated 1 month, 2 weeks ago by
Artem Temos.
-
AuthorPosts
-
March 12, 2025 at 12:41 pm #645166
philanthropy.grParticipantDear Support,
Context & Goal:
We have a Woocommerce/Woodmart installation and we want to Import linked variations from a CSV. We are using WP All Import (we have all extensions but they are not needed in this case).Our effort:
We are very familiar with your theme and your code, we know it upside down, we just say it to inform that you we tried many things before coming here.First off, we know the 3 required meta fields you use for post type woodmart_woo_lv, all three are arrays.
_woodmart_linked_products _woodmart_linked_attrs _woodmart_linked_use_product_image
So we have created a CSV (see attached image) with the desired data (we build the data as we will show in the next step)
Inside WP All Import functions we have created a function that builds the data.
At the end, of this function, we tried some code to update the post and clear caches (we will explain later why).function create_linked_var_data( $post_id, $xml_node, $is_update ) { $import_id = wp_all_import_get_import_id(); if ( $import_id == '5' ) { $record = json_decode( json_encode( ( array ) $xml_node ), 1 ); /** * Get all Product IDs from SKUs */ $skus = explode(',', $record['skus']); $ids = array(); foreach($skus as $sku){ $p = wc_get_product_id_by_sku($sku); if(!empty($p) && $p > 0){ $ids[] = $p; } } /** * Get all Associated taxonomies */ $taxonomies = explode(',', $record['color']); $atts = array(); foreach($taxonomies as $taxonomy){ if(taxonomy_exists( $taxonomy )){ $atts[] = $taxonomy; } } /** * Get all Associated taxonomies for images */ $taxonomies = explode(',', $record['images']); $images = array(); foreach($taxonomies as $taxonomy){ if(taxonomy_exists( $taxonomy )){ $images[] = $taxonomy; } } //Values update_post_meta($post_id,'_woodmart_linked_products',$ids); update_post_meta($post_id,'_woodmart_linked_attrs',$atts); update_post_meta($post_id,'_woodmart_linked_use_product_image',$images); // Try to manually delete transients foreach($ids as $id){ wc_delete_product_transients($id); } // Try to manually update and clear caches do_action( 'save_post', $post_id, get_post( $post_id ), true ); wp_cache_delete( $post_id, 'posts' ); clean_post_cache( $post_id ); wp_cache_flush(); } } add_action( 'pmxi_saved_post', 'create_linked_var_data', 99, 3 );
So after the Import, Linked Variations are created correctly with all their data and they are populated (See other attached images).
The problem is that they are not displayed in the front end. We tried many things and only when we manually click the Update button inside a Linked Variation post it appears in the front end.
Inside this file : woodmart/inc/integrations/woocommerce/modules/linked-variations/class-frontend.php
function set_linked_data is not returning the data we need.
either this is working$post = new WP_Query( [ 'post_type' => 'woodmart_woo_lv', 'numberposts' => 1, 'meta_query' => [ // phpcs:ignore [ 'key' => '_woodmart_linked_products', 'value' => sprintf( '"%d"', $product_id ), 'compare' => 'LIKE', ], ], ] );
or this is not working
$this->linked_data = [ 'products' => get_post_meta( $post->posts[0]->ID, '_woodmart_linked_products', true ), 'attrs' => get_post_meta( $post->posts[0]->ID, '_woodmart_linked_attrs', true ), 'use_image' => get_post_meta( $post->posts[0]->ID, '_woodmart_linked_use_product_image', true ), ];
That is why inside the create_linked_var_data function we try at the end to manually trigger the update process and clear any caches.
But only the button Update seems to make it work.We have run out of ideas.
Attachments:
You must be logged in to view attached files.March 12, 2025 at 12:55 pm #645183
Artem TemosKeymasterHello,
Please send us your admin and FTP access so we can check this. We also need to be able to run the import process to troubleshoot it, so send us the instructions as well.
Kind Regards
March 12, 2025 at 2:05 pm #645221
philanthropy.grParticipantHere are the credentials.
This website is a clone of the production.
You can run the Import with ID: 5 (which is the one)
March 12, 2025 at 4:45 pm #645283
Artem TemosKeymasterWe can’t connect using this FTP https://monosnap.com/file/6nkjxdeKN6M9Ku2XIvP6m51Pyi4q7r
Also, please clarify where is thecreate_linked_var_data
function located in the code.March 12, 2025 at 6:07 pm #645314
philanthropy.grParticipantFunction is located on WP All Import function editor.
You can access this either through: All Import -> Settings -> Function Editor
or inside the All Import -> Manage Imports -> Edit Template (of the import and scroll at the bottom)We stated in the message if TLS is not working use ‘Only use Plain FTP (insecure)’
March 12, 2025 at 6:10 pm #645315
philanthropy.grParticipantUse port 21 for ‘Only use Plain FTP (insecure)’
Please provide us your IP address so we make sure you can access it with TLS.
March 13, 2025 at 11:56 am #645512
Artem TemosKeymasterHello,
You need to replace the following line
$ids[] = $p;
with this$ids[] = strval( $p );
https://monosnap.com/file/m8Ull6cXHF4BgkZyqWPa0UcyOHWyz4Kind Regards
March 13, 2025 at 12:29 pm #645529
philanthropy.grParticipantIt worked like a charm.
Now that we look at this
'value' => sprintf( '"%d"', $product_id ),
we can see, hindsight though.We love you, best theme ever.
Have a great day
March 13, 2025 at 1:13 pm #645553
Artem TemosKeymasterGreat, we are glad that you sorted it out. Feel free to contact us if you have any further questions.
-
AuthorPosts
Tagged: Import, linked variations, WoodMart
- You must be logged in to create new topics. Login / Register