Divi 

WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WooCommerce: Add products with attribute in REST API

Discussion in 'Plugins and Hacks' started by mr_ocean, Feb 17, 2017.

  1. mr_ocean

    New Member

    Joined:
    Feb 17, 2017
    Messages:
    2
    Likes Received:
    0
    Hi all!

    I've a problem with the REST API. I installed this class (automattic/woocommerce) for WooCommerce API.
    I can to insert a new product but i found difficulty to add a product's attributes.

    I want to create a new product in my website with attribute (color).

    This is the code that i use:
    PHP:
    $data = [
                
    'name' => 'Microsoft Surface',
                
    'type' => 'simple',
                
    'regular_price' => '1100',
                
    'description' => 'Il tablet AiO di Microsoft',
                
    'short_description' => 'Tablet surface',
                
    'categories' => [
                    [
                        
    'id' => 20
                    
    ]
                ],
                
    'images' => [
                    [
                        
    'src' => 'images/pic.jpg',
                        
    'position' => 0
                    
    ]
                ],
                
    'attributes' => [
                        
    'id' => 'colore',
                        
    'position' => 1,
                        
    'visible' => true,
                        
    'variation' => [
                            
    '0' => 'argento',
                            
    '1' => 'nero',
                            
    '2' => 'oro'
                            
    ]
                ]
            ];

            
    print_r$woocommerce->post('products'$data)
    This code works, the product was added into WooCommerce but it don’t have any attribute.
    Can you help me to solve the problem? I read the docs but i don’t understand how can i do to solve..
     
    #1

Share This Page