Skip to content

Instantly share code, notes, and snippets.

@InpsydeNiklas
Created June 9, 2023 09:19
Show Gist options
  • Save InpsydeNiklas/bebf38d610dd3d928412c5ecde4925ee to your computer and use it in GitHub Desktop.
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"
<?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;
});
@joshuwash
Copy link

@nuwangithu I can help you with that. Let me know if you still need help.

@rohitr825
Copy link

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