Checkout Page: How do I set the default value for the Shipping Options dropdown?

Do you know how to set a default value for the Shipping Option dropdown. We only have one options, so I don’t want the user to have to select anything.

I tried this code, but it doesn’t work. You can see that the shipping option changes, but then it changes back quickly to “Please select”.

<script>
    var mySelect = document.getElementById("cart_shipping").querySelectorAll("select"); 
    mySelect[0].value = "7361027874612051983";
</script>

The code you have will likely work, but I think what is happening is that your script is running just before the Treepl eCommerce script is updating the shipping in the background.

One quick way to deal with this (although not a great option) is to use a timeout/delay to run your script ‘hopefully’ after the Treepl code finishes, eg:

<script>
    setTimeout(function(){ 
        var mySelect = document.getElementById("cart_shipping").querySelectorAll("select"); 
        mySelect[0].value = "7361027874612051983";
    }, 3000);   <!-- time in milliseconds -->
</script>

Alternatively (but still using a setTimeout), you can use the new Treepl eCommerce triggers to change the shipping option:

<script>
    setTimeout(function(){ 
        var trigger = new Event("CMS_TriggerChangeShippingOption");
        trigger.data = {
            "Value": "7361027874612051983"
        };
        document.dispatchEvent(trigger);
    }, 3000);   <!-- time in milliseconds -->
</script>