Liudas
Liudas

Reputation: 3

Change all prices in MySql database wordpress e-commerce

I'm preparing for new currency in my country. How I can easily divide all prices from 3.45. All prices stored in mysql table wp_postmeta _wps_price. I haven't found any wordpress plugins which will convert all.

Upvotes: 0

Views: 391

Answers (3)

Liudas
Liudas

Reputation: 3

My question was with mistake. With edited Micheal's code I succeeded. Also find out how to round result.

   UPDATE `wp_postmeta` SET `meta_value`= `meta_value` / 3.45 WHERE meta_key='_wpsc_price'
   UPDATE `wp_postmeta` SET `meta_value`= round(meta_value,2) WHERE meta_key='_wpsc_price'

I hope this will help somebody. Today I learned MySql basic's.

Upvotes: 0

baao
baao

Reputation: 73231

UPDATE wp_postmeta_wps_price SET price = price / 3.45

This will divide all your prices by 3.45. You need to change price to whatever your column that stores the prices.

Upvotes: 1

Fatih SARI
Fatih SARI

Reputation: 433

You can get all products and change price with wp queries. My example:

$get_your_products = get_posts( array(
    'post_type' => 'wpsc-product',
    'showposts' => -1
) );

foreach( $get_your_products as $product ){
    $current_price  = get_post_meta($product->ID, '_wps_price', true);
    $new_price      = $current_price / (3.45);
    update_post_meta($product->ID, '_wps_price', $new_price);
}

Upvotes: 0

Related Questions