I am interested in creating a new order programmatically and my codes are working fine but for the subscription product, it's not adding the subscription, it only adds the order. Here is my code
$product = get_product($product_id);
$order = wc_create_order();
$order->add_product( $product , 1 );
$order->calculate_totals();
// assign the order to the current user
update_post_meta(
$order->id,
'_customer_user',
get_current_user_id()
);
// payment_complete
$order->payment_complete();