Updating Woocommerce Product Attributes

I’m building a purchase order system for my Woocommerce store. Everything is working as expected except for product attributes. With my current code (shown below) the attributes are updated in the database and they show up in the product edit page, but my front end product search filter doesn’t show the updated attributes. I thought refreshing the lookup table would fix this, but so far it isn’t working. I’ve also cleared caches (browser and server) but no luck. When I change the attributes through the product edit page directly it works as expected, so I do think it has something to do with my code.

if (!empty($ov['attributes']) && is_array($ov['attributes'])) {
  $pairs = [];
  foreach ($ov['attributes'] as $key => $val) {
    $name = trim((string)$val);
    if ($name === '') continue;
    $attr_slug   = strtolower(str_replace('_', '-', $key));
    $tax         = function_exists('wc_attribute_taxonomy_name')
                    ? wc_attribute_taxonomy_name($attr_slug)
                    : 'pa_' . $attr_slug;
    if (!taxonomy_exists($tax)) continue;
    $pairs[] = [$tax, $name];
  }

  if ($pairs) {
    foreach ($pairs as [$tax, $name]) {
      $term = term_exists($name, $tax);
      if (!$term) {
        $res = wp_insert_term($name, $tax);
        if (!is_wp_error($res)) $term = $res;
      }
      if ($term && !is_wp_error($term)) {
        $term_id = is_array($term) ? (int)$term['term_id'] : (int)$term;
        wp_set_post_terms($product_id, [$term_id], $tax, false);
      }
    }

    $meta_attrs = get_post_meta($product_id, '_product_attributes', true);
    if (!is_array($meta_attrs)) $meta_attrs = [];

    foreach ($pairs as [$tax, $name]) {
      $meta_attrs[$tax] = array(
        'name'         => $tax,  
        'value'        => '',    
        'position'     => 0,
        'is_visible'   => 1,     
        'is_variation' => 0,     
        'is_taxonomy'  => 1
      );
    }

    update_post_meta($product_id, '_product_attributes', $meta_attrs);

    if (function_exists('wc_delete_product_transients')) {
      wc_delete_product_transients($product_id);
    }

    tsf_po_refresh_attribute_lookup( $product_id );
  }
}