Shipping rates get messed up when removing product from cart

I have 3 code snippets that pertain to shipping:
One hides local pickup from regular customer role. Two orders shipping rates from low to high. Three hides other shipping rates if free shipping is available.

They all work fine when loading the cart. The problem is if I remove a product from the cart, all shipping rates show up and they are out of order.

What’s the best strategy for tackling this issue?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer