set_attributes() public méthode

Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name value pairs.
public set_attributes ( array $raw_attributes )
$raw_attributes array
 function test_varation_save_attributes()
 {
     // Create a variable product with a color attribute.
     $product = new WC_Product_Variable();
     $attribute = new WC_Product_Attribute();
     $attribute->set_id(0);
     $attribute->set_name('color');
     $attribute->set_options(explode(WC_DELIMITER, 'green | red'));
     $attribute->set_visible(true);
     $attribute->set_variation(true);
     $product->set_attributes(array($attribute));
     $product->save();
     // Create a new variation with the color 'green'.
     $variation = new WC_Product_Variation();
     $variation->set_parent_id($product->get_id());
     $variation->set_attributes(array('color' => 'green'));
     $variation->set_status('private');
     $variation->save();
     // Now update some value unrelated to attributes.
     $variation = wc_get_product($variation->get_id());
     $variation->set_status('publish');
     $variation->save();
     // Load up the updated variation and verify that the saved state is correct.
     $loaded_variation = wc_get_product($variation->get_id());
     $this->assertEquals('publish', $loaded_variation->get_status('edit'));
     $_attribute = $loaded_variation->get_attributes('edit');
     $this->assertEquals('green', $_attribute['color']);
 }
 /**
  * Link all variations via ajax function.
  */
 public static function link_all_variations()
 {
     check_ajax_referer('link-variations', 'security');
     if (!current_user_can('edit_products')) {
         die(-1);
     }
     wc_maybe_define_constant('WC_MAX_LINKED_VARIATIONS', 49);
     wc_set_time_limit(0);
     $post_id = intval($_POST['post_id']);
     if (!$post_id) {
         die;
     }
     $variations = array();
     $product = wc_get_product($post_id);
     if ($product->is_type('variable')) {
         $attributes = wc_list_pluck(array_filter($product->get_attributes(), 'wc_attributes_array_filter_variation'), 'get_slugs');
         if (!empty($attributes)) {
             // Get existing variations so we don't create duplicates.
             $existing_variations = array_map('wc_get_product', $product->get_children());
             $existing_attributes = array();
             foreach ($existing_variations as $existing_variation) {
                 $existing_attributes[] = $existing_variation->get_attributes();
             }
             $added = 0;
             $possible_attributes = wc_array_cartesian($attributes);
             foreach ($possible_attributes as $possible_attribute) {
                 if (in_array($possible_attribute, $existing_attributes)) {
                     continue;
                 }
                 $variation = new WC_Product_Variation();
                 $variation->set_parent_id($post_id);
                 $variation->set_attributes($possible_attribute);
                 do_action('product_variation_linked', $variation->save());
                 if ($added++ > WC_MAX_LINKED_VARIATIONS) {
                     break;
                 }
             }
             echo $added;
         }
     }
     die;
 }