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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi sir i sell iptv any option to add it to woocommerce So that PayPal does not know what I am selling