Guest User

allow BGN for WooCommerce and PayPal

a guest
Aug 7th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. // allow BGN for WooCommerce and PayPal
  2. add_filter( 'woocommerce_paypal_supported_currencies', 'add_bgn_paypal_valid_currency' );    
  3.     function add_bgn_paypal_valid_currency( $currencies ) {  
  4.      array_push ( $currencies , 'BGN' );
  5.      return $currencies;  
  6.     }
  7.  
  8.  
  9. // Convert BGN to EUR for PayPal payments
  10. add_filter('woocommerce_paypal_args', 'convert_bgn_to_eur');
  11. function convert_bgn_to_eur($paypal_args){
  12.     if ( $paypal_args['currency_code'] == 'BGN'){
  13.         $convert_rate = 1.955; //set the converting rate
  14.         $paypal_args['currency_code'] = 'EUR'; //change BGN to EUR
  15.         $i = 1;
  16.  
  17.         while (isset($paypal_args['amount_' . $i])) {
  18.             $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
  19.             ++$i;
  20.         }
  21.        
  22.         if ( $paypal_args['shipping_1'] > 0 ) {
  23.                 $paypal_args['shipping_1'] = round( $paypal_args['shipping_1'] / $convert_rate, 2);
  24.                 }
  25.        
  26.         if ( $paypal_args['discount_amount_cart'] > 0 ) {
  27.                 $paypal_args['discount_amount_cart'] = round( $paypal_args['discount_amount_cart'] / $convert_rate, 2);
  28.                 }
  29.                 }
  30.  
  31.                 return $paypal_args;
  32. }
Add Comment
Please, Sign In to add comment