title: Convert product categories to product attributes in Woocommerce
body: <p>In Woocommerce I am trying to convert product categories to product attributes, using the following code:</p>
  
  <pre><code>$all_categories = wp_get_post_terms( get_the_ID(), 'product_cat' );;
  $productid = get_the_ID();
  
  foreach ($all_categories as $_term) {
      //$_term-&gt;name
      // $_term-&gt;parent
      $parent  = get_term_by( 'id', $_term-&gt;parent, 'product_cat');
  
  
      // echo $parent-&gt;name . ': ' . $_term-&gt;name . '&lt;br /&gt;';
  
      $attribute_name =  $parent-&gt;name; //slug of the attribute(taxonomy) 
      $attribute_value = $_term-&gt;name; //slug of the attribute value (term)
  
      //Appending term to the object/product.
      $term_taxonomy_ids = wp_set_object_terms(get_the_ID(), $attribute_value, $attribute_name, true);
      $data = array(
          $attribute_name =&gt; array(
              'name' =&gt; wc_clean($attribute_name),
              'value' =&gt; $attribute_value,
              'is_visible' =&gt; '1',
              'is_variation' =&gt; '1',
              'is_taxonomy' =&gt; '0' // i tried with 1
          )
      );
  
      // getting the Post Meta
      $_product_attributes = get_post_meta($productid, '_product_attributes', TRUE);
      if ( is_array($_product_attributes) ){
      } else { 
          $_product_attributes = array();
      }
  
      //Updating the Post Meta
      update_post_meta($productid, '_product_attributes', array_merge($_product_attributes, $data)); 
  }
  </code></pre>
  
  <p><strong>Is works partially</strong> as I need to see in backend Product > attributes the converted attributes listed…</p>