---
title: Shipping options
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

### Creating a new shipping option

```csharp

// Creates a new shipping option object
ShippingOptionInfo newOption = new ShippingOptionInfo();

// Sets the shipping option properties
newOption.ShippingOptionDisplayName = "New option";
newOption.ShippingOptionName = "NewOption";
newOption.ShippingOptionSiteID = SiteContext.CurrentSiteID;
newOption.ShippingOptionEnabled = true;

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);
if (taxClass != null)
{
    // Sets the shipping option tax class
    newOption.ShippingOptionTaxClassID = taxClass.TaxClassID;
}

// Saves the shipping option to the database
ShippingOptionInfo.Provider.Set(newOption);

```

[> Back to list of examples](#toc)

### Updating a shipping option

```csharp

// Gets the shipping option
ShippingOptionInfo updateOption = ShippingOptionInfo.Provider.Get("NewOption", SiteContext.CurrentSiteID);
if (updateOption != null)
{
    // Updates the shipping option properties
    updateOption.ShippingOptionDisplayName = updateOption.ShippingOptionDisplayName.ToLower();

    // Saves the changes to the database
    ShippingOptionInfo.Provider.Set(updateOption);
}

```

[> Back to list of examples](#toc)

### Updating multiple shipping options

```csharp

// Gets all shipping options on the current site whose code name starts with 'NewOption'
var options = ShippingOptionInfo.Provider.Get()
                                        .OnSite(SiteContext.CurrentSiteID)
                                        .WhereStartsWith("ShippingOptionName", "NewOption");

// Loops through the shipping options
foreach (ShippingOptionInfo option in options)
{
    // Updates the shipping option properties
    option.ShippingOptionDisplayName = option.ShippingOptionDisplayName.ToLower();

    // Saves the changes to the database
    ShippingOptionInfo.Provider.Set(option);
}

```

[> Back to list of examples](#toc)

### Adding a new shipping cost to a shipping option

```csharp

/*
 * Note: The example only works correctly for shipping options that use shipping costs
 * stored in the COM_ShippingCost database table (includes all options based on the Default carrier).
 * You may need a different approach for shipping options of custom carriers.
*/

// Gets the shipping option
ShippingOptionInfo option = ShippingOptionInfo.Provider.Get("NewOption", SiteContext.CurrentSiteID);
if (option != null)
{
    // Creates a new shipping cost object
    ShippingCostInfo cost = new ShippingCostInfo();

    // Sets the shipping cost properties
    cost.ShippingCostMinWeight = 10;
    cost.ShippingCostValue = 9.9M;

    // Assigns the shipping option to which the shipping cost applies
    cost.ShippingCostShippingOptionID = option.ShippingOptionID;

    // Saves the shipping cost to the database
    ShippingCostInfo.Provider.Set(cost);
}

```

[> Back to list of examples](#toc)

### Removing a shipping cost from a shipping option

```csharp

/*
 * Note: The example only works correctly for shipping options that use shipping costs
 * stored in the COM_ShippingCost database table (includes all options based on the Default carrier).
 * You may need a different approach for shipping options of custom carriers.
*/

// Gets the shipping option
ShippingOptionInfo option = ShippingOptionInfo.Provider.Get("NewOption", SiteContext.CurrentSiteID);
if (option != null)
{
    // Gets the cost assigned to the shipping option for a specified weight (10)
    ShippingCostInfo deleteCost = ShippingCostInfoProvider.GetShippingCostInfo(option.ShippingOptionID, 10);
    if (deleteCost != null)
    {
        // Deletes the shipping cost
        ShippingCostInfo.Provider.Delete(deleteCost);
    }
}

```

[> Back to list of examples](#toc)

### Deleting a shipping option

```csharp

// Gets the shipping option
ShippingOptionInfo deleteOption = ShippingOptionInfo.Provider.Get("NewOption", SiteContext.CurrentSiteID);

if (deleteOption != null)
{
    // Deletes the shipping option
    ShippingOptionInfo.Provider.Delete(deleteOption);
}

```

[> Back to list of examples](#toc)
