title: update woocommerce cart after changing shipping method
body: <p>I am currently working on an online shop with WooCommerce. I faced the problem that I want to grant a discount to customers who chose a specific shipping method. The discount is 0.50 for every single product. I basically solved this problem with the following code in my "<strong>functions.php</strong>": </p>
  
  <pre><code>add_action('woocommerce_before_calculate_totals', 'woo_add_cart_fee');
  
  function woo_add_cart_fee() {
  
      global $woocommerce;
      $cart = $woocommerce-&gt;cart-&gt;get_cart();
      //Calculating Quantity
      foreach ($cart as $cart_val =&gt; $cid) {
          $qty += $cid['quantity'];
      }
  
      if ($woocommerce-&gt;cart-&gt;shipping_label == "specific shipping method") {
          $woo_fee = $qty * (-0.5);
          $woo_name = "discount for specific shipping method";
      }
  
      $woocommerce-&gt;cart-&gt;add_fee(__($woo_name, 'woocommerce'), $woo_fee, true);
  }
  </code></pre>
  
  <p>The code technically works, the only problem I have now is that if a customer changes the shipping method i.e. from the "specific shipping method" to a "normal one" (without any discount) or the other way round, it always displays and calculates the discount value from the previously chosen shipping method. In other words it is always one step back and therefore displays the customer the wrong total amount.</p>
  
  <p>Does anyone has an idea to solve this problem?</p>