title: Run JS function in add_action WooCommerce
body: <p>I have this action in my functions.php:</p>
  
  <pre><code>add_action( 'woocommerce_before_calculate_totals', 'adding_custom_price', 10, 1);
  function adding_custom_price( $cart ) {
  global $current_user, $woocommerce, $wpdb;
  
      // This is necessary for WC 3.0+
      if ( is_admin() &amp;&amp; ! defined( 'DOING_AJAX' ) )
          return;
  
      // Avoiding hook repetition (when using price calculations for example)
      if ( did_action( 'woocommerce_before_calculate_totals' ) &gt;= 2 )
          return;
  
              $quantity = 0;
                  foreach ( $cart-&gt;get_cart() as $cart_item ) {
                      $quantity += $cart_item['quantity'];
                      $product_id = $cart_item['data']-&gt;get_id();
                      $product_price = $cart_item['data']-&gt;get_price();
                      $categorie_id = $cart_item['data']-&gt;get_category_ids();
                      $korting_product = get_field( 'discount_points', $product_id );
  
                      //Zet prijs min benegas korting
                      $cart_item['data']-&gt;set_price($product_price - $korting_product);
                  }
  
  echo "&lt;script type='text/javascript'&gt;alert('$quantity');&lt;/script&gt;";
  
  }
  </code></pre>
  
  <p>But the with this line:</p>
  
  <p><code>echo "&lt;script type='text/javascript'&gt;alert('$quantity');&lt;/script&gt;";</code></p>
  
  <p>The cart keeps loading after changing the quantity so what am I doing wrong. I do not get an alert.</p>