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

Set Config

set_config is a special control-flow tag pair that lets you change CartThrob config/customer values at runtime using inline set_* commands (often inside conditionals).

It is designed to apply changes, save cart state, and reload the current URL so those changes are available on the next page render.

See also:

Variables

set_price_field

Sets the product price field mapping for a channel.

Supported params:

  • channel or channel_id (required)
  • field (required, or use value as fallback for field name)

    {set_price_field channel="products" field="sale_price"}

set_shipping_plugin

Sets cart shipping plugin config for this cart context.

Required param:

  • value (shipping plugin short name or prefixed name)

Implementation normalizes value by prefixing shipping_ and then setting: Cartthrob_shipping_{value}.

{set_shipping_plugin value="by_weight_ups_xml"}

set_customer_info

Sets a customer info field value in cart customer info.

Required params:

  • field
  • value

If field starts with customer_, that prefix is removed automatically before save.

{set_customer_info field="first_name"  value="Ace"}

set_CONFIG_NAME

Generic setter pattern:

{set_CONFIG_NAME value="..."}

If there is no dedicated set_config_CONFIG_NAME method, CartThrob falls back to:

  • cart->set_config(CONFIG_NAME, value)

This is useful for simple cart config keys where a direct value override is enough.

{set_number_format_defaults_prefix value="£"}

Behavior and Constraints

  1. This is a tag pair and uses only set_* variables inside its body.
  2. Tag parses EE conditionals using runtime data including:
    1. customer info (customer_* aliases included)
    2. cart info values
    3. segment variables
    4. global template variables
  3. Supported variable syntax:
    1. {set_name ...}
    2. {set_config_name ...}
  4. For each parsed set_* variable:
    1. if matching method exists (set_config_{name}), that method runs
    2. otherwise, if value exists, generic cart->set_config(name, value) is used
  5. Processed set_* variables are removed from output.
  6. Tag saves cart and redirects to the current URL so updates apply on the next render.
  7. Loop-prevention behavior:
    1. tag stores hash of processed tagdata in cart meta (set_config_hash)
    2. on immediate reload, matching hash short-circuits and clears hash
  8. Practical result: this tag is effectively a no-output configuration helper.
  9. set_customer_info can also push mapped values to member fields when:
    1. a member is logged in
    2. save_member_data config is enabled
    3. a matching member_{field}_field mapping exists

Examples

{exp:cartthrob:set_config}
{if group_id == 7}
{set_price_field channel="products" field="product_discounted_price"}
{if:else}
{set_price_field channel="products" field="product_price"}
{/if}
{/exp:cartthrob:set_config}

Set shipping plugin dynamically:

{exp:cartthrob:set_config}
    {if segment_3 == "express"}
        {set_shipping_plugin value="by_weight_ups_xml"}
    {/if}
{/exp:cartthrob:set_config}

Set customer info from template context:

{exp:cartthrob:set_config}
    {if logged_in}
        {set_customer_info field="customer_type" value="member"}
    {/if}
{/exp:cartthrob:set_config}