Zend certified PHP/Magento developer

magento 2.4 update shipping method when user add/remove products from minicart

On my magento 2.4.6 I have a custom code that allows the free shipping method only for peculiar products so, if one of these products are in the cart, the free shipping is visible, otherwise it’s not.

In order to achieve this I created a plugin beforeAppend on magento class MagentoShippingModelRateResult. The code works:

  • I add the product to the cart from the product page, I go to checkout, I see the shipping method
  • I put another product (which does not have the free shipping option) in the cart and when I go to checkout, I no longer see the shipping method.
  • If I remove the second product from the cart and then I go to checkout, I see the free shipping again

My problem is when I remove the valid product from the minicart. When I do, the checkout is still showing the free shipping and I have to reload the page in order for the shipping method to disappear.

Is there a way to reload the checkout shipping method data when the product is removed from minicart without the need of manually reloading the checkout page?