Add special handling charge to cart totals
Some of the products that our client sells are classified as hazardous materials and so they must be shipped by ground on a special truck. So if a customer adds one or more of these products to their cart, we needed to add an additional flat handling fee of $20 to the shopping cart totals. Regardless of how many of these products are added to the cart, the handling charge would remain $20 per cart. So using the shipping_freight field in the products table would not work since it▓s designed to be incremented each time an additional product is added.
Here▓s the procedure for the solution we came up with: Step 1: Add an extra field: handling_special Default value: (leave blank) Show: Dont check (Doesn▓t really matter, since this is going to be used only in the codework.) Step 2: Create new label: Variable: lbl_handling_special Description: Special Handling Value: Special Handling Step 3: The client wanted to track the special handling cost separate from shipping costs so we created a new field in the ⌠xcart_orders■ table called ⌠handling_special■ using the same definition parameters as the field ⌠shipping_cost■. Later, we▓ll need to modify the INSERT query in func_place_order within func.php to save this new value. Step 4: You will be editing these files: (remember to make backup copies of these files before you make any changes) 1. /include/func.php 2. /skin1/customer/main/cart_totals.tpl 3. /skin1/main/order_info.tpl 4. /skin1/mail/order_data.tpl Edit: /include/func.php In Function: func_calculate_shippings Add this code under other initial definition statements: Code:
$handling_special = 0; In Function: func_calculate_shippings Add this code just before the closing bracket of the code: foreach($products as $k=>$product) { Code:
$int_hdl = func_query_first("SELECT * FROM $sql_tbl[extra_field_values] ALERT: The value ⌠3■ that is hard coded in the query statement above for fieldid is the value that xcart defined for the extra_field when it was created in step 1. You may need to change that value. Look at the xcart_extra_fields table to see what the value is for the extra field you create. In Function: func_calculate_shippings Add this code before: return $return; (this allows the skin1/customer/main/cart_totals.tpl file to retrieve this value.) Code:
$return["handling_special"] = $handling_special; In function: func_calculate_single Revise: Code:
$total = $discounted_subtotal + $shipping_cost + $total_tax; Code:
$total = $discounted_subtotal + $shipping_cost + $total_tax + $handling_special; In function: func_calculate_single Add this code after: "shipping_cost"=>price_format($shipping_cost), (This allows skin1/main/order_info.tpl to retrieve the value of the new handling charge.) Code:
"handling_special"=>price_format($handling_special), In function: func_select_order Add this code just above: return $order; which is located near the end of the function (This allows skin1/main/order_info.tpl to retrieve the value of the new handling charge.) Code:
$order["display_handling_special"] = $order["handling_special"]; In function: func_place_order Add: handling_special to the first part of query statement as shown here: Code:
db_query("INSERT INTO $sql_tbl[orders] (login, membership, total, giftcert_discount, (This will now save the special handling charge in the xcart_orders table along with the other order information.) Code:
VALUES ('".addslashes($userinfo["login"])."', '".addslashes($userinfo["membership"])."', Edit: skin1/customer/main/cart_totals.tpl Add the following code wherever you want the special handling charge to be displayed within the cart totals: Code:
{if $handling_special ne ""} Edit: skin1/main/order_info.tpl Add this code after sub total amount: (This will display the new special handling charge when the customer and administrator view the order history.) Code:
{if $order.display_handling_special gt 0} Edit: skin1/mail/order_data.tpl Add this code above the line showing shipping cost: (This will show special handling charge in emails that are sent to customer and administrator.) Code:
{if $order.display_handling_special gt 0} |
Re: Add special handling charge to cart totals
Very nice! Exactly what I was looking for.
I modified your scenario to one where the store charges a flat transaction fee per order. Thanks for taking the time to post this. |
Re: Add special handling charge to cart totals
How would you charge a handling fee only if the order total is less than a certain amount?
|
Re: Add special handling charge to cart totals
I don't think you can do what you want in the markup feature under shipping charges. I believe you'd need to modify the code in /include/func.php. Use a conditional statement to check the cart total and if that total is below a specific dollar amount then you'd add the extra handling fee to the total.
Try this... In function: func_calculate_single After this code: $total = $discounted_subtotal + $shipping_cost + $total_tax; Add: Code:
if ($total < 100) If you need the extra handling fee to show up as a line item in the cart totals for the shopping cart, invoices, order history and confirmation emails, then you'd need to do extra programming similar to my original example. I think I've seen other posts discussing what you want to do so try doing a search. There may be a better way than what I'm suggesting. |
Re: Add special handling charge to cart totals
Has anyone tried this recently? I followed the steps exactly, and my total cost includes the handling, but the handling cost does not show up on the order information. It is like the tpl files are being passed a $handling_special that is NULL, but when I look in the orders table, the correct value is there.
I even tried removing the {if $handling_special ne ""}, but all it showed then was a "$" and no value. It displays when I log into the administrative end to check the order, but does not show up upon checkout or the email invoice. I wonder if some other xcart updates have made this procedure outdated. I did realize that func.php is now split into func.order.php and func.cart.php with their respective functions. Any comments would be greatly appreciated!!! |
Re: Add special handling charge to cart totals
Phew! I resolved the issue using the following:
Edit: skin1/customer/main/cart_totals.tpl Add the following code wherever you want the special handling charge to be displayed within the cart totals: Code:
{if $cart.display_handling_special gt 0} --- ALSO --- Edit: skin1/mail/html/order_data.tpl Add this code above the line showing shipping cost: (This will show special handling charge in emails and invoices that are sent to customer and administrator.) Code:
{if $order.display_handling_special gt 0} |
Re: Add special handling charge to cart totals
Hmm I wounder if this could be used to add extra charge for different type of payment ways in 4.018?
|
Re: Add special handling charge to cart totals
ok...i was wondering if anyne had an idea to make this work in this scenario. I want to charge a "handling fee" in a way only for international orders. Actually, the fee is for a gov't import certificate that i have to purchase for international orders.
Is there a way to write a conditional statement to check which shipping zone this customer is in before adding this "handling fee"? THanks Otis |
Re: Add special handling charge to cart totals
Yes, I believe that would be possible. Although I haven't checked it myself, I think the variable for the shipping zone for the customer is "$customer_zone" which you would use in the conditional statement.
if ($customer_zone == 122) $handling_fee = 20.0; |
Re: Add special handling charge to cart totals
Any idea how this modification can be used to add a 'handling fee' to certain payment methods?
Thanks! :D |
Re: Add special handling charge to cart totals
Quote:
definitely, you need to write a custom code to apply the fee for specific payment methods. |
Re: Add special handling charge to cart totals
Thanks for your message, Dongan.
Any suggestion how this custom code would look? 8O |
Re: Add special handling charge to cart totals
Quote:
if you are able to understand and do basic programming, we can give some tips to implement. otherwise, i would recommend to get quote from the developers, proceed further. |
Re: Add special handling charge to cart totals
It's always worth trying, so tips are very welcomed, Dongan!
Thanks in advance! :D |
Re: Add special handling charge to cart totals
Nice mod. But it seems this works on x-cart 4.0.x
Has anyone tried to modify this for x-cart 4.1.x? I need to add the facility to my x-cart, where, I can add handling charges per order for specific products, irrespective of the number of items purchased. |
Re: Add special handling charge to cart totals
Quote:
Does anyone know if this is do-able in 4.1.10?? Thanks! |
Re: Add special handling charge to cart totals
I like this solution.
Is there a way to easily assign different charges based on the shipping method? (ie. FedEx Ground =$30.00, International Economy=$50.00, etc.) Thanks Steve |
Re: Add special handling charge to cart totals
Great info :)
Has anyone tried this in 4.4.x ? Or can post different files (if any) that will need modify? Also can we use extra_field value as the amount to be charged extra? Any tips would be greatly appreciated. |
Re: Add special handling charge to cart totals
Seems like func.php does not exist anymore :(
I see now there is a folder called "func" with bunch of func_xxx files. Can anyone suggest which files will need this changes for 4.4.2 ? Thanks. |
Re: Add special handling charge to cart totals
func.order.php is the one for orders functions
|
Re: Add special handling charge to cart totals
Quote:
Thank you Steve :) I actually followed instructions and got it to work in Gold 4.4.2 but my situation is a bit different. We have extra field that certain products use (extra charge) and so far it works if one product is added to the cart but if you add two or more products it pulls only one extra field value (extra charge). It needs to add this field value for each product in the cart. I played with the code adding foreach ( but no luck. Here is the sample code: PHP Code:
Thanks for your help. |
Re: Add special handling charge to cart totals
Because your code assigns new value to $handling_special with each loop without adding the old one to the cart. You need to also include in the foreach code to add the value to cart if any then go to the next one. Something like
foreach ($int_hdl as $handling_special) { $handling_special = field_value; cart_total += $handling_special; } } replace cart_total with the actual cart total field (or the field you are adding value to) |
Re: Add special handling charge to cart totals
Quote:
Thank you so much Steve for taking time to look at this, it's a headache. I actually got it to calculate subtotal that includes these extra charges with this code : PHP Code:
but for some reason if I add product that does not have the extra field, it adds extra charge to it as well and than ads discounted total line, subtracts one extra charge. Than at the end shows total plus one extra charge. Seems like the code needs to be somewhere where it calculates $product price, I don't know. |
Re: Add special handling charge to cart totals
That's way I had the code added inside the foreach loop so it will execute only if the foreach executes - so only if the added product has this extra field value
|
Re: Add special handling charge to cart totals
Quote:
Man, it's so close but still adds this charge for all items including item that does not have this extra field. This is the code again (keeping $subtotal inside foreach loop: PHP Code:
This is placed just before the closing bracket of the code: foreach($products as $k=>$product) { - as instructed by the author of this post even tho he states it is in "In Function: func_calculate_shippings" but in xcart 4.4.2 code is a lot different, so maybe this code needs to go in different place?? Or some of the code in other places (as he instructs to put) needs also foreach loop??? I really appreciate all you help Steve. |
Re: Add special handling charge to cart totals
Then there is soemthign wrong in the above code - you need to debug it and print every value/array to make sure all is adding properly. Could be your sql, could be the foreach you are using
|
Re: Add special handling charge to cart totals
Quote:
Hey Steve, I sent you an email this morning "Re: Add special handling charge to cart totals", please take a look when you have a minute. Thanks. |
Re: Add special handling charge to cart totals
Replied
|
Re: Add special handling charge to cart totals
I just wanted to thank everyone that posted here but mostly Steve as he ended up doing this modification for us and we can't be more happy with his work. Professional, fast and very reasonable rates. I would recommend him to anyone looking for x-cart modification.
Thanks. |
Re: Add special handling charge to cart totals
I've got this working in my store for good classified as dangerous goods.
We want to add $40 charge including tax. So I have set the value of $handling_special to be 36.36 which is working well, however I also need to know where to put the code to add the 10% tax to this. We offer free freight on all orders over $200 so adding the $handling_special charge to the shipping value is pointless as it gets set back to zero when the order gets over $200. Any help much appreciated. |
Re: Add special handling charge to cart totals
Hello,
I tried to do this for X-Cart 4.5.2 Gold but the handling special charge will just not show up on checkout. Has anyone got this code working for X-Cart 4.5.2 Gold or can anyone please share some thoughts on how to make this work for X-Cart 4.5.2 Gold. Thanks. |
Re: Add special handling charge to cart totals
Anybody no answer for this?
|
Re: Add special handling charge to cart totals
Is there a 4.6.1 solution to this?
Steve |
Re: Add special handling charge to cart totals
Quote:
Also, for 4.6.x? |
All times are GMT -8. The time now is 01:17 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.