Created
June 9, 2023 09:19
-
-
Save InpsydeNiklas/bebf38d610dd3d928412c5ecde4925ee to your computer and use it in GitHub Desktop.
PayPal Payments - unset SKU, empty description, and replace the product title with "Order #123"
This file contains hidden or 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 | |
add_filter('ppcp_create_order_request_body_data', function (array $data): array { | |
foreach ($data['purchase_units'] as $index => $purchase_unit) { | |
// extract order number from custom_id | |
$order_number = isset($purchase_unit['custom_id']) ? $purchase_unit['custom_id'] : 'N/A'; | |
foreach ($purchase_unit['items'] as $item_index => $item) { | |
$data['purchase_units'][$index]['items'][$item_index]['description'] = ''; | |
unset($data['purchase_units'][$index]['items'][$item_index]['sku']); | |
$data['purchase_units'][$index]['items'][$item_index]['name'] = 'Order #' . $order_number; | |
} | |
} | |
return $data; | |
}); | |
add_filter('ppcp_patch_order_request_body_data', function (array $patches_array): array { | |
foreach ($patches_array as $patch_index => $patch) { | |
if (isset($patch['value']['items'])) { | |
// extract order number from custom_id | |
$order_number = isset($patch['value']['custom_id']) ? $patch['value']['custom_id'] : 'N/A'; | |
foreach ($patch['value']['items'] as $item_index => $item) { | |
$patches_array[$patch_index]['value']['items'][$item_index]['description'] = ''; | |
unset($patches_array[$patch_index]['value']['items'][$item_index]['sku']); | |
$patches_array[$patch_index]['value']['items'][$item_index]['name'] = 'Order #' . $order_number; | |
} | |
} | |
} | |
return $patches_array; | |
}); |
@nuwangithu I can help you with that. Let me know if you still need help.
hey can you please tell me how to change title and description in paypal for a product like microsoft office or windows.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nuwangithu Please contact the support team if you need help. Thanks!