woocommerce api创建具有变体的新产品

woocommerce api创建具有变体的新产品,api,attributes,woocommerce,variations,Api,Attributes,Woocommerce,Variations,我想用WooCommerceAPI创建一个新产品。我有一个颜色属性,我想从sku识别产品,例如codeblack 我的问题是如何做到这一点 在创建具有倾斜、描述、sku等的产品时,一切正常。为了创建具有属性的产品,我添加了'type'=>'variable' 现在我有了属性,我启用了变体,但我不能赋予变体价值 这是我的密码 $client->products->create( array( 'title' => 'Premium Qualit

我想用WooCommerceAPI创建一个新产品。我有一个颜色属性,我想从sku识别产品,例如codeblack

我的问题是如何做到这一点

在创建具有倾斜、描述、sku等的产品时,一切正常。为了创建具有属性的产品,我添加了
'type'=>'variable'

现在我有了属性,我启用了变体,但我不能赋予变体价值

这是我的密码

    $client->products->create( 
    array( 
        'title' => 'Premium Quality', 
        'type' => 'variable', 
        'sku' => 'code',
        'regular_price' => '29.98',
        'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
        'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
        'images' => array(
                array(
                    'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
                    'position' => 0

                ),
                array(
                    'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
                    'position' => 1
                )
         ),
         'attributes' => array( 
            array( 
                'name'=>'color',
                'slug'=>'color',
                'position'=>'0',
                'visible'=>'true',
                'variation'=>'true',
                'options'=>array('red','black')
            ) 
         ),
         'variations' => array(
            array(
                'sku' => 'codered',
                'regular_price' => '29.98',
                'attributes' => array( 
                    array( 
                        'name'=>'color',
                        'options'=>'red'
                    )

                ) 
            ),
            array(
                'sku' => 'codeblack',
                'regular_price' => '29.98',
                'attributes' => array( 
                    array( 
                        'name'=>'color',
                        'options'=>'black'
                    )
                ) 
            )
        )

    ) 

);
所以我有我的属性

但我无法将它们与变体相匹配


您能帮助我吗?

我有完全相同的问题,尽管我通过NodeJS使用API。 我已经确定了API调用中处理
位置
is_分类法
的方式存在问题,这会阻止变体正确链接到属性: 我找到了解决办法

'variations' => array(
                array(
                    'sku' => date('His').'_1',
                    'regular_price' => '29.98',
                    'attributes' => array( 
                        array( 
                            'id' => date('YmdHis', strtotime('+2 seconds')),
                            'slug'=>'color',
                            'name'=>'color',
                            'option'=>'red' 
                        )
                    ) 
                ),
                array(
                    'sku' => date('His').'_2',
                    'regular_price' => '29.98',
                    'attributes' => array( 
                        array( 
                            'id' => date('YmdHis'),
                            'slug'=>'color',
                            'name'=>'color',
                            'option'=>'black'
                        )
                    ) 
                )
            )
如果颜色属性和红色、黑色值存在,则适用于我


您必须使用
id

您可以使用变体/批次并使用您现有的产品属性,它适用于我。。。

将id放入变体的属性中。这对我有用