title: Replace "added to cart" notice with JS Sweet Alert on WooCommerce
body: <p>I've removed the standard "Added to cart" message given by WooCommerce. I have then added the code below which is using the Sweet Alert. The idea is to remove all "added to cart" messages and to only use the sweet alert.</p>
  
  <p>Based on <em>"<a href="https://stackoverflow.com/questions/50553666/js-alert-on-ajax-add-to-cart-for-specific-product-category-count-in-woocommerce/50554322#50554322">JS alert on ajax add to cart for specific product category count in Woocommerce</a>"</em> answer code by @LoicTheAztec, my code works for the first product added, <strong>but not for the following ones.</strong> So it works fine when the cart is empty and when adding the first product.</p>
  
  <p>Here's the code I'm using:</p>
  
  <pre><code>// remove add to cart woocommerce message
  add_filter('wc_add_to_cart_message_html', '__return_null');
  
  // Wordpress Ajax PHP
  add_action('wp_ajax_nopriv_checking_items', 'atc_sweet_message');
  add_action('wp_ajax_checking_items', 'atc_sweet_message');
  
  function atc_sweet_message() {
      if (isset($_POST['id']) &amp;&amp; $_POST['id'] &gt; 0) {
          $count = 0;
          $product_id = $_POST['id'];
          foreach(WC()-&gt; cart-&gt; get_cart() as $cart_item) {
              $count += $cart_item['quantity'];
          }
      }
      echo $count;
      die();
  }
  
  // jQuery Ajax
  add_action('wp_footer', 'item_count_check');
  function item_count_check() {
      if (is_checkout())
          return; 
      ?&gt; 
      &lt;script src="https://unpkg.com/sweetalert2@7.20.1/dist/sweetalert2.all.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
      jQuery( function($) {
          if ( typeof wc_add_to_cart_params === 'undefined' )
              return false;
  
          $(document.body).on( 'added_to_cart', function( event, fragments, cart_hash, $button ) {
              $.ajax({
                  type: 'POST',
                  url: wc_add_to_cart_params.ajax_url,
                  data: {
                      'action': 'checking_items',
                      'id'    : $button.data( 'product_id' )
                  },
                  success: function (response) {
                      if(response == 1 ){
                          const toast = swal.mixin({
                              toast: true,
                              showConfirmButton: false,
                              timer: 3000
                          });
                          toast({
                              type: 'success',
                              title: 'Product Added To Cart'
                          })
                      }
                  }
              });
          });
      });
      &lt;/script&gt;
      &lt;?php
  }
  </code></pre>
  
  <p>I tried removing <code>if(response == 1 ){</code> without success. Any input on this is appreciated.</p>