register_hooks(); } } /** * Register all tax rate-related hooks. * * Registers hooks for tax rate CRUD operations fired by WC_Tax class. * * @return void */ private function register_hooks(): void { add_action( 'woocommerce_tax_rate_added', array( $this, 'handle_woocommerce_tax_rate_added' ), 10, 1 ); add_action( 'woocommerce_tax_rate_updated', array( $this, 'handle_woocommerce_tax_rate_updated' ), 10, 1 ); add_action( 'woocommerce_tax_rate_deleted', array( $this, 'handle_woocommerce_tax_rate_deleted' ), 10, 1 ); } /** * Handle the woocommerce_tax_rate_added hook. * * @param int $tax_rate_id The tax rate ID. * * @return void * * @since 10.6.0 * * @internal */ public function handle_woocommerce_tax_rate_added( $tax_rate_id ): void { $this->invalidate( (int) $tax_rate_id ); $this->invalidate_tax_rates_list(); } /** * Handle the woocommerce_tax_rate_updated hook. * * @param int $tax_rate_id The tax rate ID. * * @return void * * @since 10.6.0 * * @internal */ public function handle_woocommerce_tax_rate_updated( $tax_rate_id ): void { $this->invalidate( (int) $tax_rate_id ); $this->invalidate_tax_rates_list(); } /** * Handle the woocommerce_tax_rate_deleted hook. * * @param int $tax_rate_id The tax rate ID. * * @return void * * @since 10.6.0 * * @internal */ public function handle_woocommerce_tax_rate_deleted( $tax_rate_id ): void { $this->invalidate( (int) $tax_rate_id ); $this->invalidate_tax_rates_list(); } /** * Invalidate the tax rates list version string. * * Called when tax rates are added, updated, or deleted, * as these operations affect collection/list endpoints. * * @return void */ private function invalidate_tax_rates_list(): void { wc_get_container()->get( VersionStringGenerator::class )->delete_version( 'list_tax_rates' ); } /** * Invalidate a tax rate version string. * * @param int $tax_rate_id The tax rate ID. * * @return void * * @since 10.6.0 */ public function invalidate( int $tax_rate_id ): void { wc_get_container()->get( VersionStringGenerator::class )->delete_version( "tax_rate_{$tax_rate_id}" ); } }