• Resolved madtwo

    (@madtwo)


    Hello,

    Is it possible to csv import related products by SKUs using the standard woocommerce importer?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WebToffee

    (@webtoffee)

    Hi @madtwo,

    You can import related products using CSV by including the product IDs of related product in columns named _crp_related_ids. While importing make sure to choose “Import as metadata” while mapping CSV columns.

    Currently, there is no SKU based import support. We will add it to backlogs and improve in coming updates.

    Thread Starter madtwo

    (@madtwo)

    Oh okay, it is because the site I am working on has over 46,000 products and the client has given SKUs to be linked as related products as they do not know what the IDs for each product would be.

    Would be kinda impossible to manually search for each ID of the SKUs they want to link to all the products as each product has 4 to 5 SKUs to be linked. Which means I would have to go through all 46,000 products to find their IDs.

    Plugin Author WebToffee

    (@webtoffee)

    @madtwo

    Please use the below code snippet for importing related products with product SKUs instead of product IDs. use the CSV column Meta:_crp_related_skus for adding comma-separated SKUs

    add_filter( 'woocommerce_product_importer_parsed_data', 'woocommerce_product_importer_parsed_data', 10, 2 );
    
    function woocommerce_product_importer_parsed_data( $data, $d_data ) {
    	foreach ( $data[ 'meta_data' ] as $mkey => $mvalue ) {
    		if ( $mvalue[ 'key' ] == '_crp_related_skus' ) {
    			$product_skus	 = explode( ",", $mvalue[ 'value' ] );
    			$product_ids	 = array();
    			foreach ( $product_skus as $sku ) {
    				$product_ids[] = wc_get_product_id_by_sku( trim( $sku ) );
    			}
    
    			$data[ 'meta_data' ][ '_crp_related_ids' ][ 'key' ]		 = '_crp_related_ids';
    			$data[ 'meta_data' ][ '_crp_related_ids' ][ 'value' ]	 = $product_ids;
    			unset( $data[ 'meta_data' ][ '_crp_related_skus' ] );
    		}
    	}
    	return $data;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Importing CSV with SKUs’ is closed to new replies.