CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Get Shipping Options

get_shipping_options returns available shipping options from the active shipping plugin.

It can be used in two ways:

  1. As a single tag (no inner tagdata), which outputs a <select name="shipping_option">... element.
  2. As a tag pair, which loops through options so you can render custom markup.

See also:

Parameters

shipping_plugin

Optionally sets a specific shipping plugin before options are loaded.

shipping_plugin="shipping_flat_rates"

Use this when you need options from a specific plugin instead of the currently configured/active one.

variable_prefix

Adds a prefix to variables in pair output to avoid naming collisions.

variable_prefix="liverates_"

Example variable usage with prefix:

{liverates_rate_short_name}

hide_price

Single-tag mode only. Hides price text in generated <select> option labels.

hide_price="yes"

Without hide_price, labels are rendered like:

My Shipping Option - 0.00

id

Single-tag mode only. Sets <select> id.

id="shipping_option"

class

Single-tag mode only. Sets <select> class.

class="shipping-option-select"

onchange

Single-tag mode only. Sets <select> onchange attribute.

onchange="this.form.submit()"

extra

Single-tag mode only. Appends raw attributes to the generated <select>.

extra='data-role="shipping-options"'

Variables

rate_short_name

Short key for the shipping option.

{rate_short_name}

rate_title

Display title for the shipping option.

{rate_title}

price

Formatted price for the option in pair mode.

{price}

selected

Outputs selected="selected" when the option is currently selected.

{selected}

checked

Outputs checked="checked" when the option is currently selected.

{checked}

count

Current loop index (1-based) in pair mode.

{count}

total_results

Total number of shipping options in pair mode.

{total_results}

first_row

True on first option row in pair mode.

{if first_row}...{/if}

last_row

True on last option row in pair mode.

{if last_row}...{/if}

option_value

Alias of rate_short_name.

{option_value}

option_name

Alias of rate_title.

{option_name}

error_message

Shipping error text from cart custom data when available (most often with live-rate integrations).

{error_message}

Conditionals

{if no_results} can be used in pair mode when no rows are returned.

In complex nested form templates, many teams prefer checking shipping error state directly (for example via custom_data:shipping_error) to show explicit failure messages.

Example pattern:

{if custom_data:shipping_error}
    <p>There was a problem retrieving shipping rates.</p>
    <p>Error: {custom_data:shipping_error}</p>
{/if}

Behavior and Constraints

  1. If shipping_plugin is provided, that plugin is set before options are loaded.
  2. Selected option is resolved from shipping_info('shipping_option'), falling back to plugin default shipping option.
  3. Single-tag mode:
    • returns a complete <select name="shipping_option"> when options exist,
    • returns nothing (null) when no options are available.
  4. Pair mode:
    • loops through valid options (rate_short_name and rate_title required),
    • formats price,
    • provides selection helpers and loop metadata.
  5. If cart has custom_data:shipping_error, the tag returns error-oriented output path instead of normal options rendering.
  6. hide_price, id, class, onchange, and extra apply to single-tag mode (generated <select>) only.

Examples

Single tag (auto <select> output):

{exp:cartthrob:get_shipping_options}

Single tag with hidden prices and attributes:

{exp:cartthrob:get_shipping_options
    hide_price="yes"
    id="shipping_option"
    class="shipping-select"
    onchange="this.form.submit()"
}

Pair mode with custom <select>:

<select name="shipping_option">
    {exp:cartthrob:get_shipping_options}
        <option value="{rate_short_name}" {selected}>
            {rate_title} - {price}
        </option>
    {/exp:cartthrob:get_shipping_options}
</select>

Pair mode with variable_prefix:

{exp:cartthrob:get_shipping_options variable_prefix="liverates_"}
    {if liverates_count == 1}<select name="shipping_option">{/if}
        <option value="{liverates_rate_short_name}" {liverates_selected}>
            {liverates_rate_title} - {liverates_price}
        </option>
    {if liverates_count == liverates_total_results}</select>{/if}
{/exp:cartthrob:get_shipping_options}