Get Shipping Options

This tag pair outputs available shipping options. For instance, it will return available options used in conjunction with the shipping plugin called "Customer Selectable Flat Rates". The information it returns varies by shipping plugin.

Table of Contents

Parameters

shipping_plugin

You can output rates for the specific shipping plugin set in the setting by passing in the short_name of your chosen shipping plugin. The short_name for the shipping plugin can be found on its configuration page. This is really only useful when using multiple live rates plugins (which are not included with CartThrob by default.)

shipping_plugin="fedex_live_rates"
variable_prefix

Allows you to add a prefix to all variables within the tag to avoid variable collisions with another tag.

variable_prefix="my_var"

This is an example of how you could then call the entry_id variable within the tag.

hide_price

This only applies if using the "single" version of the tag. (not when using the tag pair). By default the single tag outputs the shipping method's title & price. If you want to hide the price, use

hide_price="yes"

If unset, the price will be shown like so: My Shipping Option - 0.00

Variables

rate_short_name

Short name of the shipping option.

{rate_short_name}

rate_title

Long (descriptive) title of a shipping option.

{rate_title}

price

Cost of the shipping option.

{price}

selected

This outputs selected="selected" if that shipping option is chosen. For use in drop-down list.

{selected}

checked

This outputs checked="checked" if that shipping option is chosen. For use in radio groups.

{checked}

count

This tag, when used as a tag pair will output content in a looping fashion. Count is the current loop number.

{count}

total_results

When this tag is used as a variable pair, this outputs the total amount of shipping options available.

{total_results}

error_message

Outputs any error messages (usually only used with Live Rates shipping plugins)

{error_message}

Conditionals

Though no_results will work with this tag when used by itself, as soon as you put it within another CartThrob form, EE will find content within the system and won't ouput no_results even if there are no shipping data being returned. Instead, you may want to try the following:

{exp:cartthrob:update_cart_form  return="store/checkout"} 

        {if custom_data:shipping_error}
            <p>There is a problem retrieving shipping rates from the shipping company. Please try again in a moment or contact us for assistance.</p>
            <p>Error: {custom_data:shipping_error}</p>
        {if:else}
            <label for="shipping_option" class="forSelect">Shipping Option</label>
            {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}

                {if error_message}{error_message}{/if}

            {/exp:cartthrob:get_shipping_options}
        {/if}
        <input type="submit"  class="cartButton" value="Next &raquo; "/>

{/exp:cartthrob:update_cart_form}

Examples

Used singly:

{exp:cartthrob:get_shipping_options} will automatically output a select input field.

Using as a tag pair:

<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>