No worries! If you don’t see checkout.liquid or theme.js, here’s how you can find a suitable file to add the JavaScript code for selecting the fastest shipping option at checkout:
Follow these steps:
-
Go to online store, then themes.
-
Edit Code.
Look for JavaScript Files:
In the Assets directory, look for files that may contain JavaScript code. Common file names include:
-
theme.js.
-
custom.js.
-
scripts.js.
-
app.js.
-
Any other JavaScript files with similar names.
Adding the JavaScript Code:
Once you locate a JavaScript file (preferably theme.js or custom.js), follow these steps:
-
Open the file: Click on the file name to open it.
-
Scroll to the bottom: Go to the end of the file.
-
Insert the code: Copy and paste the following JavaScript code:
document.addEventListener('DOMContentLoaded', function() {
const shippingOptions = document.querySelectorAll('input[name="shipping_method"]');
shippingOptions.forEach(option => {
if (option.value.includes('DHL Next Day Delivery')) { // Replace with the exact value of your shipping option
option.checked = true; // Set it as checked
}
});
});
-Make sure to replace “DHL Next Day Delivery” with the exact value of your shipping method as it appears in your checkout.