Advertisement
lorro

WooCommerce - show price in two currencies

May 6th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2.   // WooCommerce - show price in two currencies
  3.   // not great because you'll need to manually update the factor regularly
  4.   add_filter( 'woocommerce_get_price_html', 'euros_custom_price', 100, 2 );
  5.   function euros_custom_price( $price, $product ) {
  6.     $factor = 0.008352; // Euro conversion factor
  7.     if ( $product->is_type('simple') ) {
  8.       $my_price = $product->get_price();
  9.       $euros = $my_price * $factor;
  10.       $euros = number_format($euros, 2);
  11.       $price = 'XPF ' . $price . ' (EUROS ' . $euros . ')';
  12.     }
  13.     if ( $product->is_type('variable') ) {
  14.       $min_price = $product->get_variation_price('min');
  15.       $min_euros = $min_price * $factor;
  16.       $min_euros = number_format($min_euros, 2);
  17.       $max_price = $product->get_variation_price('max');
  18.       $max_euros = $max_price * $factor;
  19.       $max_euros = number_format($max_euros, 2);
  20.       $price = 'XPF '.$min_price.' to '.$max_price.' (EUROS '.$min_euros.' to '.$max_euros.')';
  21.     }
  22.     return $price;
  23.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement