Support

Account

Home Forums General Issues Calculate a field using price and acf value Reply To: Calculate a field using price and acf value

  • Update:
    I was able to update the price per tablet by using the following code:

    function wc_update_price_per_unit($post_id) {
        $value= get_field('_price')/get_field('number_of_unit');//use _regular_price to get regular woocommerce price
    	$field_name = "price_per_unit";
    	update_field($field_name,$value,$post_id);
    }
    add_action('save_post','wc_update_price_per_unit');

    The price_per_tablet value gets populated when saving the post. How can I see changes in the price_per_unit field before saving or updating the post.