php – Woocommence`update_post_meta`没有更新数据库值
我创建了一个使用update_post_meta函数更新产品变化价格的插件.
如果我有产品x(id:5)和变体y(id:400)并且我运行update_post_meta(400,“_ regular_price”,13.00);它没有更新数据库.这是非常奇怪的,因为当我点击编辑产品(wp-admin)时,更新价格13.00显示在变体面板中,我必须单击更新以便更新以供客户查看.这是常规行为,如果是,如何在update_post_meta函数执行后立即更新数据库? (图片)update_post_meta()摘要页面后的价格 . (图片)相同更新后的价格.编辑产品页面 这是我进行批量更新的代码 // $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论坛 解决方法
在woocommerce(版本2.1.12):
woocommerce /包括/ WC-产品的functions.php:417 $regular_price = get_post_meta( $product_id,true ); update_post_meta( $product_id,'_price',$regular_price ); update_post_meta( $product_id,'_sale_price','' ); update_post_meta( $product_id,'_sale_price_dates_from','_sale_price_dates_to','' ); wc_delete_product_transients( $product_id ); 您似乎必须更新“_price”元,甚至删除瞬态以更新产品价格. 要删除产品临时呼叫: wc_delete_product_transients( $product_id ); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |