title: Saving product attributes with Woocommerce methods not syncing to front end
body: <p>This is not a duplicate question.</p>
  <p>The problem here is not adding the attributes per say. The problem is associating the added attribute options with the proper terms I guess. As can be seen in the pictures below, the attribute options are set correctly but they are not associated with their terms (as seen in picture one [text instead of the gray background attribute option as seen in picture three]) even though I manually run set_object_terms for each product and the relationship is set properly in the database.</p>
  <pre><code>foreach($terms as $term_id) {
      $term = get_term( $term_id );
      $term_name = $term-&gt;name;
      $term_taxonomy = $term-&gt;taxonomy;
      $term_slug = $term-&gt;slug;
                              
      if( ! has_term( $term_name, $term_taxonomy, $parent_id ) ) {
          $set_terms = wp_set_object_terms($parent_id, $term_slug, $term_taxonomy, true );
      }
                              
  }
  </code></pre>
  <p>While working on transferring some attributes from one database to another I'm facing an issue with the fact that attributes are being transferred correctly but they are saved in text form...</p>
  <p><a href="https://i.stack.imgur.com/jDoQt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jDoQt.jpg" alt="enter image description here" /></a></p>
  <p>and I need to manually click &quot;Save attributes&quot; in wordpress admin &gt; product edit...</p>
  <p><a href="https://i.stack.imgur.com/XSqHH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XSqHH.jpg" alt="enter image description here" /></a></p>
  <p>for it to actually register correctly in the system as can be seen here.</p>
  <p><a href="https://i.stack.imgur.com/dI8cd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dI8cd.jpg" alt="enter image description here" /></a></p>
  <p>The main issue is that while in text form as shown in the first screenshot, the attributes are not actually visible in the user facing shop and they are not available in the product's variations either.</p>
  <p>I'm using woocommerce methods to update the products. Here's a code sample:</p>
  <pre><code>$attribute_object = new WC_Product_Attribute();
  $attribute_object-&gt;set_name( $attribute_name );
  $attribute_object-&gt;set_options( $value );
  $attribute_object-&gt;set_visible(1);
  $attribute_object-&gt;set_variation(1);
  $attribute_object-&gt;set_position(0);
  $attribute_object-&gt;set_id( 0 );
  $new_product_attributes[$attribute_name] = $attribute_object;
  $new_product-&gt;set_attributes($new_product_attributes);
                          
  $new_product-&gt;save();
  </code></pre>
  <p>How can I get WP to sync the product with it's newly added attributes/attribute values?</p>