Skip to main content

Remove Line Items from PayPal Orders

By default, PayPal receives detailed information about every item in your customer's cart, including product names, quantities, and individual prices. However, PayPal's API has specific requirements for how this data must be formatted, and sometimes your WooCommerce store data doesn't align with these restrictions.

The most common issue occurs when your store uses fractional quantities instead of whole numbers. PayPal's API requires that all line item quantities be whole numbers, so if your store sells products by weight, volume, or other fractional measurements (like 2.5 pounds of coffee or 1.75 yards of fabric), the payment will fail when PayPal tries to process the itemized data.

When would you use this?

This code is useful for stores that sell products with fractional quantities and prefer to send only the order total to PayPal rather than itemized details. While the plugin typically handles quantity formatting automatically, some merchants want complete control over what information PayPal receives.

Common scenarios include stores selling products by weight (food items, bulk materials), by volume (liquids, chemicals), by length (fabric, rope, lumber), or any situation where customers can purchase partial units rather than complete items. Some merchants also prefer this approach for simplified PayPal transaction records or when dealing with complex product configurations that don't translate well to PayPal's format.

The Code

This code removes both the itemized breakdown and individual product details from PayPal order requests. The transaction will still process normally, but PayPal will only receive the total amount. Add this code to your theme's functions.php file or a custom plugin:

/**
* Remove line items when PayPal order is first created
* @param \PaymentPlugins\PayPalSDK\PurchaseUnit $purchase_unit
*/
add_filter('wc_ppcp_purchase_unit_factory_from_cart', function($purchase_unit){
$purchase_unit->getAmount()->setBreakdown(null);
$purchase_unit->setItems(null);
return $purchase_unit;
});

/**
* Remove line items when payment is being finalized
* @param \PaymentPlugins\PayPalSDK\PurchaseUnit $purchase_unit
*/
add_filter('wc_ppcp_purchase_unit_factory_from_order', function($purchase_unit){
$purchase_unit->getAmount()->setBreakdown(null);
$purchase_unit->setItems(null);
return $purchase_unit;
});

How the Code Works

The code uses two separate hooks to ensure line items are removed at different stages of the PayPal payment process. Both filters perform identical operations but are called at different times during the transaction flow.

The first filter (wc_ppcp_purchase_unit_factory_from_cart) runs when the PayPal order is initially created from the cart contents. This happens when customers first interact with PayPal payment options on your checkout page or cart page.

The second filter (wc_ppcp_purchase_unit_factory_from_order) is called when the payment is being finalized and the order is being processed. This ensures that line items are removed even if the purchase unit is rebuilt during the payment process.

Both filters call setBreakdown(null) to remove the detailed amount breakdown and setItems(null) to eliminate individual product details from the PayPal request. Using both filters ensures comprehensive coverage throughout the entire payment flow.

What Your Customers Will See

From your customer's perspective, the checkout experience remains identical. They'll still see all product details, quantities, and pricing during checkout on your WooCommerce site. The only difference is that PayPal will display a simplified transaction record showing just the total amount rather than itemized details.

In your PayPal dashboard, transactions will appear with the order total and basic information like the customer's name and email, but without the individual product breakdown that normally accompanies each transaction.

Important Considerations

While removing line items solves the fractional quantity issue, you'll lose itemized transaction details in your PayPal dashboard. PayPal will only see the total order amount without knowing what specific products were purchased.

This solution works for all PayPal payment methods supported by the plugin, including standard PayPal checkout, credit card processing, and Pay Later options. The modification only affects what data is sent to PayPal and doesn't impact your WooCommerce order records or customer receipts.

Testing Your Implementation

To verify the code is working correctly, add products with fractional quantities to a test cart in your WooCommerce store (for example, 2.5 units of a product). Complete the transaction using your PayPal sandbox environment. The order should process successfully, and when you check your PayPal sandbox dashboard, you'll see the transaction shows only the total amount without individual product details.

If you were experiencing PayPal API errors with fractional quantities before implementing this code, those errors should now be resolved.