Using WooCommerce PayPal Pro Payflow and custom comment fields.

PayPal Pro plugin for WooCommerce
PayPal Pro plugin for WooCommerce

If you are a fan of WooCommerce, and have used it for any higher-volume ecommerce sites, you have probably looked into one of the commercial PayPal gateways. The commercial plugin “PayPal Pro” from WooThemes provides a great and easy to setup plugin to get you started.
That said, if you run an ecommerce site within a company that handles PayPal transaction from several sources, you have probably been begged by your accounting department to add in site-specific notes or code in the comments fields that are provided as part of PayPal’s core transaction fields. The version of the plugin didn’t support this, so I set out to find a way.

Comment field in the PayPal transaction reports show in the far right.
Comment field in the PayPal transaction reports show in the far right.

When using these fields in a transaction, you can pass whatever information you want (within reason) to be stored in the comment fields of the transaction. These notes will then show up in the transaction report run by your accounting people.
These are very helping when working to differentiate transactions from several sites in your reports, trying to resolve chargeback issues, and in identifying trends in your transactions across sites.
After some research, I found that a simple addition to the file class-wc-gateway-paypal-pro-payflow.php file (located in /includes directory of the plugin) will do the trick.

public function do_payment( $order, $card_number, $card_exp, $card_cvc ) {
// Send request to paypal
try {
$url = $this->testmode ? $this->testurl : $this->liveurl;
$post_data = $this->get_post_data( $order );
$post_data['ACCT'] = $card_number; // Credit Card
$post_data['EXPDATE'] = $card_exp; //MMYY
$post_data['CVV2'] = $card_cvc; // CVV code
$post_data['COMMENT1'] = 'WooCommerce'; // order source
$post_data['COMMENT2'] = $order->get_order_number(); // order number

$response = wp_remote_post( $url, array(
'method' => 'POST',
'body' => urldecode( http_build_query( apply_filters( 'woocommerce-gateway-paypal-pro_payflow_request', $post_data, $order ), null, '&' ) ),
'timeout' => 70,
'sslverify' => false,
'user-agent' => 'WooCommerce',
'httpversion' => '1.1'

You can see in the code above a reference to COMMENT1 and COMMENT2 as elements of the $post_data array. Simply adding these to the array will allow values stored there to be passed to PayPal. In my case, I simply added a static “WooCommerce” to COMMENT1, and pulled the order number from the $order object passed into the function to store into COMMENT2.
Please note, I didn’t look extensively into any action hook or filter that I could have added this code to. Modifying the code this way will break (or potentially cause problems with) any standard plugin upgrades. If you find another way to do this via an established hook, please let me know. To my knowledge there is no hook for this, unless the $post_data can be altered outside the function.