Hi, there is an issue with the plugin when trying to check out my specific items in the cart. for example here cosplayhero.de/product/sonstige-stilrichtungen/halloween/anime-tomoe-cosplay-peruecke-silber-weiss-100cm-lang-gerade-hitzebestaendige-synthetische-haar-halloween-anime-peruecken-peruecken-kappe
if you select the variation for 52,95 it always give the error the response is not a valid json response. here is the log, can you please look into it? thanks
This error happens when 3rd party plugins or custom code incorrectly uses the WordPress request filter http_request_args. This plugin uses core WordPress API’s to make requests and there are filters that WordPress provides that some plugins might not be using correctly.
I’d recommend checking for a plugin conflict or theme conflict as a first step.
The same code in the plugin is called regardless of the product. I believe that adds to the evidence that there is a 3rd party plugin that’s causing that conflict.
What I recommend you try is testing for a plugin conflict. For example, deactivate everything but WooCommerce and PayPal. Does the error go away? What about when you test a default theme?
I tested it with plugins deactivated and standard theme. Still happens. Have you checked the log? My ai says that according to the log the product name is empty in the request. But the product has a name. I cant find any solution for this. Customers message me that it happens to them and they cant order.
Yes, and the error that shows over and over again in the log you provided is this one:
ERROR Error creating PayPal order. Msg: WpOrg\Requests\Transport\Curl::request(): Argument #3 ($data) must be of type array|string, boolean given Params: Array
My ai says that according to the log the product name is empty in the request
I am not seeing that in the log file you provided. If there is another file that shows that can you share it?
You are getting the error because your PayPal API call is passing a “boolean” value (true/false) to a place where it expects either an array or a string.
When looking at your order details, most of the data looks correct:
The payer name and email are fine, shipping details are there, products are listed.
But there is something suspicious in the product list:
One of your products has a corrupted name. Specifically, the second product ends with this:
“Anime Tomoe Cosplay Perücke Silber Weiß 100cm Lang Gerade Hitzebeständige Synthetische Haar Halloween Anime Perücken + Per�”
The strange character at the end (“�”) means there is a broken or invalid character encoding.
This is likely coming from the product title in your database or from how the title was saved.
What happens is:
• When your system tries to prepare the data for PayPal, it runs json_encode() to convert the data to JSON.
• If there’s a broken character like this, json_encode() fails and returns “false”.
• When this “false” is sent to the PayPal API, the system throws an error because it expected a proper array or string, not a boolean value.
That’s why you get this error.
So
could this be the reason? can I add a code snippet so such things do not cause the JSON to get broken?
Do you think sth like this works:
// Clean up product names and descriptions before PayPal order creation add_filter(‘woocommerce_paypal_payments_create_order_request’, function($request, $order) { // Safety check if (empty($request[‘purchase_units’][0][‘items’])) { return $request; }
// Loop through all items in the request
foreach ($request['purchase_units'][0]['items'] as &$item) {
if (!empty($item['name'])) {
$item['name'] = clean_utf8_string($item['name']);
}
if (!empty($item['description'])) {
$item['description'] = clean_utf8_string($item['description']);
}
}
return $request;
}, 10, 2);
// Helper function to clean UTF-8 strings function clean_utf8_string($string) { // Convert to UTF-8 and remove invalid characters $string = mb_convert_encoding($string, ‘UTF-8’, ‘UTF-8’); // Optionally strip other problematic characters $string = preg_replace(‘/[^\P{C}]+/u’, ”, $string); // Remove control characters return $string; }
I found the issue after digging a few hours! This probably affects many other plugin users, because it seems like it errors for German characters like ä ö ü which are frequently in use all over…
Thank you for the update regarding the German characters. We’ll do some testing on our end and include an update in the next release.
PayPal’s API accepts UTF-8 so those characters will need to either be removed by the plugin or encoded. In either case, those characters won’t show up in PayPal’s line item display I don’t believe.
Did you end up changing the name for those products or encoding the characters?
I tried to remove the characters for testing, which fixed the issue. Added them back, and the issue was there again. Would you like to debug this further on my store?
There is something else at play here. I performed a test using the same characters as in your product name and there was no issue with the German characters. Here is a screenshot showing the line item in PayPal.
That tells me that in the Curl request, the response to encoding the body of the request is a boolean of false which means on your site, the encoding is failing.
The PayPal plugin uses the json_encode function like this:
Well at least on my site, as I mentioned, when I remove the special characters it works fine. Could you maybe give me a snippet to hook into the encoding, so it converts the special characters before actually doing the encoding? This would be awesome, as I was not able to create this by myself. Thanks!