【发布时间】:2021-07-21 08:26:53
【问题描述】:
我创建了一个插件,它使用update_post_meta 函数来更新产品的变化价格。
如果我有一个产品 x (id:5) 和一个变体 y (id:400) 并且我运行 update_post_meta(400,"_regular_price",13.00); 它不会更新数据库。这非常奇怪,因为当我点击Edit Product(wp-admin)时,更新后的价格13.00 出现在变体面板中,我必须点击Update 才能更新以供客户查看。这是常规行为吗?如果是,如何在 update_post_meta 函数执行后立即更新数据库?
(Image) Price after update_post_meta()摘要页面
.
(Image) Price after same update. Edit Product page
这是我进行批量更新的代码
// $attribute_value/$variation_value are set correctly!
while ($loop->have_posts() ) : $loop->the_post();
global $product;
$variations = new WC_Product_Variable($product->post->ID);
$variations = $variations->get_available_variations();
foreach ($variations as $key => $variation){
foreach ($variation["attributes"] as $key => $attribute_value):
if($attribute_value == $variation_value):
update_post_meta( $variation['variation_id'], '_regular_price', $regular_price);
endif;
endforeach;
}
endwhile;
我问过同样的问题,但在 Wordpress 论坛上没有回复 http://wordpress.org/support/topic/update_post_meta-is-not-updating-the-actual-values?replies=1#post-5742842
【问题讨论】:
-
你解决了这个问题吗?我遇到了同样的问题...
标签: php wordpress woocommerce