title: Run Javascript on Woocommerce if page equals X and number of cart items equals Y
body: <p>I am trying to run javascript (Sweet Alert) on Woocommerce archive shop pages to execute only if there are 5 items in the cart &amp; the page is equal to 'url/leanshop/'.</p>
  
  <p>My add to cart functionality is using AJAX. The below code, sort of works...but I can't get it to trigger for the above conditions. It currently only triggers each time a product is added to the cart via AJAX.</p>
  
  <p><strong>My code so far:</strong></p>
  
  <pre><code>add_action( 'wp_footer', 'items_in_cart_trigger' );
  function items_in_cart_trigger() {
  
          global $woocommerce;
          // Set the minimum number of products in cart
          $maximum_num_products = 5;
          // Get the Cart's total number of products
          $cart_num_products = WC()-&gt;cart-&gt;cart_contents_count;
  
          // Compare values and if required amount of items in cart, display popup.
          if( $cart_num_products == $maximum_num_products &amp;&amp; is_page( '/leanshop/' ) ) {
  
      ?&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;
              (function($){
                  $('body').on( 'added_to_cart', function(){
                      // Test output on JS console
                      console.log('added_to_cart'); 
                      // Call Sweet Alert PopUp Here
                    swal(
                      'You added all the items!',
                      'Proceed to checkout?',
                      'success')
                  });
              })(jQuery);
          &lt;/script&gt;
      &lt;?php
  }
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  The Javascript works with the following is_page() IF statement. So the problem is the logic above where I am trying to count the amount of items in the shopping cart and see if they are equal to a value, <em>whilst</em> on the shop archive page. Can anyone suggest the correct Woocommerce code logic in order to do so?</p>
  
  <pre><code>if( is_page('leanshop'))    {
  </code></pre>