Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Rename local delivery option in one-page checkout

jamalali81
Shopify Partner
17 0 1

We offer local delivery to our customers but want to rename the option that appears on one-page checkout. I have implemented this tutorial (I have only removed the zip code filter) and it does rename the standard delivery option but not the local delivery one.

 

Here is my code:

export function run(input) {
const message = "May be delayed due to weather conditions";

let toRename = input.cart.deliveryGroups
.flatMap(group => group.deliveryOptions)
.map(option => ({
rename: {
deliveryOptionHandle: option.handle,
title: option.title ? `${option.title} - ${message}` : message
}
}));

return {
operations: toRename
};
};

 

Here is a screenshot of the checkout page:

Screenshot 2024-01-02 at 22.45.15.png

 

Here is a screenshot of the function run details:

Screenshot 2024-01-02 at 22.44.58.png

Replies 2 (2)

Liam
Shopify Staff
2616 281 718

Hi Jamalali81,

 

I believe you'll need to modify your existing code to target the specific local delivery option, by applying a condition that checks if the current delivery option is indeed the local delivery option. You may need to target the local delivery option handle specifically - if you're not sure of the handle, you can temporarily log the handles to the console to find out:

 

input.cart.deliveryGroups
.flatMap(group => group.deliveryOptions)
.forEach(option => console.log(option.handle));

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

jamalali81
Shopify Partner
17 0 1

Hi @Liam, thanks for replying.

 

In the function run details screenshot, the Output section shows the option.handle in the rename operation. Is that not the correct way to do it? Do you have a link to the docs with more details as to how this works? Thank you!