updateTaxRate method

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

Updates an existing tax rate in the WooCommerce store.

This method updates an existing tax rate with new configuration. The tax rate must have a valid ID to be updated.

Parameters

  • taxRate - The tax rate object with updated information
  • useFaker - When true, returns the input tax rate without API call

Returns

A Future<WooTaxRate> containing the updated tax rate object.

Throws

  • WooCommerceException if the request fails or access is denied

Example Usage

final updatedTaxRate = WooTaxRate(
  id: 123,
  country: 'US',
  state: 'CA',
  rate: '9.25', // Updated rate
  name: 'California Sales Tax',
);
final result = await wooCommerce.updateTaxRate(updatedTaxRate);

Implementation

Future<WooTaxRate> updateTaxRate(WooTaxRate taxRate, {bool? useFaker}) async {
  final isUsingFaker = useFaker ?? this.useFaker;

  if (isUsingFaker) {
    return taxRate;
  }

  final response = await dio.put(
    _TaxRateEndpoints.singleTax(taxRate.id!),
    data: taxRate.toJson(),
  );

  return WooTaxRate.fromJson(response.data);
}