The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Autoselect default shipping option

In using custom code form this page:

I have:
rates.add(10001, 8, 'USPS', 'Priority');
if (cart['_embedded']['fx:shipment']['total_item_price'] >= 75) {
rates.filter(10001).price(0).service('Free USPS Priority Shipping');

This works properly, but the user has to select the shipping option even though there is only one. Some of the older code variants had an autoselect. How can I set this up where this shipping option is autoselected so they do not have to? Thanks!
  • fc_marijafc_marija FoxyCart Team
    Hi @yyhmsg -

    You can put a bit of code on the "custom footer" in the configuration page to auto-select the first rate (and in this case, the only rate). Copy the code in the that follows to your computer's clipboard and paste it into the "custom footer" text area in the templates configuration page (you may need to select "add custom header and footer code to your templates" to get it to appear).
    {% if context == "cart" or context == "checkout" %}
    FC.client.on("cart-shipping-options-update.done", autoSelectRate);
    FC.client.on("checkout-shipping-options-update.done", autoSelectRate);

    function autoSelectRate(params) {
    if (FC.json.context == "cart") {
    } else {
    {% endif %}
    Let us know if you need more detailed instructions for adding that snippet.
  • Awesome, works perfectly! Thanks!
  • Awesome thanks!
Sign In or Register to comment.