In PayPal standard gateway of Woocommerce, I want to make Woocommerce
sends only "order number" as the only item in the cart, instead of the itemized product list.
For that, I tried to edit the class which is responsible for making a PayPal request here:
woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php
I tried to edit get_order_item_names()
function to return "invoice" . $order->get_order_number()
as the name of the only item, but it wasn't successful since if there would be several items, Only the first one was returned with the order number, and other items remained.
Also, I nailed the add_line_item()
function because to approach the purpose, practically there should be only "item_name_1" with the amount of total amount of the card.
$this->line_items[ 'item_name_' . $index ] = $this->limit_length( $item['item_name'], 127 );
$this->line_items[ 'quantity_' . $index ] = $item['quantity'];
$this->line_items[ 'amount_' . $index ] = $item['amount'];
$this->line_items[ 'item_number_' . $index ] = $this->limit_length( $item['item_number'], 127 );
No success here too.
I'd appreciate your assistance.
Instead you could use in this particular case the filter hook
woocommerce_paypal_args
, where you will be able to manipulate the arguments that are used inget_request_url()
function (that will get the PayPal request URL for an order).1) TESTING AND GETTING THE DATA SENT
Just to register and get the arguments sent to paypal, I have used the hook this way:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Now I can get the data simply using this (setting the correct order ID):
Or in a hook ( visible in shop pages in this example only for admins ):
This gives me an output like that (for 2 products and different quantities):
As you can see now, with
woocommerce_paypal_args
you will be able to alter or remove any arguments.2 MANIPULATING THE DATA SENT (example):
We can still use
woocommerce_paypal_args
, filter hook for example on'item_name_1'
key, to replace the items names by the order number, just as you want:Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and works on WooCommerce 3+
See this related answer: How to get WooCommerce order details
I'm using below function for getting Order ID, You can edit and use below function for your needs.