-1

I have a shop that i now want on another domain and for that reason i need to update all prices on the new domain. I need to multiply all prices by 1.45.

I've tried an code snippet, which actually works great on simple products, but it does not work on variable/variations product.

function return_custom_price($price, $product) {
    global $post, $blog_id;
    $product = wc_get_product( $post_id );
    $post_id = $post->ID;
    $price = ($price*1.45);
    return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);

I want this code to also multiply variation pricing by 1.45

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
kongen
  • 19
  • 7
  • Do you need it to be changed in the database or just in the front-end? – Screenload Aug 30 '19 at 07:50
  • @Screenload In theory both places, it's because it's located in another country, so the currency is different, and i don't want to use currency switcher or other plugins :-D – kongen Aug 30 '19 at 07:51

1 Answers1

1

If you add this line below your code it should also do it for variations.

add_filter('woocommerce_product_variation_get_price', 'return_custom_price', 10, 2);

Keep in mind that the database has still stored the "base"-price.

Screenload
  • 431
  • 2
  • 14
  • Thanks a lot! That actually works great. Now the problem is it still shows the old price in the front-end but with striked-out, so it almost shows the item on sale, so it shows the old price which is 19,00 and that is striked out and then it shows 27,55 beside it – kongen Aug 30 '19 at 08:02
  • Then you'd have to update the database directly and don't use any code. **Backup your database** and run this SQL-query: ```UPDATE wp_postmeta SET meta_value = meta_value*1.45 WHERE meta_key = '_price'``` – Screenload Aug 30 '19 at 08:11
  • This actually worked but again only on simple products, not variations. IS there another code i should use for variations? – kongen Aug 30 '19 at 08:17
  • Okay I forgot the other meta... try this as well: ```UPDATE wp_postmeta SET meta_value = meta_value*1.45 WHERE meta_key = '_regular_price'``` – Screenload Aug 30 '19 at 08:21
  • Thanks a lot!! Works like a goddamn charm. Last thing. Do you know a quick fix for decimals? After multiplying i get a price that is 39,004999999999995 even though i added max 2 decimals in WooCommerce. Do you know a quickfix? :D – kongen Aug 30 '19 at 08:23
  • Nevermind, my bad. It is working perfectly. Sorry for the inconvience. Thanks! – kongen Aug 30 '19 at 08:30