我在woocommerce中遇到此错误“Gateway Disabled:PayPal不支持您的商店货币”

时间:2015-04-16 15:03:54

标签: wordpress paypal woocommerce

我的woocommerce网站上有这个错误:

  

网关已停用:PayPal不支持您的商店货币。

任何人都有具体的解决方案吗?

我使用的是货币沙特里亚尔(SAR)和美元($)。

2 个答案:

答案 0 :(得分:1)

我已经在这个问题上工作了几天,这里是我找到的解决方案。 在我的情况下,我需要BGN,因此代码适用于该货币(它们可以很容易地适应其他货币)。

===解决方案1 ​​===

此解决方案中的代码是针对名为 paypal-bgn-to-euro.php 的插件文件(保存为UTF-8而不包含保加利亚语单词的BOM),该文件位于名为<的文件夹中强>贝宝BGN到欧元即可。该插件告诉PayPal支持BGN。然后,在用户离开订单页面并转到PayPal网站后,它会将货币(和金额)转换为EUR(实际支持PayPal的货币)。每日两次从免费API自动更新汇率。用户以欧元付款,但WooCommerce中创建的订单仍在BGN中。 WooCommerce在验证中检测到错误(有时是两个),因为货币(和金额)不匹配,并且它将订单置于保留状态。然后,插件会将状态更改为处理任何订单,其中包含有关PayPal货币或金额不匹配的订单备注。阅读代码中的注释以获取更多信息。

<?php

/*
Plugin Name: Paypal BGN support
Description: Plugin description here.
Author: Nikolay Nikolov
Version: 1.0.0
*/

/////////////////////BEGIN segment 1
//this segment I got from here and changed it a little: http://devseon.com/en/wordpress-tutorials/woocommerce-add-a-paypal-unsupported-currency
//it lies to PayPal that the BGN currency is supported, and converts it to EUR when the payment is made
//it does not change the currency in the WooCommerce order, it remains the same, and WooCommerce detects an error and it puts the order on hold
//but we fix that in segment 3

add_filter( 'woocommerce_paypal_supported_currencies', 'pbte_add_bgn_paypal_valid_currency' );

function pbte_add_bgn_paypal_valid_currency( $currencies )
{
    array_push ( $currencies , 'BGN' );
    return $currencies;
}

add_filter('woocommerce_paypal_args', 'pbte_convert_bgn_to_eur');

function pbte_convert_bgn_to_eur($paypal_args)
{
    if ( $paypal_args['currency_code'] == 'BGN')
    {
        $convert_rate = get_option('pbte_eur_to_bgn_rate'); //set the converting rate
        $paypal_args['currency_code'] = 'EUR'; //change BGN to EUR
        $i = 1;

        while (isset($paypal_args['amount_' . $i]))
        {
            $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
            ++$i;
        }
    }
    return $paypal_args;
}

/////////////////////END segment 1


/////////////////////BEGIN segment 2
//I made this segment so the exchange rate is updated automatically with a wordpress cron job twice daily

//runs on plugin activation
register_activation_hook( plugin_dir_path( __FILE__ )."paypal-bgn-to-euro.php", 'pbte_activate_plugin' );

//runs on plugin deactivation
register_deactivation_hook( plugin_dir_path( __FILE__ )."paypal-bgn-to-euro.php", 'pbte_deactivate_plugin' );

//when the cron job runs, we call a function to update the exchange rate option value
add_action('pbte_twicedaily_check_eur_event', 'pbte_update_eur_rate_option');

//runs on plugin activation
function pbte_activate_plugin()
{
    pbte_update_eur_rate_option();  //we update the exchange rate option

    if (!wp_next_scheduled('pbte_twicedaily_check_eur_event'))  //adds an cron job (if it is not already added) to udpate the exchange rate twice daily
        wp_schedule_event(time(), 'twicedaily', 'pbte_twicedaily_check_eur_event');
}

//runs on plugin deactivation
function pbte_deactivate_plugin()
{
    wp_clear_scheduled_hook('pbte_twicedaily_check_eur_event'); //removes the cron job we added
}

