How can I adjust order waiting times based on weekdays?

Solved

How can I adjust order waiting times based on weekdays?

Timo_Krause
Excursionist
28 3 9

We use the trigger order created to notify us if no shipment has been made within 36 hours.

It goes something like this:

 

Order created >> wait 36 hours >> check for shipping >> send Slack message if no shipping.

 

But now we have the problem that our warehouse is not always working on weekends. Therefore we would like to have it something like this:

 

Order created >> Check for weekday (if order is created between Sunday and Thursday) >> Wait for 36 hours. But if the order was created between Friday and Saturday, wait e.g. 48 hours.

 

But I have not found out how to create a check based on weekdays,
Is it possible somehow?

Do not wait for success, it is the result of your actions || Warte nicht auf Erfolg, der ist das Ergebnis deines Handelns
Accepted Solution (1)

G-L
Shopify Staff (Retired)
29 4 10

This is an accepted solution.

Hi @Timo_Krause 

one way you could approach is would be to print the day of the week this order was created on using a variable that prints the day of week in a tag or metafield, and later check again for that same value to determine if it's a weekday or a weekend order:

 {{ order.createdAt | date: "%a" }}

You can use a wait step for a few seconds to make sure the condition is applied on the updated item.

This way you can have different paths to manage your shipping processes. 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 6 (6)

Jeff-Armstrong
Shopify Staff
35 3 3

Currently there is no way to check the current day of the week in Flow.

To learn more visit the Shopify Help Center or the Community Blog.

G-L
Shopify Staff (Retired)
29 4 10

This is an accepted solution.

Hi @Timo_Krause 

one way you could approach is would be to print the day of the week this order was created on using a variable that prints the day of week in a tag or metafield, and later check again for that same value to determine if it's a weekday or a weekend order:

 {{ order.createdAt | date: "%a" }}

You can use a wait step for a few seconds to make sure the condition is applied on the updated item.

This way you can have different paths to manage your shipping processes. 

To learn more visit the Shopify Help Center or the Community Blog.

CarmineT
Shopify Partner
96 2 32

At the moment of writing as in Flow can be inserted custom Javascript code this is possible indeed with a javscript code.

The following:

 

export default function main(input) {
const order = input.order;

// Parse the createdAt date
const createdDate = new Date(order.createdAt);
const dayOfWeek = createdDate.getUTCDay(); // Sunday = 0, Saturday = 6

// Check if createdAt is a weekend day (Saturday or Sunday)
const isWeekendOrder = dayOfWeek === 0 || dayOfWeek === 6;

return {
isWeekendOrder, // Boolean: true if created on a weekend
orderId: order.id, // Order ID
};
}

Yuka
Shopify Partner
11 1 0

If I understand correctly, after the `Run code` step we need to set up a condition that will establish different waiting times depending on the calculation result? This might be inconvenient as it would require duplicating the steps "check for shipping >> send Slack message if no shipping".

CarmineT
Shopify Partner
96 2 32

No, I mean, first the code into the run code(missing the input shape and output shape object in purpose, I would give in pm), is checking if the order is made on a weekend /weekday, it can be easy adapted as  dayOfWeek === 6 is Staturday.

 

There is no duplication in term of that if a condition is true, then proceed in a defined path, otherwise in another.

 

This is exactly what is been asked.

Yuka
Shopify Partner
11 1 0

I see that there is no duplication in the code itself. I meant that duplication exists in the steps following the “Run code” phase. The subsequent steps differ only in the waiting time. The “check for shipping” and “send Slack message if no shipping” steps are identical, regardless of whether the order is placed on a weekend or a weekday.

 

The duplication of these steps can also be eliminated by moving them into a separate workflow and invoking it from both branches of the condition.