我目前有一个表单,管理员可以在其中批量更新一个屏幕内的产品销售价格。
提交表单后,我只需使用 update_post_meta 即可,如下所示:
update_post_meta($id,'_sale_price', 'new sale price here');
这会更新 _sale_price 元键。当我进入管理员检查这一点时,新的销售价格已被插入。当我在前端查看产品时,该商品未标记为促销。我必须返回并重新保存产品。
我的问题是,woocommerce 是否添加了一些其他元 key 来将产品标记为促销?我在数据库中对插入的所有自定义字段进行了挖掘,但只能看到 _sale_price。
任何帮助将不胜感激
最佳答案
查看 WooCommerce 中的 Product 抽象类,以下 php 代码可获取产品是否在促销:
return ( $this->sale_price != $this->regular_price && $this->sale_price == $this->price );
这似乎表明 _price 必须与 sale_price 相同才能被归类为促销。所以只是
update_post_meta($id, '_price', 'new sale price here too');
以及您问题中的代码,它应该可以工作。
关于wordpress - woocommerce 更新销售价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21867484/