View Full Version : Script to calculate shipping fee for PayPal

Mar 26th, 2009, 11:48 PM
I'm looking for a script to calculate the shipping fee.
This fee plus the amount of goods times the price of the goods (I only sell a single product with a fixed price) is the total price to be paid.
This total amount should be passed to PayPal.

You can build a standard piece of code for the PayPal button on the PayPal website but I need to go beyond a fixed shipping amount. The shipping charge depends on (1) the order size and (2) the country of destination. Unfortunately, you can only pass a fixed shipping amount through the button code that the PayPal website generates. If you wanted to go beyond this you would need to write a script on your site to calculate the shipping and pass the amount to PayPal.

Could someone perhaps help me with this?

Mar 27th, 2009, 12:54 AM
You said that you are going to sale just one (the same) product, so why bother with size?
Most web sites calculate the price by zip code, or by country. You can calculate the middle cost to ship your product to certain country and to every zip code in US for example. And than you would have a drop box (as an example) with all the possibilities. You will need little JavaScript help to change the price as you change the drop box value.

Mar 27th, 2009, 01:11 AM
The reason I need size is that the customer can order multiple copies of the book I'm selling, which can make quite a difference (in the Netherlands) when it comes to shipping costs.
I don't have much html-coding skills but what I am capable of doing is making a form in which the customer can fill in the quantity and I can make a drop box as you suggest. What I can't do is (1) make a field that automatically calculates price*quantity, (2) a field that automatically calculates total costs, i.e., the costs for the book(s) plus shipping costs, and (3) to integrate it with the PayPal button so that PayPal charges the customer the total amount as calculated above.

Mar 27th, 2009, 01:18 AM
Those will require ether JavaScript or any other server side programming languages to write a small app that would calculate this for you. That's (http://www.earlyimpact.com/productcart/shipping_component.asp) what I found from small research. I am sure you can find couple useful scripts and web sites that would do that for you.

Mar 27th, 2009, 02:15 AM
I have made a drop down box that calculates the shipping costs. It reads as follows:

<form action="--WEBBOT-SELF--" method="POST">
<p><select size="1" name="Shippingcosts">
<option value="8.00">The Netherlands</option>
<option value="12.00">Europe</option>
<option value="18.00">Rest of World</option>

Next, the coding of the PayPal button has a line reading as follows:
<input type="hidden" name="shipping" value="444.00">

This line calculates the shipping costs as a flat fee of 444 euros.
I would like to replace this value with the value that is selected from the drop-down box. How can I do this?

I thought that this would perhaps be possible by changing the line into:
<input type="hidden" name="shipping" value="Shippingcosts">

However, this generates an error message stating that the amount is incorrect. Any suggestions how I can change the line in such a way that the shipping value is taken from the dropdown box?

Mar 27th, 2009, 06:58 AM
I don't know JavaScript, but you can set up a different PayPal pages for different countries, and than every drop box value will lead to different page. It not practical, but this is an option:

<form name="dropdown">
<select name="list" accesskey="S">
<option selected>Please your destination</option>
<option value="http://paypal.com/usa/price">USA</option>
<option value="http://paypal.com/canada/price">Canada</option>
<option value="http://paypal.com/mexico/price">Mexico</option>
<input type="button" value="Purchase" onclick="goToNewPage(document.dropdown.list)">

Or do the onChange command that will change the value on drop box value:

<select accesskey="S" onchange="goToPage(this.options(this.selectedIndex).value)">
<option selected>Please select one</option>
<option value="8.00">The Netherlands</option>
<option value="12.00">Europe</option>
<option value="18.00">Rest of World</option>

As I said I don't know JavaScript, so I don't know how to write more advanced script, but this might cover your need.

And if you need help with writing JavaScript you might want to ask in JS forum (http://codingforums.com/forumdisplay.php?f=2).
Hope this will help you out.