Classes for order info in my-account. Closes #1363.

This commit is contained in:
Mike Jolley 2012-08-12 13:44:00 +01:00
parent 402799c0eb
commit 3edf155b50
2 changed files with 50 additions and 49 deletions

View File

@ -151,6 +151,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
== Changelog == == Changelog ==
= 1.6.4 = = 1.6.4 =
* Tweak - Classes for order info in my-account
* Fix - Missing grouped product cart buttons * Fix - Missing grouped product cart buttons
* Fix - Notice in invoice template with number_format * Fix - Notice in invoice template with number_format
* Fix - Made variation get_image() return instead of echo * Fix - Made variation get_image() return instead of echo

View File

@ -1,32 +1,32 @@
<?php <?php
/** /**
* My Account Shortcodes * My Account Shortcodes
* *
* Shows the 'my account' section where the customer can view past orders and update their information. * Shows the 'my account' section where the customer can view past orders and update their information.
* *
* @package WooCommerce * @package WooCommerce
* @category Shortcode * @category Shortcode
* @author WooThemes * @author WooThemes
*/ */
/** /**
* Shortcode wrappers * Shortcode wrappers
*/ */
function get_woocommerce_my_account( $atts ) { function get_woocommerce_my_account( $atts ) {
global $woocommerce; global $woocommerce;
return $woocommerce->shortcode_wrapper('woocommerce_my_account', $atts); return $woocommerce->shortcode_wrapper('woocommerce_my_account', $atts);
} }
function get_woocommerce_edit_address() { function get_woocommerce_edit_address() {
global $woocommerce; global $woocommerce;
return $woocommerce->shortcode_wrapper('woocommerce_edit_address'); return $woocommerce->shortcode_wrapper('woocommerce_edit_address');
} }
function get_woocommerce_change_password() { function get_woocommerce_change_password() {
global $woocommerce; global $woocommerce;
return $woocommerce->shortcode_wrapper('woocommerce_change_password'); return $woocommerce->shortcode_wrapper('woocommerce_change_password');
} }
function get_woocommerce_view_order() { function get_woocommerce_view_order() {
global $woocommerce; global $woocommerce;
return $woocommerce->shortcode_wrapper('woocommerce_view_order'); return $woocommerce->shortcode_wrapper('woocommerce_view_order');
} }
/** /**
@ -37,36 +37,36 @@ function get_woocommerce_view_order() {
*/ */
function woocommerce_my_account( $atts ) { function woocommerce_my_account( $atts ) {
global $woocommerce, $current_user; global $woocommerce, $current_user;
$woocommerce->nocache(); $woocommerce->nocache();
if ( ! is_user_logged_in() ) : if ( ! is_user_logged_in() ) :
woocommerce_get_template( 'myaccount/form-login.php' ); woocommerce_get_template( 'myaccount/form-login.php' );
else : else :
extract(shortcode_atts(array( extract(shortcode_atts(array(
'recent_orders' => 5 'recent_orders' => 5
), $atts)); ), $atts));
$recent_orders = ('all' == $recent_orders) ? -1 : $recent_orders; $recent_orders = ('all' == $recent_orders) ? -1 : $recent_orders;
get_currentuserinfo(); get_currentuserinfo();
woocommerce_get_template( 'myaccount/my-account.php', array( woocommerce_get_template( 'myaccount/my-account.php', array(
'current_user' => $current_user, 'current_user' => $current_user,
'recent_orders' => $recent_orders 'recent_orders' => $recent_orders
) ); ) );
endif; endif;
} }
/** /**
* Edit Address Shortcode. * Edit Address Shortcode.
* *
* @todo Address fields should be loaded using the array defined in * @todo Address fields should be loaded using the array defined in
* the checkout class, and the fields should be built off of that. * the checkout class, and the fields should be built off of that.
* *
* Adapted from spencerfinnell's pull request * Adapted from spencerfinnell's pull request
@ -76,15 +76,15 @@ function woocommerce_my_account( $atts ) {
*/ */
function woocommerce_edit_address() { function woocommerce_edit_address() {
global $woocommerce; global $woocommerce;
$woocommerce->nocache(); $woocommerce->nocache();
if ( ! is_user_logged_in() ) return; if ( ! is_user_logged_in() ) return;
$load_address = woocommerce_get_address_to_edit(); $load_address = woocommerce_get_address_to_edit();
$address = $woocommerce->countries->get_address_fields( get_user_meta( get_current_user_id(), $load_address . '_country', true ), $load_address . '_' ); $address = $woocommerce->countries->get_address_fields( get_user_meta( get_current_user_id(), $load_address . '_country', true ), $load_address . '_' );
woocommerce_get_template( 'myaccount/form-edit-address.php', array( woocommerce_get_template( 'myaccount/form-edit-address.php', array(
'load_address' => $load_address, 'load_address' => $load_address,
'address' => $address 'address' => $address
@ -108,21 +108,21 @@ function woocommerce_save_address() {
return; return;
$woocommerce->verify_nonce( 'edit_address' ); $woocommerce->verify_nonce( 'edit_address' );
$validation = $woocommerce->validation(); $validation = $woocommerce->validation();
$user_id = get_current_user_id(); $user_id = get_current_user_id();
if ( $user_id <= 0 ) return; if ( $user_id <= 0 ) return;
$load_address = woocommerce_get_address_to_edit(); $load_address = woocommerce_get_address_to_edit();
$address = $woocommerce->countries->get_address_fields( esc_attr($_POST[ $load_address . '_country' ]), $load_address . '_' ); $address = $woocommerce->countries->get_address_fields( esc_attr($_POST[ $load_address . '_country' ]), $load_address . '_' );
foreach ($address as $key => $field) : foreach ($address as $key => $field) :
if (!isset($field['type'])) $field['type'] = 'text'; if (!isset($field['type'])) $field['type'] = 'text';
// Get Value // Get Value
switch ($field['type']) : switch ($field['type']) :
case "checkbox" : case "checkbox" :
@ -132,26 +132,26 @@ function woocommerce_save_address() {
$_POST[$key] = isset($_POST[$key]) ? woocommerce_clean($_POST[$key]) : ''; $_POST[$key] = isset($_POST[$key]) ? woocommerce_clean($_POST[$key]) : '';
break; break;
endswitch; endswitch;
// Hook to allow modification of value // Hook to allow modification of value
$_POST[$key] = apply_filters('woocommerce_process_myaccount_field_' . $key, $_POST[$key]); $_POST[$key] = apply_filters('woocommerce_process_myaccount_field_' . $key, $_POST[$key]);
// Validation: Required fields // Validation: Required fields
if ( isset($field['required']) && $field['required'] && empty($_POST[$key]) ) $woocommerce->add_error( $field['label'] . ' ' . __('is a required field.', 'woocommerce') ); if ( isset($field['required']) && $field['required'] && empty($_POST[$key]) ) $woocommerce->add_error( $field['label'] . ' ' . __('is a required field.', 'woocommerce') );
// Postcode // Postcode
if ($key=='billing_postcode' || $key=='shipping_postcode') : if ($key=='billing_postcode' || $key=='shipping_postcode') :
if ( ! $validation->is_postcode( $_POST[$key], $_POST[ $load_address . '_country' ] ) ) : if ( ! $validation->is_postcode( $_POST[$key], $_POST[ $load_address . '_country' ] ) ) :
$woocommerce->add_error( __( 'Please enter a valid postcode/ZIP.', 'woocommerce' ) ); $woocommerce->add_error( __( 'Please enter a valid postcode/ZIP.', 'woocommerce' ) );
else : else :
$_POST[$key] = $validation->format_postcode( $_POST[$key], $_POST[ $load_address . '_country' ] ); $_POST[$key] = $validation->format_postcode( $_POST[$key], $_POST[ $load_address . '_country' ] );
endif; endif;
endif; endif;
endforeach; endforeach;
if ( $woocommerce->error_count() == 0 ) { if ( $woocommerce->error_count() == 0 ) {
foreach ($address as $key => $field) : foreach ($address as $key => $field) :
update_user_meta( $user_id, $key, $_POST[$key] ); update_user_meta( $user_id, $key, $_POST[$key] );
endforeach; endforeach;
@ -173,7 +173,7 @@ add_action( 'template_redirect', 'woocommerce_save_address' );
function woocommerce_get_address_to_edit() { function woocommerce_get_address_to_edit() {
$load_address = ( isset( $_GET[ 'address' ] ) ) ? esc_attr( $_GET[ 'address' ] ) : ''; $load_address = ( isset( $_GET[ 'address' ] ) ) ? esc_attr( $_GET[ 'address' ] ) : '';
$load_address = ( $load_address == 'billing' || $load_address == 'shipping' ) ? $load_address : ''; $load_address = ( $load_address == 'billing' || $load_address == 'shipping' ) ? $load_address : '';
return $load_address; return $load_address;
@ -187,7 +187,7 @@ function woocommerce_get_address_to_edit() {
*/ */
function woocommerce_change_password() { function woocommerce_change_password() {
global $woocommerce; global $woocommerce;
if ( ! is_user_logged_in() ) return; if ( ! is_user_logged_in() ) return;
woocommerce_get_template( 'myaccount/form-change-password.php' ); woocommerce_get_template( 'myaccount/form-change-password.php' );
@ -214,17 +214,17 @@ function woocommerce_save_password() {
if ( $user_id <= 0 ) if ( $user_id <= 0 )
return; return;
$_POST = array_map( 'woocommerce_clean', $_POST ); $_POST = array_map( 'woocommerce_clean', $_POST );
if ( empty( $_POST[ 'password_1' ] ) || empty( $_POST[ 'password_2' ] ) ) if ( empty( $_POST[ 'password_1' ] ) || empty( $_POST[ 'password_2' ] ) )
$woocommerce->add_error( __( 'Please enter your password.', 'woocommerce' ) ); $woocommerce->add_error( __( 'Please enter your password.', 'woocommerce' ) );
if ( $_POST[ 'password_1' ] !== $_POST[ 'password_2' ] ) if ( $_POST[ 'password_1' ] !== $_POST[ 'password_2' ] )
$woocommerce->add_error( __('Passwords do not match.', 'woocommerce') ); $woocommerce->add_error( __('Passwords do not match.', 'woocommerce') );
if ( $woocommerce->error_count() == 0 ) { if ( $woocommerce->error_count() == 0 ) {
wp_update_user( array ('ID' => $user_id, 'user_pass' => esc_attr( $_POST['password_1'] ) ) ) ; wp_update_user( array ('ID' => $user_id, 'user_pass' => esc_attr( $_POST['password_1'] ) ) ) ;
do_action( 'woocommerce_customer_change_password', $user_id ); do_action( 'woocommerce_customer_change_password', $user_id );
@ -243,40 +243,40 @@ add_action( 'template_redirect', 'woocommerce_save_password' );
*/ */
function woocommerce_view_order() { function woocommerce_view_order() {
global $woocommerce; global $woocommerce;
$woocommerce->nocache(); $woocommerce->nocache();
if ( ! is_user_logged_in() ) return; if ( ! is_user_logged_in() ) return;
$user_id = get_current_user_id(); $user_id = get_current_user_id();
$order_id = ( isset( $_GET['order'] ) ) ? $_GET['order'] : 0; $order_id = ( isset( $_GET['order'] ) ) ? $_GET['order'] : 0;
$order = new WC_Order( $order_id ); $order = new WC_Order( $order_id );
if ( $order_id == 0 ) { if ( $order_id == 0 ) {
woocommerce_get_template('myaccount/my-orders.php', array( 'recent_orders' => 10 )); woocommerce_get_template('myaccount/my-orders.php', array( 'recent_orders' => 10 ));
return; return;
} }
if ( $order->user_id != $user_id ) { if ( $order->user_id != $user_id ) {
echo '<div class="woocommerce_error">' . __('Invalid order.', 'woocommerce') . ' <a href="'.get_permalink( woocommerce_get_page_id('myaccount') ).'">'. __('My Account &rarr;', 'woocommerce') .'</a>' . '</div>'; echo '<div class="woocommerce_error">' . __('Invalid order.', 'woocommerce') . ' <a href="'.get_permalink( woocommerce_get_page_id('myaccount') ).'">'. __('My Account &rarr;', 'woocommerce') .'</a>' . '</div>';
return; return;
} }
$status = get_term_by('slug', $order->status, 'shop_order_status'); $status = get_term_by('slug', $order->status, 'shop_order_status');
echo '<p>' echo '<p class="order-info">'
. sprintf( __('Order <mark>%s</mark> made on <mark>%s</mark>', 'woocommerce'), $order->get_order_number(), date_i18n(get_option('date_format'), strtotime($order->order_date)) ) . sprintf( __( 'Order <mark class="order-number">%s</mark> made on <mark class="order-date">%s</mark>', 'woocommerce'), $order->get_order_number(), date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ) )
. sprintf( __('. Order status: <mark>%s</mark>', 'woocommerce'), __($status->name, 'woocommerce') ) . '. ' . sprintf( __( 'Order status: <mark class="order-status">%s</mark>', 'woocommerce' ), __( $status->name, 'woocommerce' ) )
. '.</p>'; . '.</p>';
$notes = $order->get_customer_order_notes(); $notes = $order->get_customer_order_notes();
if ($notes) : if ($notes) :
?> ?>
<h2><?php _e('Order Updates', 'woocommerce'); ?></h2> <h2><?php _e('Order Updates', 'woocommerce'); ?></h2>
<ol class="commentlist notes"> <ol class="commentlist notes">
<?php foreach ($notes as $note) : ?> <?php foreach ($notes as $note) : ?>
<li class="comment note"> <li class="comment note">
<div class="comment_container"> <div class="comment_container">
<div class="comment-text"> <div class="comment-text">
<p class="meta"><?php echo date_i18n('l jS \of F Y, h:ia', strtotime($note->comment_date)); ?></p> <p class="meta"><?php echo date_i18n('l jS \of F Y, h:ia', strtotime($note->comment_date)); ?></p>
<div class="description"> <div class="description">
@ -284,13 +284,13 @@ function woocommerce_view_order() {
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ol> </ol>
<?php <?php
endif; endif;
do_action( 'woocommerce_view_order', $order_id ); do_action( 'woocommerce_view_order', $order_id );
} }