for anyone interested i added 1 line to mike’s great bit of code to include the main (parent) product. so this will add the product for the provided id and all of its upsells to the cart.
add_action( 'wp_loaded', 'bulk_upsell_add_to_cart_action', 20 );
function bulk_upsell_add_to_cart_action() {
if ( ! empty( $_GET['add-upsells-to-cart'] ) ) {
$product_id = absint( $_GET['add-upsells-to-cart'] );
$product = wc_get_product( $product_id );
if ( $product ) {
$upsell_ids = $product->get_upsells();
array_unshift($upsell_ids, $product_id); // <-- new line
if ( $upsell_ids ) {
$count = 0;
foreach ( $upsell_ids as $upsell_id ) {
if ( WC()->cart->add_to_cart( $upsell_id ) ) {
$count ++;
}
}
wc_add_notice( sprintf( _n( 'Added %d item to the cart', 'Added %d items to the cart', $count ), $count ) );
}
}
}
}