如果库存数量为空,则缺货

问题描述

我正在使用 wpallimport 来更新我的产品价格和库存状态。 我的经销商使用 csv 文件,其中库存数量仅在库存产品中填写数量,如果产品缺货,数量字段为空。 如果数量不为 0,则自动库存状态工具会使所有物品都有库存。 导入已安排,插件每小时从 URL 下载文件。 如果 csv 文件中的库存数量为空,有什么方法可以使产品缺货?

解决方法

您可以调用自定义 PHP 函数来更新股票价值,如本文档所述:

https://www.wpallimport.com/documentation/developers/custom-code/inline-php/

function update_item_stock( $item_id,$stock_count ) {
    // if stock quantity is empty - adjust this according to value in the CSV:
    if( $stock_count == '' ) {
        wc_update_product_stock_status( $post_id,'outofstock' ); 
     }
}

您可以使用如下方式从导入字段调用它(取决于您的字段在 CSV 中的名称):

[update_item_stock( {product_id[1]},{stock_qty[1]} )]