Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我对woocommerce api自定义选项的错误在哪里?_Php_Wordpress_Api_Woocommerce - Fatal编程技术网

Php 我对woocommerce api自定义选项的错误在哪里?

Php 我对woocommerce api自定义选项的错误在哪里?,php,wordpress,api,woocommerce,Php,Wordpress,Api,Woocommerce,我在自定义选项的源代码中的错误在哪里?我正在使用商业RESTAPI。在foreach中,我需要添加不同的选项,如S-blue、M-red、S-red、M-blue,但我在wordpress中得到了空输入: 这是我的代码和文件: 当我试图创建一个产品,特别是一个可变产品时,我也遇到了同样的问题。终于找到了解决办法 如果您的代码是正确的,只是没有创建变体,那么我发现的解决方案是,您必须只使用一个属性“name”或“slug”,并保持“option”属性不变。尝试在属性中仅使用“name”和“op

我在自定义选项的源代码中的错误在哪里?我正在使用商业RESTAPI。在foreach中,我需要添加不同的选项,如S-blue、M-red、S-red、M-blue,但我在wordpress中得到了空输入:

这是我的代码和文件:


当我试图创建一个产品,特别是一个可变产品时,我也遇到了同样的问题。终于找到了解决办法

如果您的代码是正确的,只是没有创建变体,那么我发现的解决方案是,您必须只使用一个属性“name”或“slug”,并保持“option”属性不变。尝试在属性中仅使用“name”和“option”或“slug”和“option”

我在这里以我的代码为例

$child_prod_json = json_encode(
    array( 'product' =>
    array( 'title'           => $child_prod->product->title,
        'type'           => 'variable',
        'variations'         => array(array(
        'regular_price'      => $child_prod->product->regular_price,
        'sale_price'         => $child_prod->product->sale_price,
        'images'         => array( array( 'src'      => $child_prod->product->images[0]->src,
            'position'   => $child_prod->product->images[0]->position ) ),
        'attributes'    => array(array('name'=>$child_prod->product->attributes[0]->name,'option'=>$child_prod->product->attributes[0]->option)),
        'managing_stock'     => $child_prod->product->managing_stock,
        'in_stock'       => $child_prod->product->in_stock,
        'stock_quantity'     => $child_prod->product->stock_quantity,
        'shipping_class' => $shipping_class,
        'shipping_class_id'     =>$shipping_class_id,
    'purchase_note'     =>$child_prod->product->purchase_note,          
        ),)
    )  )    );
对于本例,我仅使用第一个属性,即[0]位置作为演示


我的观点是-‘name’和‘slug’不能一起工作。使用其中任何一个。这个解决方案对我有效。请尝试让我知道它是否对您有效。

我也有同样的问题。你的解决方案不起作用。尝试了slug和option,以及name和option。
$child_prod_json = json_encode(
    array( 'product' =>
    array( 'title'           => $child_prod->product->title,
        'type'           => 'variable',
        'variations'         => array(array(
        'regular_price'      => $child_prod->product->regular_price,
        'sale_price'         => $child_prod->product->sale_price,
        'images'         => array( array( 'src'      => $child_prod->product->images[0]->src,
            'position'   => $child_prod->product->images[0]->position ) ),
        'attributes'    => array(array('name'=>$child_prod->product->attributes[0]->name,'option'=>$child_prod->product->attributes[0]->option)),
        'managing_stock'     => $child_prod->product->managing_stock,
        'in_stock'       => $child_prod->product->in_stock,
        'stock_quantity'     => $child_prod->product->stock_quantity,
        'shipping_class' => $shipping_class,
        'shipping_class_id'     =>$shipping_class_id,
    'purchase_note'     =>$child_prod->product->purchase_note,          
        ),)
    )  )    );