Created
December 12, 2023 11:51
-
-
Save InpsydeNiklas/cce603f8bae8d2193b67305d1c671164 to your computer and use it in GitHub Desktop.
WooCommerce PayPal Payments - Copy buyer email address to Memo field in PayPal order (Memo field may not always be present)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Function to get the email from WooCommerce Checkout or Order | |
function get_wc_checkout_email() { | |
if ( $order_id = WC()->session->get('order_awaiting_payment') ) { | |
$order = wc_get_order($order_id); | |
return $order->get_billing_email(); | |
} else { | |
return WC()->checkout()->get_value('billing_email'); | |
} | |
} | |
// Modify the create order data | |
add_filter('ppcp_create_order_request_body_data', static function (array $data): array { | |
if (isset($data['purchase_units'][0]['items'][0]['description'])) { | |
$email = get_wc_checkout_email(); | |
$data['purchase_units'][0]['items'][0]['description'] = $email; | |
} | |
return $data; | |
}); | |
// Modify the patch order data | |
add_filter('ppcp_patch_order_request_body_data', function($patches_array) { | |
if (isset($patches_array[0]['value']['items'][0])) { | |
$email = get_wc_checkout_email(); | |
$patches_array[0]['value']['items'][0]['description'] = $email; | |
} | |
return $patches_array; | |
}, 10); |
thank you
hi sir i sell iptv any option to add it to woocommerce So that PayPal does not know what I am selling
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@beinhd The buyer email address can be displayed below the products like this:
![image](https://private-user-images.githubusercontent.com/70433191/322183324-74e0aac4-d1b6-40c2-9e95-a7c20d2d8aa3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4NjY4MjYsIm5iZiI6MTcyMTg2NjUyNiwicGF0aCI6Ii83MDQzMzE5MS8zMjIxODMzMjQtNzRlMGFhYzQtZDFiNi00MGMyLTllOTUtYTdjMjBkMmQ4YWEzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI1VDAwMTUyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNiNTE1Njc5YTViMGRmODM3MjFhODdiZjVkM2NlNGIzNzMyZmEzOWQxNmZmZDIxNzY5ZjJlMjAwZjNkZDRkMTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1gCDOul89x32lRihh-gdatQ7jfCEkFhN-wkOYxjYd78)
Keep in mind this may be visible to buyers in their PayPal confirmation mails. But to achieve it you can use this code snippet:
If you need more guidance customizing the plugin to your needs, I recommend getting in touch with the support team. Hope this helps!