createTaxRate method

Future<WooTaxRate> createTaxRate(
  1. WooTaxRate taxRate, {
  2. bool? useFaker,
})

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 create
  • useFaker - When true, returns the input tax rate without API call

Returns

A Future<WooTaxRate> containing the created tax rate object with assigned ID.

Throws

  • WooCommerceException if 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);
}