diff --git a/modules/customer/includes/commerce_customer.checkout_pane.inc b/modules/customer/includes/commerce_customer.checkout_pane.inc index eebdcc0..04ef6a9 100644 --- a/modules/customer/includes/commerce_customer.checkout_pane.inc +++ b/modules/customer/includes/commerce_customer.checkout_pane.inc @@ -58,6 +58,12 @@ function commerce_customer_profile_pane_settings_form($checkout_pane) { ), ), ); + $form['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default'] = array( + '#type' => 'checkbox', + '#title' => t('Copy option enabled by default?'), + '#description' => t('Default copy checkbox state.'), + '#default_value' => variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', FALSE), + ); } return $form; @@ -110,6 +116,7 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec // customer profile, add a checkbox to allow users to toggle this. if (variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy', FALSE) && $source_profile_type_name = variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_source', NULL)) { + $profile_copy_default = variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', FALSE); // Make sure our profile type still exists.. if ($source_profile_type = commerce_customer_profile_type_load($source_profile_type_name)) { @@ -121,7 +128,7 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec '#type' => 'checkbox', '#title' => t('My @target is the same as my @source.', array('@target' => drupal_strtolower($target_profile_type['name']), '@source' => drupal_strtolower($source_profile_type['name']))), '#element_validate' => array('commerce_customer_profile_copy_validate'), - '#default_value' => isset($order->data['profile_copy'][$checkout_pane['pane_id']]['status']) ? $order->data['profile_copy'][$checkout_pane['pane_id']]['status'] : FALSE, + '#default_value' => isset($order->data['profile_copy'][$checkout_pane['pane_id']]['status']) ? $order->data['profile_copy'][$checkout_pane['pane_id']]['status'] : $profile_copy_default, '#weight' => -30, '#ajax' => array( 'callback' => 'commerce_customer_profile_copy_ajax_callback', @@ -136,7 +143,7 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec // If the order data has reference to fields that were copied over, hide // them so we don't confuse the user by still allowing them to edit values. - if (!empty($order->data['profile_copy'][$checkout_pane['pane_id']]['status']) && isset($order->data['profile_copy'][$checkout_pane['pane_id']]['elements'])) { + if (!empty($order->data['profile_copy'][$checkout_pane['pane_id']]['status']) && (isset($order->data['profile_copy'][$checkout_pane['pane_id']]['elements']))) { foreach ($order->data['profile_copy'][$checkout_pane['pane_id']]['elements'] as $field_name => $field) { foreach ($field as $langcode => $items) { foreach ($items as $delta => $item) { @@ -145,6 +152,16 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec } } } + // Default copy address option + elseif (empty($form_state['build_info']['args'][0]->data) && $profile_copy_default) { + foreach ($pane_form as $field_name => $field) { + if(strpos($field_name, '#') !== 0 && $field_name != 'customer_profile') { + if(isset($pane_form[$field_name]['#language'])) { + $pane_form[$field_name][$pane_form[$field_name]['#language']][0]['#access'] = FALSE; + } + } + } + } } }