我的代码在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));产品被插入到名为Premium 的数据库中,问题是SKU没有插入,当我试图在WordPress面板中查看时,发现它是空的。
为什么会发生这种情况?
我的wordpress和WooCommerce升级到最新版本(我的PHP也是=> 1.3.0)
发布于 2019-02-08 02:09:59
卷曲
$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;
}https://stackoverflow.com/questions/44979518
复制相似问题