woocommerce API,用于通过变体ID更新变体库存

时间:2018-10-18 06:34:40

标签: php wordpress woocommerce variance product-quantity

我想通过使用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);    

此代码仅更新主要库存库存数量。 我要更新差异数量。

1 个答案:

答案 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