💰 Magento 2 Tax Configuration – Set Up Taxes the Right Way
Taxes are critical for any eCommerce store operating across regions. Magento 2 offers a flexible tax system that can be configured by location, customer group, product type, and more. Let’s dive into how to configure it correctly!
🔧 How Magento 2 Handles Taxes
- Tax Rates – Defines percentage per region/postcode
- Tax Rules – Combines rates + customer groups + product classes
- Tax Zones – Matches location-specific rules
- Product Tax Classes – Assign to products
- Customer Tax Classes – Assign to customers/groups
⚙️ Step-by-Step: Creating a Tax Rate
Go to Stores > Tax Zones and Rates and click Add New Tax Rate.
// Programmatically create a tax rate
$taxRate = $this->taxRateFactory->create();
$taxRate->setCode('US-CA-Standard')
->setTaxCountryId('US')
->setTaxRegionId(12) // e.g., California
->setZipIsRange(0)
->setTaxPostcode('*')
->setRate(8.25)
->save();
🧩 Creating a Tax Rule
Tax rules are combinations of product tax classes, customer tax classes, and tax rates.
Navigate to Stores > Tax Rules > Add New Tax Rule.
// Create Tax Rule
$rule = $this->taxRuleFactory->create();
$rule->setCode('US-Standard')
->setTaxRateIds([$taxRate->getId()])
->setCustomerTaxClassIds([3]) // e.g., Retail
->setProductTaxClassIds([2]) // e.g., Taxable Goods
->setPriority(0)
->setPosition(0)
->setCalculateSubtotal(0)
->save();
🏷 Assign Product & Customer Tax Classes
Product tax class is set under Catalog > Products > [Product] > Tax Class.
Customer tax class is assigned via Customer Groups in Customers > Customer Groups.
📦 Tax Display & Calculation Settings
To control how tax is calculated and displayed:
- Go to Stores > Configuration > Sales > Tax
- Configure options like:
- Display Prices Including/Excluding Tax
- Apply Tax After Discount
- Shipping Tax Class
✅ Summary
- Create Tax Rates for locations
- Create Tax Rules by linking rates, customer & product classes
- Assign correct tax classes to products and customers
- Configure display settings in the Tax configuration
Magento 2 gives you powerful tools to comply with global tax requirements. Whether you’re selling in California or Canada, it scales with your business!