Adding Data to a Variable in a Contributed Module I'd like to add some data to a variable in a contributed module but I'm not sure how to do that with a custom module.

The Question:

The module I need to 'hack' is the Drupal Commerce PayPal WPP Module. I talked with PayPal and they said specifically I'd need to hack this file: 'commerce_paypal_wpp.module'. They said on line 365 if I added more data to the 'CUSTOM' variable (see below) it would pass that on to PayPal. Sweet! But how can I do that?

My Proposed Solution

I'm thinking I will create my variables to add to CUSTOM, like so (this is how I'd normally do it in PHP of course:

$fname = 'examplename';
$lname = 'examplelastname';
$arr = array($fname, $lname);
$allthedata = implode('+', $arr);
CUSTOM = $allthedata


It's that last line I don't know how to add properly! This, because 'CUSTOM' is already defined in the contributed module (see below).

The Function I Need to Edit:

The function in question in the contributed module is:

function commerce_paypal_wpp_submit_form_submit($payment_method, 
$pane_form, $pane_values, $order, $charge) { 


And the relevant code with 'CUSTOM' > the variable I want to change:

// Add additional transaction invormation to the request array.
  $nvp += array(
    // Order Information; we append the timestamp to the order number to 
allow
    // for multiple transactions against the same order.
    'INVNUM' =&gt; substr($order-&gt;order_number, 0, 127) . '-' . REQUEST_TIME,
    'CUSTOM' =&gt; substr(t('Order @number', array('@number' =&gt; $order-
&gt;order_number)), 0, 256),
    'DESC' =&gt; substr(implode(', ', $description), 0, 127),

    // Customer Information
    'EMAIL' =&gt; substr($order-&gt;mail, 0, 127),
    'IPADDRESS' =&gt; substr($ip_address, 0, 15),
    'FIRSTNAME' =&gt; substr($billing_address['first_name'], 0, 25),
    'LASTNAME' =&gt; substr($billing_address['last_name'], 0, 25),
    'STREET' =&gt; substr($billing_address['thoroughfare'], 0, 100),
    'STREET2' =&gt; substr($billing_address['premise'], 0, 100),
    'CITY' =&gt; substr($billing_address['locality'], 0, 40),
    'STATE' =&gt; substr($billing_address['administrative_area'], 0, 40),
    'COUNTRYCODE' =&gt; $billing_address['country'],
    'ZIP' =&gt; substr($billing_address['postal_code'], 0, 20),
  );
}
You will not need to 'hack' this module, you can use a legitimate hook to modify the $nvp array, hook_commerce_paypal_api_request_alter

At line 382 of the commerce_paypal_wpp.module, right after the part you mention, the whole array is passed to the commerce_paypal_api_request where the mentioned hook is called early on, to allow modifications from other modules.

Following your example code, your hook implementation would look like this:

function yourmodule_commerce_paypal_api_request_alter(&amp;$nvp, $order, $payment_method) {
  ...
  $fname = 'examplename';
  $lname = 'examplelastname';
  $arr = array($fname, $lname);
  $allthedata = implode('+', $arr);
  $nvp['CUSTOM'] = $allthedata;
  ...
}


Hope this helps!