Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Created July 1, 2014 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save claudiosanches/cdf77f6b2be0a6d92937 to your computer and use it in GitHub Desktop.
Save claudiosanches/cdf77f6b2be0a6d92937 to your computer and use it in GitHub Desktop.
Custom PayPal Adaptive Payments args
<?php
/**
* Custom PayPal Adaptive Payments args.
*
* @param array $args
* @param WC_Order $order
* @return array
*/
function custom_woocommerce_paypal_ap_payment_args( $args, $order ) {
$args['receiverList'] = array(
'receiver' => array(
array(
'amount' => '40.00',
'email' => 'your@email.com',
// 'primary' => 'true' // use this only for Chained Payment.
)
),
'receiver' => array(
array(
'amount' => '15.00',
'email' => 'receiver1@email.com'
)
),
'receiver' => array(
array(
'amount' => '60.00',
'email' => 'receiver2@email.com'
)
)
);
return $args;
}
add_filter( 'woocommerce_paypal_ap_payment_args', 'custom_woocommerce_paypal_ap_payment_args', 10, 2 );
@neovea
Copy link

neovea commented Aug 18, 2014

Hello,

I tried your snippet, and unfortunately, only the last amount is made.

Here is my code :

function custom_woocommerce_paypal_ap_payment_args( $args, $order ) {
    $args['receiverList'] = array(
        'receiver' => array(
            array(
                'amount' => '40.00',
                'email'  => 'paypal-fs-de@dispostable.com'
            )
        ),
        'receiver' => array(
            array(
                'amount' => '60.00',
                'email'  => 'paypal-fs-fr@dispostable.com'
            )
        )
    );

    return $args;
}

add_filter( 'woocommerce_paypal_ap_payment_args', 'custom_woocommerce_paypal_ap_payment_args', 10, 2 );

This is a bit weird. Do you know why ?

Thanks for helping

@claudiosanches
Copy link
Author

@neovea Have you tested to do what?
This is for advanced users who need to do some custom. If otherwise you do not need to use it.

@neovea
Copy link

neovea commented Aug 27, 2014

Hello,

I have a website for a NGO, on which people make donation AND can buy products.
There are 5 different countries in which this NGO is installed and so as many paypal accounts :
Depending on the countries from which the payment is done by the customer, the money has to go to a specific paypal account.

More precisely : for products in the cart -> The split must always send the money the account A.
And for donation in the same cart -> To the specified paypal account B (variable depending on the country).
This is the way it has to work on my side.

In my code, the $args are dynamically fill with the right amounts and email adresses. But the matter I'm having with your piece of code is that only the last receiver is funded. The other one is simply ignored. Event with your snippet, as it.

What would you recommand ?

Thanks for answering

@neovea
Copy link

neovea commented Aug 27, 2014

Ok. I figured it out :
It seems like the way the array is build messes up the payment. I forked the code with the correction if you want to check.
Thanks

@carterbryden
Copy link

When is this filter triggered? Is there a way to set the receivers on product creation?

@thisleenoble
Copy link

Neovea is correct. The example code displayed here is not valid. It is setting the same key 'receiver' multiple times on the same array, so only the last one will ever be recorded. I'm sure his fork addressed this. This page should be updated to avoid confusion.

@manoj611
Copy link

If you get only last amount than try this code
EX:

$receivers => array(
array(
'amount'=>reviever amount FIRST here,
'email'=> reviever paypal FIRST email here here
),
array(
'amount'=>reviever amount SECOND here,
'email'=> reviever paypal SECOND email here here
),
array(
'amount'=>reviever amount THIRD here,
'email'=> reviever paypal THIRD email here here
)
);

$args['receiverList'] = array(
    'receiver' => array($receivers)
);
return $args;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment