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.
@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;
}