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;
});
@InpsydeNiklas
Copy link
Author

@nuwangithu You can insert the snippet above (without the <?php) with a plugin like Code Snippets. Alternatively, it can be inserted into the function.php file of your active child theme.
Please consider reaching out to the PayPal Payments support team directly for more guidance. Thanks!

@nuwangithu
Copy link

Actually my product's item title like Windows 10 Genuine License Key, But I need it in the transaction "Order 456" Like this. Can I do it using this method?

@nuwangithu
Copy link

@InpsydeNiklas Any updates Sir.

@InpsydeNiklas
Copy link
Author

@nuwangithu Please contact the support team if you need help. Thanks!

@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