I have a meta key called 'prijs' in each post. The value of this meta key consist of numbers in the follow structure: 2,100.00
I want to remove the comma in the meta value to get this output: 2100.00
So, i created a function but it doesn't work:
add_action('wp_insert_post', 'deleteCommaDB');
function deleteCommaDB($postID){
$price_key = 'prijs';
$getPrice = get_post_meta($postID, $price_key, true);
$newPrice = str_replace(array(','), '', $getPrice);
update_post_meta($postID, $price_key, $newPrice);
return true;
}
I created the function deleteCommaDB
. This function gets the post meta from the meta key 'prijs', and replaces the comma for nothing. This new value is saved in the variable $newPrice. Next thing to do, is update the post meta with the new value.
What am i doing wrong?