WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
update_post_meta is not updating the actual values (1 post)

  1. CezarisLT
    Member
    Posted 1 month ago #

    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 behavor 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

    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):
                        echo update_post_meta( $variation['variation_id'], '_regular_price', $regular_price);
                    endif;
                endforeach;
            }
    endwhile;

    https://wordpress.org/plugins/woocommerce/

Reply

You must log in to post.

About this Plugin

About this Topic