1

I have a Attribute called "Color" and it has two attributes "Red" and "Green".
When i run this using WC REST API

Everything is working from the below code, i am stuck with the attributes.

print_r( $client->products->create( array( 
    'title' => 'Nile - Over Counter Basin',
    'sku' => '91081_Nile', 
    'type' => 'simple', 
    'regular_price' => '7260',
    'sale_price' => '5445',
    'description' => 'Nile - Over Counter BasinOver Counter BasinHindware Italian CollectionContemporary design with smooth flowing line Space for toiletries', 
    'dimensions'=>array( 'length' =>'67.5' ,'width' =>'39.5','height'=>'12.5'), 
    'categories'=>array( ' SANITARYWARE' =>'592',' WASHBASIN' =>'650',' Table Top Wash Basin' =>'508'),
    'images' =>Array ('91081_Nile'=>Array('src'=>'http://www.somethingsomething.com/images/products/91081/2.jpg','title'=>'91081_Nile','position'=>'0') ),
    'short_description'=>'Contemporary design with smooth flowing line Space for toiletries <table id="ProductDescriptiontable"><tr><td>Brand</td><td>:</td><td class="thirdcolumn">Hindware</td></tr><tr><td>Product Name</td><td>:</td><td class="thirdcolumn">Nile - Over Counter Basin</td></tr><tr><td>Product Description</td><td>:</td><td class="thirdcolumn">Table Top Wash Basin</td></tr></tr><tr><td>Product Color</td><td>:</td><td class="thirdcolumn">StarwhiteIvory</td></tr></table>',
'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),
    'enable_html_short_description' => true,  // This is the line you need to add 
)  ) ) ;

Anand: After adding the attributes in multiple array, the attributes are displayed in correct section, but they are not considered as attributes, .. please see the image, they are seen as a plain text and not as an attributes.
My Code is:

'attributes'=>array(array('name'=>'Color','Slug'=>'color','position'=>'0','visible'=>true,'options'=>'Starwhite'),array('name'=>'Model',
'Slug'=>'model','position'=>'0','visible'=>true,'options'=>'Pedestal Wash Basin'),array('name'=>'Brands','Slug'=>'brands','position'=>'0','visible'=>true,'options'=>'Hindware'),array('name'=>'Washbasin Size','Slug'=>'washbasin-size','position'=>'0','visible'=>true,'options'=>'56 x 46 x 38.5 cm'),array('name'=>'Washbasin Type','Slug'=>'washbasin-type','position'=>'0','visible'=>true,'options'=>'Washbasin With Pedestal'))

enter image description here

0

1 Answer 1

1

You need to pass attributes as an array of arrays, change

'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),

to

'attributes' => array( array( 'name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red' ) ),

P.S: I am presuming there that the taxonomy and term already exist, and that the taxonomy's type is set to text.

EDIT

When the taxonomy's type is set to "text" pass options as plain text

'options' => 'term'

When the taxonomy's type is set to "select" pass options as an array

'options' => array( 'red', 'white' )

To pass multiple attributes, send them as an array of arrays, for eg:

'attributes'=>array(
    array( 'name'=>'Color', 'slug'=>'color', 'position'=>'0', 'visib‌​le'=>true, 'options'=> array('Starwhite') ),
    array( 'name'=>'Washbasin Type', 'slug'=>'washbasin-type', 'position'=>'0', 'visible'=>true, 'options'=> array(‌​'Washbasin With Pedestal') ),
);
Sign up to request clarification or add additional context in comments.

10 Comments

Again, thank you a million, this worked. Many people suggested to change the API version.. but this solved my issue..
how will i modify your solution if i have multiple attributes for the same products, will they come under multiple Array ? or single Arrary ? can you share an example for the below please ? Multiple Attributes: (Color : White, Red) (Model: Wall Mounted) (Tank: Ceramic)
You need to pass multiple array elements, for eg 'attributes' => array( array('name'=>'color'....), array( 'name' => 'model'.....) )
the attributes are taken as plain text, and not like the real attributes. example i have attached the image in the question above. The Pedestal wash basin is shown as plain text, but it should be shown as the real attribute like seen for Table Top wash basin.. can you suggest, if i am dong anything wrong..
When the taxonomy's type is set to "Select" , you need to pass the options as an array, 'options'=>array('Red')
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.