Woocommerce Redirect Thank you page based on product ID – Leave items in the cart

I use the following code to redirect users to the personalized thank you page after the purchase of a specific product. It gets the product ID and then redirects based on that ID. I have pasted the code below. The problem is after the purchase when using this excerpt in my functions.php purchased items remain in the basket. I've used this particular code so that tracking can always occur; however, I can use another tracking method if needed, so I'm not against the use of the woocommerce_get_return_url

add_action (& # 39; template_redirect & # 39 ;, redirect_thankyou_1month & # 39;);

function redirect_thankyou_1month () {

/ * do not do anything if we are not on the appropriate page * /
if (! is_wc_endpoint_url ('command-received') || empty ($ _GET['key'] )) {
return;
}

$ order_id = wc_get_order_id_by_order_key ($ _GET['key'] )
$ order = wc_get_order ($ order_id);

foreach ($ order-> get_items () as $ item) {
if ($ item['product_id'] == 2781) {
wp_redirect (& # 39; / ar1m / & # 39;)
exit;
}
}

}