Skip to content

Instantly share code, notes, and snippets.

@InpsydeNiklas
Created December 12, 2023 11:51
Show Gist options
  • Save InpsydeNiklas/cce603f8bae8d2193b67305d1c671164 to your computer and use it in GitHub Desktop.
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)
<?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);
@beinhd
Copy link

beinhd commented Jun 18, 2024

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