I creating a plugin that uses the update_post_meta function to update variation prices of products.

If I have a product x (id:5) and a variation y (id:400) and I run the update_post_meta(400,"_regular_price",13.00); It’s not updating the database. It’s extremely strange as when I click on Edit Product the updated price 13.00 shows up in variations panel and I have to click “Update” for it to update for customers to see. Is this regular behavior and if so how to update the database as soon as the update_post_meta function executes?

(Image) Price after update_post_meta()

.

(Image) Edit Product

Here is my code for doing the bulk updates

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;

I have asked the same question but no reply on WordPress forums
http://wordpress.org/support/topic/update_post_meta-is-not-updating-the-actual-values?replies=1#post-5742842

Read more here: Woocommence `update_post_meta` is not updating database values


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: