title: Updated Woommerce Cart Total Discount Total Not Updating The Order Saved
body: <p>I want to set max. Coupon discount for percent type, e.g 15% from total Order but max. $150. I have successfully updated this to my Cart, so it shows $150 max. But upon saved, the Order does not take the $150 but it recalculates the total Order x 15% and ignore the discount I have set on my Cart (which was $150).</p>
  
  <p>Below is the code I use:</p>
  
  <pre><code>/**
   * Update subtotal with max discount set previously
   * @return string Subtotal with currency
   */
  add_filter( 'woocommerce_cart_subtotal', 'woocommerce_set_max_discount', 10, 3 );
  function woocommerce_set_max_discount( $subtotal, $compound, $cart ) {
      // Get current Coupons
      $coupons = $cart-&gt;coupon_discount_totals;
      foreach($coupons as $coupon_code =&gt; $discount) {
          $coupon = new WC_Coupon($coupon_code);
          // Check max discount
          $max_discount = get_post_meta( $coupon-&gt;get_id(), '_max_discount', true );
          if($max_discount) {
              // Current discount &gt; max discount
              if($discount &gt; $max_discount) {
                  // Set discount to max discount
                  $coupons[$coupon_code] = $max_discount;
                  $need_update = true;
              }
          }
      }
      // Get total discount
      $total_discount = 0;
      foreach($coupons as $coupon_code =&gt; $discount) {
          $total_discount += $discount;
      }
      $total_content = $cart-&gt;get_subtotal() - $total_discount;
      // Update Cart's data
      // $cart-&gt;set_applied_coupons($coupons);
      $cart-&gt;set_discount_total($total_discount);
      $cart-&gt;set_cart_contents_total($total_content);
      $cart-&gt;set_total( $cart-&gt;get_subtotal() - $total_discount + $cart-&gt;get_fee_total());
      $cart-&gt;coupon_discount_totals = $coupons;
      return $subtotal;
  }
  </code></pre>