Improved edit address. Closes #689.

This commit is contained in:
Mike Jolley 2012-02-22 21:06:08 +00:00
parent f22738b975
commit 04fde0a603
5 changed files with 96 additions and 81 deletions

View File

@ -160,6 +160,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Hooks for quantity selectors
* Load order of the translation files tweaked so ones in wp-content/languages get priority
* Improved woocommerce_get_template_part
* Improved edit my address page when accessed directly
= 1.4.4 - 18/02/2012 =
* Fix for remove coupon links after ajax update of shipping

View File

@ -171,15 +171,10 @@ add_action( 'template_redirect', 'woocommerce_save_address' );
* @since 1.4
*/
function woocommerce_get_address_to_edit() {
$load_address = 'billing';
if ( isset( $_GET[ 'address' ] ) )
$load_address = esc_attr( $_GET[ 'address' ] );
if ( $load_address == 'billing' )
$load_address = 'billing';
else
$load_address = 'shipping';
$load_address = ( isset( $_GET[ 'address' ] ) ) ? esc_attr( $_GET[ 'address' ] ) : '';
$load_address = ( $load_address == 'billing' || $load_address == 'shipping' ) ? $load_address : '';
return $load_address;
}

View File

@ -8,19 +8,27 @@ global $woocommerce;
<?php $woocommerce->show_messages(); ?>
<form action="<?php echo esc_url( add_query_arg( 'address', $load_address, get_permalink( woocommerce_get_page_id('edit_address') ) ) ); ?>" method="post">
<h3><?php if ($load_address=='billing') _e('Billing Address', 'woocommerce'); else _e('Shipping Address', 'woocommerce'); ?></h3>
<?php
foreach ($address as $key => $field) :
woocommerce_form_field( $key, $field, get_user_meta( get_current_user_id(), $key, true ) );
endforeach;
?>
<input type="submit" class="button" name="save_address" value="<?php _e('Save Address', 'woocommerce'); ?>" />
<?php $woocommerce->nonce_field('edit_address') ?>
<input type="hidden" name="action" value="edit_address" />
<?php if (!$load_address) : ?>
</form>
<?php woocommerce_get_template('myaccount/my-address.php'); ?>
<?php else : ?>
<form action="<?php echo esc_url( add_query_arg( 'address', $load_address, get_permalink( woocommerce_get_page_id('edit_address') ) ) ); ?>" method="post">
<h3><?php if ($load_address=='billing') _e('Billing Address', 'woocommerce'); else _e('Shipping Address', 'woocommerce'); ?></h3>
<?php
foreach ($address as $key => $field) :
woocommerce_form_field( $key, $field, get_user_meta( get_current_user_id(), $key, true ) );
endforeach;
?>
<input type="submit" class="button" name="save_address" value="<?php _e('Save Address', 'woocommerce'); ?>" />
<?php $woocommerce->nonce_field('edit_address') ?>
<input type="hidden" name="action" value="edit_address" />
</form>
<?php endif; ?>

View File

