title: Add Product Attributes with values to a product in Woocommerce
body: <p>I am using this code to add custom attributes </p>
  
  <pre><code>$attributes = array(
      array("name"=&gt;"Size","options"=&gt;array("S","L","XL","XXL"),"position"=&gt;1,"visible"=&gt;1,"variation"=&gt;1),
      array("name"=&gt;"Color","options"=&gt;array("Red","Blue","Black","White"),"position"=&gt;2,"visible"=&gt;1,"variation"=&gt;1)
  );
  if($attributes){
      $productAttributes=array();
      foreach($attributes as $attribute){
          $attr = wc_sanitize_taxonomy_name(stripslashes($attribute["name"])); // remove any unwanted chars and return the valid string for taxonomy name
          $attr = 'pa_'.$attr; // woocommerce prepend pa_ to each attribute name
          if($attribute["options"]){
              foreach($attribute["options"] as $option){
                  wp_set_object_terms($product_id,$option,$attr,true); // save the possible option value for the attribute which will be used for variation later
              }
          }
          $productAttributes[sanitize_title($attr)] = array(
              'name' =&gt; sanitize_title($attr),
              'value' =&gt; $attribute["options"],
              'position' =&gt; $attribute["position"],
              'is_visible' =&gt; $attribute["visible"],
              'is_variation' =&gt; $attribute["variation"],
              'is_taxonomy' =&gt; '1'
          );
      }
      update_post_meta(11874,'_product_attributes',$productAttributes); // save the meta entry for product attributes
  </code></pre>
  
  <p>The result of this code I got added just product attribute Name without term values...</p>
  
  <p>See the picture
  <a href="https://i.stack.imgur.com/Nj4U5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nj4U5.png" alt="enter image description here"></a></p>
  
  <p>I searched about that very much but did not got any answer.</p>