Woocommerce – how to round up all prices to end in .99


I need to update all prices in my store to end in .99, both on the front end and in the database. I have the following code which appears to do it when I run a shortcode, but I have a problem.

When I look at the products in the admin they sill show the old prices. I’ve cleared the transients and regenerated the product lookup tables but the old prices are still showing, which makes me think the new prices are only shown on the front end, even though the code is clearly updating the database. Bit confused.

add_shortcode( 'shortcode_update_price','shortcode_update_price' );
function shortcode_update_price(){
  global $wpdb;

  $prefix = $wpdb->prefix;
  $results = $wpdb->get_results( "SELECT `meta_id`, `meta_value` FROM {$prefix}postmeta WHERE `meta_key`='_price'", ARRAY_A );
  if ( !empty($results) ) {
    foreach ($results as $key => $value) {
      $new_price = ceil($value['meta_value']) - 0.01; 
      $wpdb->query( "UPDATE {$prefix}postmeta SET `meta_value`=$new_price WHERE `meta_id`=$value[meta_id]" );


enter image description here

What am I doing wrong? Is this likely still just a caching issue?

Xav 3 months 0 Answers 17 views 0

Leave an answer