@ -82,64 +82,7 @@ endif;
<h2><?php _e('My Addresses', 'woocommerce'); ?></h2>
<p><?php _e('The following addresses will be used on the checkout page by default.', 'woocommerce'); ?></p>
<div class="col2-set addresses">
<?php woocommerce_get_template('myaccount/my-address.php'); ?>
<div class="col-1">
<header class="title">
<h3><?php _e('Billing Address', 'woocommerce'); ?></h3>
<a href="<?php echo esc_url( add_query_arg('address', 'billing', get_permalink(woocommerce_get_page_id('edit_address'))) ); ?>" class="edit"><?php _e('Edit', 'woocommerce'); ?></a>
</header>
<address>
<?php
$address = array(
'first_name' => get_user_meta( $customer_id, 'billing_first_name', true ),
'last_name' => get_user_meta( $customer_id, 'billing_last_name', true ),
'company' => get_user_meta( $customer_id, 'billing_company', true ),
'address_1' => get_user_meta( $customer_id, 'billing_address_1', true ),
'address_2' => get_user_meta( $customer_id, 'billing_address_2', true ),
'city' => get_user_meta( $customer_id, 'billing_city', true ),
'state' => get_user_meta( $customer_id, 'billing_state', true ),
'postcode' => get_user_meta( $customer_id, 'billing_postcode', true ),
'country' => get_user_meta( $customer_id, 'billing_country', true )
);
$formatted_address = $woocommerce->countries->get_formatted_address( $address );
if (!$formatted_address) _e('You have not set up a billing address yet.', 'woocommerce'); else echo $formatted_address;
?>
</address>
</div><!-- /.col-1 -->
<div class="col-2">
<header class="title">
<h3><?php _e('Shipping Address', 'woocommerce'); ?></h3>
<a href="<?php echo esc_url( add_query_arg('address', 'shipping', get_permalink(woocommerce_get_page_id('edit_address'))) ); ?>" class="edit"><?php _e('Edit', 'woocommerce'); ?></a>
</header>
<address>
<?php
$address = array(
'first_name' => get_user_meta( $customer_id, 'shipping_first_name', true ),
'last_name' => get_user_meta( $customer_id, 'shipping_last_name', true ),
'company' => get_user_meta( $customer_id, 'shipping_company', true ),
'address_1' => get_user_meta( $customer_id, 'shipping_address_1', true ),
'address_2' => get_user_meta( $customer_id, 'shipping_address_2', true ),
'city' => get_user_meta( $customer_id, 'shipping_city', true ),
'state' => get_user_meta( $customer_id, 'shipping_state', true ),
'postcode' => get_user_meta( $customer_id, 'shipping_postcode', true ),
'country' => get_user_meta( $customer_id, 'shipping_country', true )
);
$formatted_address = $woocommerce->countries->get_formatted_address( $address );
if (!$formatted_address) _e('You have not set up a shipping address yet.', 'woocommerce'); else echo $formatted_address;
?>
</address>
</div><!-- /.col-2 -->
</div><!-- /.col2-set -->
<?php
do_action('woocommerce_after_my_account');

View File

@ -0,0 +1,68 @@
<?php
/**
* My Addresses
*/
global $woocommerce;
$customer_id = get_current_user_id();
?>
<div class="col2-set addresses">
<div class="col-1">
<header class="title">
<h3><?php _e('Billing Address', 'woocommerce'); ?></h3>
<a href="<?php echo esc_url( add_query_arg('address', 'billing', get_permalink(woocommerce_get_page_id('edit_address'))) ); ?>" class="edit"><?php _e('Edit', 'woocommerce'); ?></a>
</header>
<address>
<?php
$address = array(
'first_name' => get_user_meta( $customer_id, 'billing_first_name', true ),
'last_name' => get_user_meta( $customer_id, 'billing_last_name', true ),
'company' => get_user_meta( $customer_id, 'billing_company', true ),
'address_1' => get_user_meta( $customer_id, 'billing_address_1', true ),
'address_2' => get_user_meta( $customer_id, 'billing_address_2', true ),
'city' => get_user_meta( $customer_id, 'billing_city', true ),
'state' => get_user_meta( $customer_id, 'billing_state', true ),
'postcode' => get_user_meta( $customer_id, 'billing_postcode', true ),
'country' => get_user_meta( $customer_id, 'billing_country', true )
);
$formatted_address = $woocommerce->countries->get_formatted_address( $address );
if (!$formatted_address) _e('You have not set up a billing address yet.', 'woocommerce'); else echo $formatted_address;
?>
</address>
</div><!-- /.col-1 -->
<div class="col-2">
<header class="title">
<h3><?php _e('Shipping Address', 'woocommerce'); ?></h3>
<a href="<?php echo esc_url( add_query_arg('address', 'shipping', get_permalink(woocommerce_get_page_id('edit_address'))) ); ?>" class="edit"><?php _e('Edit', 'woocommerce'); ?></a>
</header>
<address>
<?php
$address = array(
'first_name' => get_user_meta( $customer_id, 'shipping_first_name', true ),
'last_name' => get_user_meta( $customer_id, 'shipping_last_name', true ),
'company' => get_user_meta( $customer_id, 'shipping_company', true ),
'address_1' => get_user_meta( $customer_id, 'shipping_address_1', true ),
'address_2' => get_user_meta( $customer_id, 'shipping_address_2', true ),
'city' => get_user_meta( $customer_id, 'shipping_city', true ),
'state' => get_user_meta( $customer_id, 'shipping_state', true ),
'postcode' => get_user_meta( $customer_id, 'shipping_postcode', true ),
'country' => get_user_meta( $customer_id, 'shipping_country', true )
);
$formatted_address = $woocommerce->countries->get_formatted_address( $address );
if (!$formatted_address) _e('You have not set up a shipping address yet.', 'woocommerce'); else echo $formatted_address;
?>
</address>
</div><!-- /.col-2 -->
</div><!-- /.col2-set -->