Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

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.