PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Changing the value of a custom field when changing the price

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi,
I have two custom fields: cost and result.

To simplify, Result must have the value ( full price – cost) / 100

When the value of full price or cost is changed from bulk I need the custom field result to be updated according to the formula written before.

I have tried using woobe_before_update_product_field. In the DB the value is updated. The problem is that to see it in the bulk I have to refresh the page otherwise I always see the old value.

How can I solve this? Is the hook I am using the correct one?
Thank you.

Hello

yes let's check it out

Can you give me your custom code?

Ok, thank

add_filter('woobe_before_update_product_field', function($value, $product_id, $field_key) {

if ($field_key === 'cost' || $field_key === 'regular_price') {

if ($field_key === 'cost') {
$cost = $value;
} else {
$cost = get_post_meta( $product_id, 'cost', true );
}
if ($field_key === 'regular_price') {
$regular_price = $value;
} else {
$regular_price = get_post_meta( $product_id, '_regular_price', true );
}

$result = ($regular_price - $cost) / 100;

update_post_meta( $product_id, 'result', round($result, 2));

}

return $value;
}, 10, 3);

Hello

Yes, the problem is that you change a third-party field and the plugin redraws only the field that is being edited in the current operation

But if you use bulk edit, then the whole row is redrawn

OK, thanks for the clarification!

And there is no way to force the page to reload or have the entire line redrawn by the function executed with the woobe_before_update_product_field hook right?

unfortunately there is no way to affect JS with this hook