diff --git a/modules/customer/includes/commerce_customer.checkout_pane.inc b/modules/customer/includes/commerce_customer.checkout_pane.inc index eebdcc0..4ae6918 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; @@ -121,7 +127,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'] : variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', FALSE), '#weight' => -30, '#ajax' => array( 'callback' => 'commerce_customer_profile_copy_ajax_callback', @@ -136,7 +142,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']) || (empty($form_state['build_info']['args'][0]->data) && variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', FALSE)))) { 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 +151,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) && variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', FALSE)) { + 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; + } + } + } + } } }