我創建了一個插件,它使用update_post_meta
函數來更新產品的變化價格。Woocommence`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
你已經解決了這個問題?我遇到同樣的問題... – Lorenzo