createTaxRate method
Creates a new tax rate in the WooCommerce store.
This method creates a new tax rate with the specified configuration. The tax rate will be applied based on its geographical and tax class settings.
Parameters
taxRate- The tax rate object to createuseFaker- When true, returns the input tax rate without API call
Returns
A Future<WooTaxRate> containing the created tax rate object with assigned ID.
Throws
WooCommerceExceptionif the request fails or access is denied
Example Usage
final newTaxRate = WooTaxRate(
country: 'US',
state: 'CA',
rate: '8.25',
name: 'California Sales Tax',
);
final created = await wooCommerce.createTaxRate(newTaxRate);
Implementation
Future<WooTaxRate> createTaxRate(WooTaxRate taxRate, {bool? useFaker}) async {
final isUsingFaker = useFaker ?? this.useFaker;
if (isUsingFaker) {
return taxRate;
}
final response = await dio.post(
_TaxRateEndpoints.taxes,
data: taxRate.toJson(),
);
return WooTaxRate.fromJson(response.data);
}