简体   繁体   中英

woocommerce PayPal link error - comma instead of dot

i am using WooCoomerce and Wordpress in their newest versions. On top i have German Market installed. I enter my prices like 24,99€. The decimal position is separated by an "," and the thousand separator by an "." I Also tried to set the decimal to "." and the thousand to "" (empty)

The payment gateway is PayPal. After getting to the checkout and clicking on the "Pay with PayPal" link the following error appears:

The link you have used to enter the PayPal system contains an incorrectly formatted item amount.

I narrowed it down to the semicolon/comma within amount_1=49,98 ( ...quantity_1=1&amount_1=49,98&item_number_1=5381 )

Comma is not working in the link. If i change it to an dot it works.

Unfortunately i can not find any place in the whole code or Wordpress Settings Area where i can edit the PayPal behavior. Does any one have any idea how to change the "," to a "." within the PayPal link?

Thanks in advance

Try hook in your function file without change core file of woo commerce plugin by use of default woo commerce hook for Paypal,

'woocommerce_paypal_args'

your_function_name($array){
    global $woocommerce;
    //Edit your price to send to Paypal

    return $array;
}
add_filter( 'woocommerce_paypal_args','your_function_name',10,1);

I edited the file in
plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php on line 311 :

FROM:
$this->line_items[ 'amount_' . $index ] = (float) $amount;

TO:
$this->line_items[ 'amount_' . $index ] = (string) str_replace(",", ".", $amount);

Now every comma is converted into a dot and everything works :) IMPORTANT You may have to reset this if there is a woocommerce update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM