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