title: WooCommerce creating Product Custom Attributes fields programmatically?
body: <p>I am trying to add Product Custom Attributes programmatically under the URL field as shown in the figure:
  <a href="https://i.stack.imgur.com/zrbEf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zrbEf.png" alt="enter image description here"></a></p>
  
  <p>I have been able to do it using the following code using <code>transition_post_status</code> action:</p>
  
  <pre><code>add_action('transition_post_status', 'wpa_120062_new_product', 10, 3);
  
  function wpa_120062_new_product($new_status, $old_status, $post){
  
      if( function_exists( 'wc_get_attribute_taxonomies' ) &amp;&amp; ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) ) {
  
          $defaults = array();
  
          foreach ( $attribute_taxonomies as $key=&gt;$tax ) {
  
                  $name = wc_attribute_taxonomy_name( $tax-&gt;attribute_name );
  
                  $value= get_post_meta( $post-&gt;ID , '_product_attributes');
  
                  $defaults[ $name ] = array (
                      'name' =&gt; $name,
  
                      'position' =&gt; $key+1,
                      'is_visible' =&gt; 1,
                      'is_variation' =&gt; 1,
                      'is_taxonomy' =&gt; 1,
                  );
  
              update_post_meta( $post-&gt;ID , '_product_attributes', $defaults );
          }
      }
  }
  </code></pre>
  
  <p>But the problem here is that <code>transition_post_status</code> hook doesn't work great as it sometimes doesn't complete the loading of fields completely.</p>
  
  <p>I have also tried to use <code>wp</code> action but no success.</p>
  
  <p>How can I make this code work but using a different Hook?</p>