//gets the exchange rate from a free api and updates our option
function pbte_update_eur_rate_option()
{
    $data = json_decode(file_get_contents("http://api.fixer.io/latest?symbols=BGN&base=EUR")); //gets the exchange rate from a free api
    if(!empty($data->rates->BGN))
    {
        if(get_option('pbte_eur_to_bgn_rate'))
            update_option('pbte_eur_to_bgn_rate', floatval($data->rates->BGN));
        else
            add_option('pbte_eur_to_bgn_rate', floatval($data->rates->BGN)); //if the option does not exist for some reason, we create it
    }
    else //something went wrong while getting the data from the api so we will email the admin
    {
        $message = "This is a message from ".get_site_url()
        .". There is a problem getting the API data in the plugin PayPal BGN support.";
        $subject = "Problem with Paypal BGN support";
        $to_email = get_bloginfo('admin_email');
        $headers[] = 'Content-Type: text/html; charset=UTF-8';
        wp_mail($to_email, $subject, $message, $headers);
    }
}

/////////////////////END segment 2


/////////////////////BEGIN segment 3
//Since the currencies do not match, WooCommerce puts the order on hold. We fix this with this segment.

//this runs when a new note is added to the order
add_filter( 'woocommerce_new_order_note_data', 'pbte_fix_order_status', 10, 2 );

//if the note says that the PayPal currencies or amounts do not match, then we will change the status to processing
function pbte_fix_order_status($a_note, $a_order)
{
    //the check is done in two languages
    if ( strpos($a_note['comment_content'],'PayPal валутите не съвпадат') !== false
    || strpos($a_note['comment_content'],'PayPal currencies do not match') !== false
    || strpos($a_note['comment_content'],'PayPal наличността не отговаря') !== false
    || strpos($a_note['comment_content'],'PayPal amounts do not match') !== false )
    {
        //we create the order var
        $order = new WC_Order($a_order['order_id']);
        //if the current status is on-hold - we change it to processing and add an optional note
        if($order->status == 'on-hold')
            $order->update_status('processing', 'The PayPal BGN support plugin did this note.');
    }

    return $a_note;
}

/////////////////////END segment 3

?>

===解决方案2 ===

---第1步---

您需要使用小插件或在functions.php中添加此代码:

add_filter( 'woocommerce_paypal_supported_currencies', 'add_my_own_paypal_currency' );

function add_my_own_paypal_currency( $currencies )
{
    array_push ( $currencies , 'BGN' );
    return $currencies;
}

---第2步---

当用户在我们网站的订单页面上时,我们将货币(和金额)转换为受支持的货币,因为他选择了PayPal方法。

因此,我们需要为不同的WooCommerce网关使用不同的货币。这正是免费插件的一个功能,名为 Booster for WooCommerce (它也有付费版本)。此功能称为Payment Gateways Currency

当我们激活插件和所选功能时,我们只能为PayPal选择不同的货币,我们在那里输入转换率(由于某种原因,它需要逗号分隔符而不是点)。据说付费版本支持自动更新转换率(我还没有测试过)。

付款完成后,WooCommerce中的订单现在使用新货币(不像解决方案1)。如果他们假设所有订单都是WooCommerce商店货币,则可能会影响您正在使用的其他插件。

===解决方案3 ===

我没有测试过这个,但我发现这个名为“PAYPAL CURRENCY CONVERTER PRO FOR WOOCOMMERCE”的付费插件,并且作者声称它解决了这个问题。

答案 1 :(得分:0)

如果您仍然遇到此问题,这是我找到的解决方案。 更改货币以对应您的货币。

    add_filter( 'woocommerce_paypal_supported_currencies', 'add_a_paypal_valid_currency' );       

function add_a_paypal_valid_currency( $currencies ) {    
  array_push ( $currencies , 'AED' );  // AED = United Arab Emirates Dirham.
  return $currencies;    
}

add_filter('woocommerce_paypal_args', 'convert_to_usd');  

function convert_to_usd($paypal_args){  
  if ( $paypal_args['currency_code'] == 'AED'){  
      $convert_rate = 3.67; // set the converting rate here
      $paypal_args['currency_code'] = 'USD'; // change to USD  
      $i = 1;

      while (isset($paypal_args['amount_' . $i])) {  
          $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);  
          ++$i;  
      }  

  }  
  return $paypal_args;  
}