WC_Tax::maybe_remove_tax_class_rates PHP Method

maybe_remove_tax_class_rates() public static method

When the woocommerce_tax_classes option is changed, remove any orphan rates.
public static maybe_remove_tax_class_rates ( string $old_value, string $value )
$old_value string
$value string
    public static function maybe_remove_tax_class_rates($old_value, $value)
    {
        $old = array_filter(array_map('trim', explode("\n", $old_value)));
        $new = array_filter(array_map('trim', explode("\n", $value)));
        $removed = array_filter(array_map('sanitize_title', array_diff($old, $new)));
        if ($removed) {
            global $wpdb;
            foreach ($removed as $removed_tax_class) {
                $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class = %s;", $removed_tax_class));
                $wpdb->query("DELETE locations FROM {$wpdb->prefix}woocommerce_tax_rate_locations locations LEFT JOIN {$wpdb->prefix}woocommerce_tax_rates rates ON rates.tax_rate_id = locations.tax_rate_id WHERE rates.tax_rate_id IS NULL;");
            }
            WC_Cache_Helper::incr_cache_prefix('taxes');
        }
    }