PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Calculate Shipping based on Quantity

  1. I have been trying to figure out how to Calculate a Shipping cost based on Quantity and I think I have found a solution using jQuery. Here it is if anyone wants to use it or optimize it:

    $('.ginput_quantity').keyup(function() {
    		var sum = 0;
    		$('.ginput_quantity').each(function() {
    			sum += Number($(this).val() * .50);
    		});
    
    		$('.gfield_shipping .gform_hidden').attr('value',parseFloat(sum).toFixed(2));
    	});

    I have a list of Products with the Quantity field attached (by default) and want to add a $.50 cent per Quantity shipping cost to the total order. This jQuery snippet adds the total Quantity value and multiplies it by .5 and then places that value in the hidden input of the Shipping field.

    Since I am a newbie at jQuery, I'm sure there is a better to do this and would love to hear about it.

    Thanks

    Posted 13 years ago on Thursday August 25, 2011 | Permalink
  2. I have noticed that this will not work unless I include a USD symbol within the value of the hidden shipping input field. I am receiving a validation error of an invalid value.

    Any ideas on how to fix this?

    Posted 13 years ago on Friday August 26, 2011 | Permalink
  3. Well, I have successfully added a USD symbol to the value of the hidden shipping input field, but I still am receiving a validation error for a Valid Value. I don't know why. Any ideas?

    Posted 13 years ago on Friday August 26, 2011 | Permalink
  4. Can you post a link to your page with the form in it?

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  5. Here is the page: http://www.bankstreettheater.com/beta/prices/gift-cards/

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  6. Hi Katart,

    Most likely the issue is that although you are changing the shipping price on the front end, Gravity Forms does not know that the shipping price has been updated. You need to update this dynamically in the backend as well using the gform_product_info hook. You will see that all of the $product_info is passed to this hook and can be modified as needed. This includes the shipping price.

    Posted 13 years ago on Monday August 29, 2011 | Permalink
  7. Thanks for the response David. Using hooks is very new to me, but I am always up for a challenge. Does this mean I can eliminate my jQuery calculations and let the hooks to the work, or is it a bit of both?

    I'm not sure where to start, but I guess I should start reading about WP hooks.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  8. Hi Katart,

    You will need to keep what you've done with the front end code. We do have some javascript hooks, but none that will accomplish what are you trying to do. The backend hooks provide support for what you've done on the front end to the the backend.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink