custom checkout field to adjust order total

We want to add checkbox field at checkout that offers the customer "expedited order fulfillment", which when checked will add a flat fee surcharge in the order totals. Ideally this checkbox would appear in the "shipping options" section of checkout, and the surcharge would appear as a separate line item in the order totals. Is this possible? Would would be the best way of accomplishing this, or what are my best options to implement something like this?

We are using the custom shipping endpoint, and it is working great. I am not sure if we need to hook this custom field into the shipping endpoint or if it can operate separately. Please advise. Thank you.
Comments
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    Good question. It is possible to add in a checkbox which would toggle an additional fee for the customer - but we don't currently natively support adding additional line items into the totals area.

    There are two approaches you could take here. One would be to take a look at our snippet for gift wrapping, and utilise that to add the fee. The fee would then appear as an additional product in the cart: https://wiki.foxycart.com/v/2.0/snippets/gift_wrapping_checkbox_on_checkout

    The other approach would be to include that fee in the shipping rates you display to the user. You could set up the checkbox as being related to the shipping, so when the customer checks the checkbox, it triggers the rates to be re-calculated and passes in that checkbox as a custom field to your endpoint. You can then roll the surcharge into the returned rates and even change the labels of the shipping rates returned to note it's now expedited. Details on doing that can be seen in the "Passing custom fields" section on the wiki for the custom shipping endpoint: https://wiki.foxycart.com/v/2.0/shipping#custom_shipping_endpoint

    Actually a third outside-the-box approach. You can technically make a coupon increase the cart rather than decrease. If you set up the coupon to increase by your desired surcharge, the checkbox on the checkout could add that coupon to the cart automatically. That would get the surcharge included in the totals area, but may look a little weird mixed in with other normal decreasing coupons if you're using those too.
  • Cool! Thanks for the quick response @fc_adam. I think one of these approaches should work just fine. I'll take a look at the linked resources.
  • @fc_adam, one more question... is there any way to alter the way the custom shipping endpoint output is sorted? It defaults to sorting the results by price in ascending order, but we use multiple carriers and they all get jumbled up when sorted by price. Is it possible to sort by service ID? That way I could customize the sorting so that the rates for each carrier are grouped together.
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    Good question. We don't currently support changing the order of shipping rates from the default low-high price sorting. It should be possible to do some custom javascript coding there to update the order in the JSON and trigger a re-render of the shipping results block. You would probably want to run it on cart-shipping-options-update.done and checkout-shipping-options-update.done.
Sign In or Register to comment.