return
Returns a value from a function or sends a response from HTTP, shipping-rate and function scripts. Stops script execution immediately after returning.
{% json response %}
{
"success": true,
"message": "Operation completed"
}
{% endjson %}
{% return response %}Syntax
{% return value %}Parameters
value
Yes
The value to return (variable, object, string, number, etc.)
Behavior
Immediately stops script execution
Sets the return value accessible to the caller
In functions: the returned value is output where the function was called
In HTTP scripts: the returned value becomes the response body
In shipping-rate scripts: the returned value defines the shipping rates
Only one value can be returned
Examples
Return from a function:
Return an object from a function:
Return simple values:
HTTP script response:
Shipping rates response:
Early return with validation:
Conditional return based on logic:
Return array data:
Return with computed values:
Use Cases
Functions
Return computed values to the calling script
HTTP Scripts
Send response body to the HTTP caller
Shipping Rate Scripts
Define available shipping rates and prices
Notes
Only one argument is allowed - you cannot return multiple values directly
To return multiple values, wrap them in an object using the
jsontagScript execution stops immediately after
return- code after it won't runIf no return is called in a function, the function returns
nullFor complex responses, always use
jsontag to structure the dataThe returned value from functions is a string - use
| parse_jsonif you need to access object properties in the caller
Last updated