---
title: Tax classes
---

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

## Tax classes

### Creating a new tax class

```csharp

// Creates a new tax class object
TaxClassInfo newClass = new TaxClassInfo();

// Sets the tax class properties
newClass.TaxClassDisplayName = "New class";
newClass.TaxClassName = "NewClass";
newClass.TaxClassSiteID = SiteContext.CurrentSiteID;

// Saves the tax class to the database
TaxClassInfoProvider.SetTaxClassInfo(newClass);

```

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

### Updating a tax class

```csharp

// Gets the tax class
TaxClassInfo updateClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
if (updateClass != null)
{
    // Updates the tax class properties
    updateClass.TaxClassDisplayName = updateClass.TaxClassDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    TaxClassInfoProvider.SetTaxClassInfo(updateClass);
}

```

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

### Updating multiple tax classes

```csharp

// Gets all tax classes whose code name starts with 'NewClass'
var classes = TaxClassInfoProvider.GetTaxClasses().WhereStartsWith("TaxClassName", "NewClass");

// Loops through the tax classes
foreach (TaxClassInfo modifyClass in classes)
{
    // Updates the tax class properties
    modifyClass.TaxClassDisplayName = modifyClass.TaxClassDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    TaxClassInfoProvider.SetTaxClassInfo(modifyClass);
}

```

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

### Assigning tax classes to products and shipping options

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets a department
DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);

// Gets all products in the specified department
var products = SKUInfoProvider.GetSKUs().WhereEquals("SKUDepartmentID", department.DepartmentID);

// Gets a shipping option
ShippingOptionInfo shippingOption = ShippingOptionInfoProvider.GetShippingOptionInfo("NewOption", SiteContext.CurrentSiteName);

if (taxClass != null)
{
    if (department != null)
    {
        // Assigns the tax class as the default class of the specified department
        department.DepartmentDefaultTaxClassID = taxClass.TaxClassID;
        DepartmentInfoProvider.SetDepartmentInfo(department);
    }

    // Assigns the tax class to the specified products
    foreach (SKUInfo product in products)
    {
        product.SKUTaxClassID = taxClass.TaxClassID;
        SKUInfoProvider.SetSKUInfo(product);
    }

    if (shippingOption != null)
    {
        // Assigns the tax class to the specified shipping option
        shippingOption.ShippingOptionTaxClassID = taxClass.TaxClassID;
        ShippingOptionInfoProvider.SetShippingOptionInfo(shippingOption);
    }
}

```

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

### Deleting a tax class

```csharp

// Gets the tax class
TaxClassInfo deleteClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

if (deleteClass != null)
{
    // Deletes the tax class
    TaxClassInfoProvider.DeleteTaxClassInfo(deleteClass);
}

```

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

## Tax values for countries

### Setting a country tax value for a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");

if ((taxClass != null) && (country != null))
{
    // Creates a new object representing the tax class-country relationship
    TaxClassCountryInfo newTaxCountry = new TaxClassCountryInfo();

    // Sets the tax value for the given country within the tax class
    newTaxCountry.TaxClassID = taxClass.TaxClassID;
    newTaxCountry.CountryID = country.CountryID;
    newTaxCountry.TaxValue = 10;

    // Saves the changes to the database
    TaxClassCountryInfoProvider.SetTaxClassCountryInfo(newTaxCountry);
}

```

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

### Updating a country tax value of a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");

if ((taxClass != null) && (country != null))
{
    // Gets the object representing the tax class-country relationship
    TaxClassCountryInfo updateTaxCountry = TaxClassCountryInfoProvider.GetTaxClassCountryInfo(country.CountryID, taxClass.TaxClassID);
    if (updateTaxCountry != null)
    {
        // Updates the tax value for the given country in the tax class
        updateTaxCountry.TaxValue = 20;

        // Saves the changes to the database
        TaxClassCountryInfoProvider.SetTaxClassCountryInfo(updateTaxCountry);
    }
}

```

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

### Updating multiple country tax values of a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");

if ((taxClass != null) && (country != null))
{                   
    // Gets the objects representing the relationships between the given country and the tax class
    var classCountries = TaxClassCountryInfoProvider.GetTaxClassCountries()
                                                    .WhereEquals("TaxClassID", taxClass.TaxClassID)
                                                    .WhereEquals("CountryID", country.CountryID);

    // Loops through the tax class-country relationships
    foreach (TaxClassCountryInfo modifyClassCountry in classCountries)
    {
        // Updates the tax value for the country in the tax class
        modifyClassCountry.TaxValue = 30;

        // Saves the changes to the database
        TaxClassCountryInfoProvider.SetTaxClassCountryInfo(modifyClassCountry);
    }
}

```

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

### Deleting a country tax value of a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");

if ((taxClass != null) && (country != null))
{
    // Gets the object representing the tax class-country relationship
    TaxClassCountryInfo deleteTaxCountry = TaxClassCountryInfoProvider.GetTaxClassCountryInfo(country.CountryID, taxClass.TaxClassID);
    if (deleteTaxCountry != null)
    {
        // Deletes the tax value for the country
        TaxClassCountryInfoProvider.DeleteTaxClassCountryInfo(deleteTaxCountry);
    }
}

```

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

## Tax values for states

### Setting a state tax value for a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");

if ((taxClass != null) && (state != null))
{                   
    // Creates a new object representing the tax class-state relationship
    TaxClassStateInfo newTaxState = new TaxClassStateInfo();

    // Sets the tax value for the given state within the tax class
    newTaxState.TaxClassID = taxClass.TaxClassID;
    newTaxState.StateID = state.StateID;
    newTaxState.TaxValue = 10;

    // Saves the changes to the database
    TaxClassStateInfoProvider.SetTaxClassStateInfo(newTaxState);
}

```

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

### Updating a state tax value of a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");

if ((taxClass != null) && (state != null))
{                   
    // Gets the object representing the tax class-state relationship
    TaxClassStateInfo updateTaxState = TaxClassStateInfoProvider.GetTaxClassStateInfo(taxClass.TaxClassID, state.StateID);
    if (updateTaxState != null)
    {                       
        // Updates the tax value for the given state in the tax class
        updateTaxState.TaxValue = 20;

        // Saves the changes to the database
        TaxClassStateInfoProvider.SetTaxClassStateInfo(updateTaxState);
    }
}

```

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

### Updating multiple state tax values of a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");

if ((taxClass != null) && (state != null))
{                   
    // Gets the objects representing the relationships between the given state and the tax class
    var classStates = TaxClassStateInfoProvider.GetTaxClassStates()
                                                .WhereEquals("TaxClassID", taxClass.TaxClassID)
                                                .WhereEquals("StateID", state.StateID);

    // Loops through the tax class-state relationships
    foreach (TaxClassStateInfo modifyClassState in classStates)
    {
        // Updates the tax value for the state in the tax class
        modifyClassState.TaxValue = 30;

        // Saves the changes to the database
        TaxClassStateInfoProvider.SetTaxClassStateInfo(modifyClassState);
    }
}

```

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

### Deleting a state tax value of a tax class

```csharp

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");

if ((taxClass != null) && (state != null))
{
    // Gets the object representing the tax class-state relationship
    TaxClassStateInfo deleteTaxState = TaxClassStateInfoProvider.GetTaxClassStateInfo(taxClass.TaxClassID, state.StateID);
    if (deleteTaxState != null)
    {
        // Deletes the tax value for the state
        TaxClassStateInfoProvider.DeleteTaxClassStateInfo(deleteTaxState);
    }
}

```

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