Created a catalog via CPT (NOT WooCommerce) and each product has a meta field (via ACF) – Price (price)
Please tell me how you can massively (for all products), change this meta field price (price) to the required percentage (for example, 15%)
Ideally, I need to set the required percentage on the settings page and, if this setting is saved, the meta field price (price) for all products in the catalog will change
I tried
function change_price( )
{
global $wpdb;
$wpdb->query("UPDATE " . $wpdb->prefix . "postmeta SET meta_value = meta_value * 1.135 WHERE meta_key = 'price'");
}
But I dont understand how it work on settings page, on how "action"
2
Answers
You can do by filtering the post meta via PHP:
Add the below code to your theme’s functions.php file or a custom plugin.
The code will only execute the price update if this parameter is present and its value is set to
'true'
. This allows you to control when the price update should happen by appending?update_prices=true
to the URL.Please make sure to replace
'price'
with the actual meta key for the price field in your ACF setup.