Referring to the solution here posted by Fnik, I'm trying to implement it on my own custom module. But I thing our two sites are configured differently, and since I'm not too familiar with php, I don't get how to adapt his code for my project.
I use Address Field module for customers billing and shipping address. This doc page explains how it stores its subfields. So I need to access these subfields with the hook Fnik pointed.
My code doesn't do it correctly on checkout. Although syntax seems ok, I get errors (specified bellow) when the function is called. Here is my code:
function my_module_commerce_paypal_wps_order_form_data_alter(&$data, $order) {
$profile = user_load($order->uid);
$data['first_name'] = $profile->field_commerce_customer_shipping->commerce_customer_address->first_name['und'][0]['value'];
$data['last_name'] = $profile->field_commerce_customer_shipping->commerce_customer_address->last_name['und'][0]['value'];
$data['address1'] = $profile->field_commerce_customer_shipping->commerce_customer_address->thoroughfare['und'][0]['value'];
}
Some context:
- commerce_paypal_wps_order_form_data_alter is a hook from commerce_paypal_wps.module
- field_commerce_customer_shipping is a Customer profile reference in Order type order entity.
- commerce_customer_address is a Postal address field type in Shipping information Profile type entity.
Erros, 3 different errors for each $data line:
- Undefined property: stdClass::$field_commerce_customer_shipping in my_module_commerce_paypal_wps_order_form_data_alter() (line 27 of ...)
- Trying to get property of non-object in my_module_commerce_paypal_wps_order_form_data_alter() (line 27 of ...)
- Trying to get property of non-object in my_module_commerce_paypal_wps_order_form_data_alter() (line 27 of ...)
Is is the $profile variable declaration that is wrong right in the beginning, or is it the way to refer to fields and subfields?
Thanks in advanced.