我想通过使用woocommerce
更新variation id
变化产品库存。
我尝试过,但是仅更新主要inventory Stock quantity
,而不更新变化量。这是我的代码:
$product_id = 7559;
$variance_id = 122;
$get_stocks = $woocommerce->get('products/'.$product_id);
$stock_quantity_old = $get_stocks["stock_quantity"];
$data = [
'stock_quantity' => $stock_quantity_old - 1
];
$result = $woocommerce->put('products/'.$product_id, $data);
此代码仅更新主要库存库存数量。 我要更新差异数量。
答案 0 :(得分:1)
首先,您需要将stock_quantity
设置为true,然后使用$product_id = 7559;
$variance_id = 122;
$get_stocks = $woocommerce->get('products/'.$product_id);
$stock_quantity_old = $get_stocks["stock_quantity"];
$data = [
'manage_stock' => true,
'stock_quantity' => $stock_quantity_old - 1
];
$result = $woocommerce->put('products/'.$product_id.'/variations/'.$variance_id, $data);
。请使用以下代码。
SELECT TOP 1 WITH TIES * FROM
employee
ORDER BY
hire_date ASC,
salary DESC