WP All Import 库存覆盖 [英] WP All Import stock ovewritte

查看:21
本文介绍了WP All Import 库存覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 WP All Import 来导入数据(特别是库存数量).当我导入库存数量时,它会覆盖我当前的数据,我希望它做的是更新数据.假设 WooCommerce 有 5 个,而我的 CSV 表有 5 个,我希望将这两个值相加(等于 10).

I'm currently using WP All Import to import data (specifically stock quantity). When I import the stock quantity it overwrites my current data, and what I would like for it to do is to update data. Lets say WooCommerce had 5 and my CSV sheet has 5, I would like those two values to add (equaling 10).

我确实给 WP All Import 支持发送了电子邮件,以提供有关使上述工作正常所需的内容的一些指示,这是他们的:

I did email WP All Import support to provide some indication on what was required to get the above to work, and here is their:

如果您擅长代码,则可以使用自定义后处理函数使其工作.只需将您的股票值导入占位符自定义字段.然后通过附加到pmxi_saved_post"操作的函数,您将访问两个实际库存自定义字段和占位符之一.添加两者的值并更新最终库存.http://www.wpallimport.com/documentation/developers/action-reference/";

"If you are good with code you can make that work using a custom post-processing function. Simply import your stock value into a placeholder custom field. Then through a function attached to the "pmxi_saved_post" action you would access both the actual stock custom field and the placeholder one. Add the values of both and update the final stock. http://www.wpallimport.com/documentation/developers/action-reference/";

我不知道从哪里开始.任何输入将不胜感激.

I have no clue where to start. Any input would be appreciated it.

推荐答案

解决方案就在您的面前.

The solution is right front of your.

方法:

  • 将下面的函数添加到主题的functions.php文件中

  • Add the below function into the theme's functions.php file

add_action('pmxi_saved_post', 'wdm_post_saved', 10, 1);

add_action('pmxi_saved_post', 'wdm_post_saved', 10, 1);

function wdm_post_saved($id) {

function wdm_post_saved($id) {

$original_stock = get_post_meta($id, '_stock', true);$new_stock = get_post_meta($id, '_custom_stock_placeholder', true);

$original_stock = get_post_meta($id, '_stock', true); $new_stock = get_post_meta($id, '_custom_stock_placeholder', true);

$combined_stock= $original_stock + $new_stock

$combined_stock= $original_stock + $new_stock

update_post_meta($id, '_stock', $combined_stock);

update_post_meta($id, '_stock', $combined_stock);

}

从仪表板添加另一个自定义字段或在使用 WP ALL IMPORT 时对产品说_custom_stock_placeholder".

Add another custom field from dashboard or while using WP ALL IMPORT say '_custom_stock_placeholder' to the products.

在使用 WP ALL IMPORT 时,将新的库存值分配给上述自定义字段,而不是原始的_stock"字段.

While using WP ALL IMPORT assign the new stock value to the above mentioned custom field rather than original '_stock' field.

休息功能会为你计算和做你需要的.

Rest the function will calculate and do the needful for you.

这篇关于WP All Import 库存覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