title: Woocommerce - Show total weight as quantity increases on archive
body: <p>I found a code snippet on <a href="https://reigelgallarde.me/programming/show-product-price-times-selected-quantity-on-woocommecre-product-page/" rel="nofollow noreferrer">Regiel Gallarde's</a> website that displays in a div the total price according to quantity field update. I used this as a base to write a snippet that does the same stuff but with the price and on the archive. I ended up with this:</p>
  <pre><code>add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_total_product_weight', 31 );
  function woocommerce_total_product_weight() {
      global $woocommerce, $product;
      // let's setup our divs
      echo sprintf('&lt;div id=&quot;product_total_weight&quot; style=&quot;margin-bottom:20px;&quot;&gt;%s %s&lt;/div&gt;',__('Peso total:','woocommerce'),'&lt;span class=&quot;weight&quot;&gt;'.$product-&gt;get_weight().'&lt;/span&gt;');
      ?&gt;
          &lt;script&gt;
              jQuery(function($){
                  const weight = &lt;?php echo $product-&gt;get_weight(); ?&gt;
                      /*weight_unit = get_option('woocommerce_weight_unit'),*/
  
                  $('[name=quantity]').change(function(){
                      if (!(this.value &lt; 1)) {
  
                          const product_total_weight = parseFloat(weight * this.value);
  
                          $('#product_total_weight .weight').html(product_total_weight.toFixed(2));
  
                      }
                  });
              });
          &lt;/script&gt;
      &lt;?php
  }
  </code></pre>
  <p>It manages to show the weight for each product on the archive page but crashes when I update the quantity selector.</p>
  <p>Does anyone know what is wrong with my approach?</p>
  <p>Thanks a lot in advance</p>