Home › Forums › General Issues › calculation not updating
So, i have something like this:
function perf_pln2($post_id)
{
$total = (get_field('zip')+get_field('kraken'))/(get_field('_price')+0.01);
$value = $total;
$field_name = "perf";
update_field($field_name,$value,$post_id);
}
add_action('save_post','perf_pln2');
And i have a plugin that synchronize prices, it does update the price, but it doesnt update the calculations based on the price from the code above.
Its working only when i click the “update” button on each product page, bulk edit doesnt work.
Im a total noob, i have no idea how to code PHP etc, so please dont bash me :P.
But how do i fix this, i started reading about acf/save_post, update_field and _value does look like something completely different.
Still i have no idea, so i just started trying some functions from the internet.
function _acf_do_save_post ($post_id) {
// Check and update $_POST data.
if( $_POST['acf'] ) {
acf_update_values( $_POST['acf'], $post_id );
}
}
// Run during generic action.
add_action( 'acf/save_post', '_acf_do_save_post' );
But no luck so far, please be so kind and help/point me in the right direction.
I would try adding the post ID reference to the get_field calls in your function, like:
function perf_pln2($post_id)
{
$total = (get_field('zip',$post_id)+get_field('kraken',$post_id))/(get_field('_price',$post_id)+0.01);
$value = $total;
$field_name = "perf";
update_field($field_name,$value,$post_id);
}
add_action('save_post','perf_pln2');
Unfortunately, emm, i cant say its not working, because it is working.
The problem is, my price synchronization plugin, well, actually its doing it job, which is updating price.
And without going into each product edit and pressing that update button, its not updating.
How to trigger that damn button without so much clicking through? zzz
ok, adding at the end:
add_action(‘woocommerce_update_product’, ‘perf_pln2’);
solved the issue 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.