• Resolved xerowolf

    (@xerowolf)


    Hi I would like to modify certain values like the order total, shipping cost etc before it is sent to paypal. For example convert the prices from USD to another currency. I’ve found the following code example which changes the brand name. But I have not idea of what other variables like price I can modify in “$data” Could someone point me in the right direction it’s would be very much appreciated. Thanks

    add_filter('ppcp_create_order_request_body_data', static function (array $data): array {
     $data['application_context']['brand_name'] = 'New Brand Name';
        return $data;
    });

    https://github.com/woocommerce/woocommerce-paypal-payments/wiki/Actions-and-Filters#modify-the-order-creation-request-body-data

    The following is what I’ve used for PayPal Standard and it works however I need to do something similar with “ppcp_create_order_request_body_data” for it to work with PayPal Payments.

    add_filter('woocommerce_paypal_args', 'convert_XCD_to_USD',10,2);  
    function convert_XCD_to_USD($paypal_args,$order){  
            $convert_rate = 0.37; //set the converting rate   
            $i = 1;  
      
            while (isset($paypal_args['amount_' . $i])) {  
                $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);  
                ++$i;  
            }  
    return $paypal_args;  
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Syde Niklas

    (@niklasinpsyde)

    Hi @xerowolf,

    The filter could be used to change certain things during the order creation. But PayPal Payments works differently compared to PayPal Standard and this code cannot be used the same way. After the order is created at PayPal, it may also be patched later on with additional information.

    The ppcp_create_order_request_body_data filter does not take eventual patches of the order into consideration. So if you were to create an order with modified data, this modification may be overridden again when the order is patched later on.

    The team is looking into improving the usability of the filter, but if you want to change the order currency and/or amount, the best option for now would probably be a multi-currency plugin.

    There are a few minor issues with certain multi-currency use cases, but PayPal Payments should be working fine with most of the popular multi-currency plugins.

    Kind regards,
    Niklas

    Thread Starter xerowolf

    (@xerowolf)

    Thank you for you response
    I’ve tried a few multi currency plugins however they just don’t seem to work the way I need them to. The ideal solution would be a plugin that lets you have one currency in your store but then converts it at checkout to USD for example to play nice with Pay Pal. I’ll take another look at them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using order creation request body data filter’ is closed to new replies.