Home Forums WoodMart support forum Import Linked Variations with WP All Import

Import Linked Variations with WP All Import

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

    philanthropy.gr
    Participant

    Dear 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.
    #645183

    Artem Temos
    Keymaster

    Hello,

    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

    #645221

    philanthropy.gr
    Participant

    Here are the credentials.

    This website is a clone of the production.

    You can run the Import with ID: 5 (which is the one)

    #645283

    Artem Temos
    Keymaster

    We can’t connect using this FTP https://monosnap.com/file/6nkjxdeKN6M9Ku2XIvP6m51Pyi4q7r
    Also, please clarify where is the create_linked_var_data function located in the code.

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