{% liquid
# If the destination looks like a PO Box, DO NOT offer Express—only Standard.
# --- editable settings ---
assign currency = "USD"
# Standard
assign std_service_name = "Standard Shipping"
assign std_service_code = "STANDARD"
assign std_description = "Ground service"
assign std_price = 899 # cents
# Express
assign exp_service_name = "Express Shipping"
assign exp_service_code = "EXPRESS"
assign exp_description = "2-day service"
assign exp_price = 1999 # cents
# --- logic ---
assign addr1 = shopify_rate_check.destination.address1 | downcase
assign is_po_box = false
if addr1 contains "po box" or addr1 contains "p.o. box" or addr1 contains "p o box" or addr1 contains "po-box"
assign is_po_box = true
endif
# Always offer Standard
assign rate = rate | merge: "currency", currency
assign rate = rate | merge: "service_name", std_service_name
assign rate = rate | merge: "service_code", std_service_code
assign rate = rate | merge: "total_price", std_price
assign rate = rate | merge: "description", std_description
assign rates = rates | array_append: rate
# Offer Express only if NOT a PO Box
unless is_po_box
assign rate = nil
assign rate = rate | merge: "currency", currency
assign rate = rate | merge: "service_name", exp_service_name
assign rate = rate | merge: "service_code", exp_service_code
assign rate = rate | merge: "total_price", exp_price
assign rate = rate | merge: "description", exp_description
assign rates = rates | array_append: rate
endunless
%}
{
"rates": {{ rates | array_wrap | json }}
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article