WooCommerce API不SKU创建产品

问题描述 投票:3回答:1

我有这样的代码,在WooCommerce创建新的产品:

$woocommerce = new Client(
    'http://www.xxxx.com.br', 
    'ck_xxxxxx', 
    'cs_xxxxxx',
    [
        'wp_api' => true, // Enable the WP REST API integration
        'version' => 'wc/v1' // WooCommerce WP REST API version
    ]
);

    $data = [
        'name' => 'Premium Quality',
        'type' => 'variable', 
        'sku' => '123450000',
    ];

    print_r($woocommerce->post('products', $data));

该产品被插入到名为高级质量数据库,该问题是SKU未插入,当我尝试在WordPress的面板我看到,它是空的。

这究竟是为什么?

我的WordPress和WooCommerce都升级到最新版本(和我的PHP API太=> 1.3.0)

php wordpress woocommerce woocommerce-rest-api
1个回答
1
投票

与卷曲尝试

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://example.com/wp-json/wc/v3/products",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"name\": \"Premium Quality\",\n  \"type\": \"variable\",\n  \"sku\" : \"123450000\"\n}",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ",
    "Content-Type: application/json",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
© www.soinside.com 2019 - 2024. All rights reserved.