Better account edit Closes #3168
This commit is contained in:
parent
0b9689f73a
commit
a3c2cef3f7
|
@ -16,3 +16,4 @@ global $wpdb, $woocommerce;
|
|||
wp_delete_post( get_option('woocommerce_pay_page_id'), true );
|
||||
wp_delete_post( get_option('woocommerce_thanks_page_id'), true );
|
||||
wp_delete_post( get_option('woocommerce_view_order_page_id'), true );
|
||||
wp_delete_post( get_option('woocommerce_change_password_page_id'), true );
|
|
@ -321,17 +321,6 @@ $woocommerce_settings['pages'] = apply_filters('woocommerce_page_settings', arra
|
|||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Change Password Page', 'woocommerce' ),
|
||||
'desc' => __( 'Page contents: [woocommerce_change_password] Parent: "My Account"', 'woocommerce' ),
|
||||
'id' => 'woocommerce_change_password_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'class' => 'chosen_select_nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Logout Page', 'woocommerce' ),
|
||||
'desc' => __( 'Parent: "My Account"', 'woocommerce' ),
|
||||
|
|
|
@ -233,12 +233,6 @@ function woocommerce_create_pages() {
|
|||
'content' => '[woocommerce_edit_address]',
|
||||
'parent' => 'myaccount'
|
||||
),
|
||||
'change_password' => array(
|
||||
'name' => _x( 'change-password', 'page_slug', 'woocommerce' ),
|
||||
'title' => __( 'Change Password', 'woocommerce' ),
|
||||
'content' => '[woocommerce_change_password]',
|
||||
'parent' => 'myaccount'
|
||||
),
|
||||
'logout' => array(
|
||||
'name' => _x( 'logout', 'page_slug', 'woocommerce' ),
|
||||
'title' => __( 'Logout', 'woocommerce' ),
|
||||
|
|
|
@ -316,10 +316,6 @@ function woocommerce_status_report() {
|
|||
'option' => 'woocommerce_edit_address_page_id',
|
||||
'shortcode' => '[woocommerce_edit_address]'
|
||||
),
|
||||
__( 'Change Password', 'woocommerce' ) => array(
|
||||
'option' => 'woocommerce_change_password_page_id',
|
||||
'shortcode' => '[woocommerce_change_password]'
|
||||
),
|
||||
__( 'Lost Password', 'woocommerce' ) => array(
|
||||
'option' => 'woocommerce_lost_password_page_id',
|
||||
'shortcode' => '[woocommerce_lost_password]'
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
a.addImmediate(c, ed.getLang('woocommerce.checkout'),"[woocommerce_checkout]" );
|
||||
a.addImmediate(c, ed.getLang('woocommerce.my_account'),"[woocommerce_my_account]" );
|
||||
a.addImmediate(c, ed.getLang('woocommerce.edit_address'),"[woocommerce_edit_address]" );
|
||||
a.addImmediate(c, ed.getLang('woocommerce.change_password'),"[woocommerce_change_password]" );
|
||||
a.addImmediate(c, ed.getLang('woocommerce.pay'),"[woocommerce_pay]" );
|
||||
a.addImmediate(c, ed.getLang('woocommerce.thankyou'),"[woocommerce_thankyou]" );
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
(function(){tinymce.create("tinymce.plugins.WooCommerceShortcodes",{init:function(e,t){},createControl:function(e,t){var n=tinymce.activeEditor;if(e=="woocommerce_shortcodes_button"){e=t.createMenuButton("woocommerce_shortcodes_button",{title:n.getLang("woocommerce.insert"),icons:!1});var r=this;e.onRenderMenu.add(function(e,t){r.addImmediate(t,n.getLang("woocommerce.order_tracking"),"[woocommerce_order_tracking]");r.addImmediate(t,n.getLang("woocommerce.price_button"),'[add_to_cart id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.product_by_sku"),'[product id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_sku"),'[products ids="" skus=""]');r.addImmediate(t,n.getLang("woocommerce.product_categories"),'[product_categories number=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_cat_slug"),'[product_category category="" per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.recent_products"),'[recent_products per_page="12" columns="4" orderby="date" order="desc"]');r.addImmediate(t,n.getLang("woocommerce.featured_products"),'[featured_products per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.shop_messages"),"[woocommerce_messages]");t.addSeparator();e=t.addMenu({title:n.getLang("woocommerce.pages")});r.addImmediate(e,n.getLang("woocommerce.cart"),"[woocommerce_cart]");r.addImmediate(e,n.getLang("woocommerce.checkout"),"[woocommerce_checkout]");r.addImmediate(e,n.getLang("woocommerce.my_account"),"[woocommerce_my_account]");r.addImmediate(e,n.getLang("woocommerce.edit_address"),"[woocommerce_edit_address]");r.addImmediate(e,n.getLang("woocommerce.change_password"),"[woocommerce_change_password]");r.addImmediate(e,n.getLang("woocommerce.pay"),"[woocommerce_pay]");r.addImmediate(e,n.getLang("woocommerce.thankyou"),"[woocommerce_thankyou]")});return e}return null},addImmediate:function(e,t,n){e.add({title:t,onclick:function(){tinyMCE.activeEditor.execCommand("mceInsertContent",!1,n)}})}});tinymce.PluginManager.add("WooCommerceShortcodes",tinymce.plugins.WooCommerceShortcodes)})();
|
||||
(function(){tinymce.create("tinymce.plugins.WooCommerceShortcodes",{init:function(e,t){},createControl:function(e,t){var n=tinymce.activeEditor;if(e=="woocommerce_shortcodes_button"){e=t.createMenuButton("woocommerce_shortcodes_button",{title:n.getLang("woocommerce.insert"),icons:!1});var r=this;e.onRenderMenu.add(function(e,t){r.addImmediate(t,n.getLang("woocommerce.order_tracking"),"[woocommerce_order_tracking]");r.addImmediate(t,n.getLang("woocommerce.price_button"),'[add_to_cart id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.product_by_sku"),'[product id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_sku"),'[products ids="" skus=""]');r.addImmediate(t,n.getLang("woocommerce.product_categories"),'[product_categories number=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_cat_slug"),'[product_category category="" per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.recent_products"),'[recent_products per_page="12" columns="4" orderby="date" order="desc"]');r.addImmediate(t,n.getLang("woocommerce.featured_products"),'[featured_products per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.shop_messages"),"[woocommerce_messages]");t.addSeparator();e=t.addMenu({title:n.getLang("woocommerce.pages")});r.addImmediate(e,n.getLang("woocommerce.cart"),"[woocommerce_cart]");r.addImmediate(e,n.getLang("woocommerce.checkout"),"[woocommerce_checkout]");r.addImmediate(e,n.getLang("woocommerce.my_account"),"[woocommerce_my_account]");r.addImmediate(e,n.getLang("woocommerce.edit_address"),"[woocommerce_edit_address]");r.addImmediate(e,n.getLang("woocommerce.pay"),"[woocommerce_pay]");r.addImmediate(e,n.getLang("woocommerce.thankyou"),"[woocommerce_thankyou]")});return e}return null},addImmediate:function(e,t,n){e.add({title:t,onclick:function(){tinyMCE.activeEditor.execCommand("mceInsertContent",!1,n)}})}});tinymce.PluginManager.add("WooCommerceShortcodes",tinymce.plugins.WooCommerceShortcodes)})();
|
|
@ -17,6 +17,5 @@ $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
|
|||
order_tracking: "' . esc_js( __( 'Order tracking', 'woocommerce' ) ) . '",
|
||||
my_account: "' . esc_js( __( 'My Account', 'woocommerce' ) ) . '",
|
||||
edit_address: "' . esc_js( __( 'Edit Address', 'woocommerce' ) ) . '",
|
||||
change_password: "' . esc_js( __( 'Change Password', 'woocommerce' ) ) . '",
|
||||
}
|
||||
}})';
|
|
@ -184,32 +184,10 @@ class WC_Checkout {
|
|||
}
|
||||
|
||||
// Store user data
|
||||
if ( $this->checkout_fields['billing'] ) {
|
||||
foreach ( $this->checkout_fields['billing'] as $key => $field ) {
|
||||
|
||||
if ( $this->checkout_fields['billing'] )
|
||||
foreach ( $this->checkout_fields['billing'] as $key => $field )
|
||||
update_post_meta( $order_id, '_' . $key, $this->posted[ $key ] );
|
||||
|
||||
// User
|
||||
if ( $this->customer_id && ! empty( $this->posted[ $key ] ) ) {
|
||||
update_user_meta( $this->customer_id, $key, $this->posted[ $key ] );
|
||||
|
||||
// Special fields
|
||||
switch ( $key ) {
|
||||
case "billing_email" :
|
||||
if ( ! email_exists( $this->posted[ $key ] ) )
|
||||
wp_update_user( array ( 'ID' => $this->customer_id, 'user_email' => $this->posted[ $key ] ) ) ;
|
||||
break;
|
||||
case "billing_first_name" :
|
||||
wp_update_user( array ( 'ID' => $this->customer_id, 'first_name' => $this->posted[ $key ] ) ) ;
|
||||
break;
|
||||
case "billing_last_name" :
|
||||
wp_update_user( array ( 'ID' => $this->customer_id, 'last_name' => $this->posted[ $key ] ) ) ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->checkout_fields['shipping'] && ( $woocommerce->cart->needs_shipping() || get_option('woocommerce_require_shipping_address') == 'yes' ) ) {
|
||||
foreach ( $this->checkout_fields['shipping'] as $key => $field ) {
|
||||
$postvalue = false;
|
||||
|
@ -579,6 +557,13 @@ class WC_Checkout {
|
|||
$this->customer_id = $new_customer;
|
||||
|
||||
woocommerce_set_customer_auth_cookie( $this->customer_id );
|
||||
|
||||
// Add customer info from other billing fields
|
||||
if ( $this->posted['billing_first_name'] )
|
||||
wp_update_user( array ( 'ID' => $this->customer_id, 'first_name' => $this->posted['billing_first_name'], 'display_name' => $this->posted['billing_first_name'] ) );
|
||||
|
||||
if ( $this->posted['billing_last_name'] )
|
||||
wp_update_user( array ( 'ID' => $this->customer_id, 'last_name' => $this->posted['billing_last_name'] ) ) ;
|
||||
}
|
||||
|
||||
// Abort if errors are present
|
||||
|
|
|
@ -51,8 +51,8 @@ class WC_Query {
|
|||
'order-received',
|
||||
|
||||
// My account actions
|
||||
'account-logout',
|
||||
'view-order'
|
||||
'view-order',
|
||||
'edit-account'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class WC_Query {
|
|||
global $wp;
|
||||
|
||||
foreach ( $this->query_vars as $var )
|
||||
if ( ! empty( $_GET[ $var ] ) )
|
||||
if ( isset( $_GET[ $var ] ) )
|
||||
$wp->query_vars[ $var ] = $_GET[ $var ];
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ class WC_Shortcodes {
|
|||
add_shortcode( 'woocommerce_order_tracking', array( $this, 'order_tracking' ) );
|
||||
add_shortcode( 'woocommerce_my_account', array( $this, 'my_account' ) );
|
||||
add_shortcode( 'woocommerce_edit_address', array( $this, 'edit_address' ) );
|
||||
add_shortcode( 'woocommerce_change_password', array( $this, 'change_password' ) );
|
||||
add_shortcode( 'woocommerce_lost_password', array( $this, 'lost_password' ) );
|
||||
}
|
||||
|
||||
|
@ -99,19 +98,6 @@ class WC_Shortcodes {
|
|||
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Edit_Address', 'output' ), $atts );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change password page shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public function change_password( $atts ) {
|
||||
global $woocommerce;
|
||||
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Change_Password', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Lost password page shortcode.
|
||||
*
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Change Password Shortcode
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Shortcodes
|
||||
* @package WooCommerce/Shortcodes/Change_Password
|
||||
* @version 2.0.0
|
||||
*/
|
||||
class WC_Shortcode_Change_Password {
|
||||
|
||||
/**
|
||||
* Get the shortcode content.
|
||||
*
|
||||
* @access public
|
||||
* @param array $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function get( $atts ) {
|
||||
global $woocommerce;
|
||||
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param array $atts
|
||||
* @return void
|
||||
*/
|
||||
public static function output( $atts ) {
|
||||
global $woocommerce;
|
||||
|
||||
if ( ! is_user_logged_in() ) return;
|
||||
|
||||
woocommerce_get_template( 'myaccount/form-change-password.php' );
|
||||
}
|
||||
}
|
|
@ -43,6 +43,10 @@ class WC_Shortcode_My_Account {
|
|||
|
||||
self::view_order( absint( $wp->query_vars['view-order'] ) );
|
||||
|
||||
} elseif ( isset( $wp->query_vars['edit-account'] ) ) {
|
||||
|
||||
self::edit_account();
|
||||
|
||||
} else {
|
||||
|
||||
self::my_account( $atts );
|
||||
|
@ -114,4 +118,11 @@ class WC_Shortcode_My_Account {
|
|||
|
||||
do_action( 'woocommerce_view_order', $order_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit account details page
|
||||
*/
|
||||
private function edit_account() {
|
||||
woocommerce_get_template( 'myaccount/form-edit-account.php', array( 'user' => get_user_by( 'id', get_current_user_id() ) ) );
|
||||
}
|
||||
}
|
|
@ -170,6 +170,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Feature - Added woocommerce-smallscreen.css to optimise default layout on handheld devices.
|
||||
* Feature - Bulk edit increase / decrease variation prices by fixed or percentage values
|
||||
* Feature - Admin action to link past orders of the same email address to a new user.
|
||||
* Feature - Account edit page for editing profile data such as email.
|
||||
* Tweak - Added filter to check the 'Create account' checkbox on checkout by default
|
||||
* Tweak - Update CPT parameters for 'product_variation' and 'shop_coupon' to be no longer public
|
||||
* Tweak - COD processing instead of on-hold
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Change password form
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $woocommerce;
|
||||
?>
|
||||
|
||||
<?php $woocommerce->show_messages(); ?>
|
||||
|
||||
<form action="<?php echo esc_url( get_permalink(woocommerce_get_page_id('change_password')) ); ?>" method="post">
|
||||
|
||||
<p class="form-row form-row-first">
|
||||
<label for="password_1"><?php _e( 'New password', 'woocommerce' ); ?> <span class="required">*</span></label>
|
||||
<input type="password" class="input-text" name="password_1" id="password_1" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label for="password_2"><?php _e( 'Re-enter new password', 'woocommerce' ); ?> <span class="required">*</span></label>
|
||||
<input type="password" class="input-text" name="password_2" id="password_2" />
|
||||
</p>
|
||||
<div class="clear"></div>
|
||||
|
||||
<p><input type="submit" class="button" name="change_password" value="<?php _e( 'Save', 'woocommerce' ); ?>" /></p>
|
||||
|
||||
<?php $woocommerce->nonce_field('change_password')?>
|
||||
<input type="hidden" name="action" value="change_password" />
|
||||
|
||||
</form>
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Edit account form
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $woocommerce;
|
||||
?>
|
||||
|
||||
<?php $woocommerce->show_messages(); ?>
|
||||
|
||||
<form action="" method="post">
|
||||
|
||||
<p class="form-row form-row-first">
|
||||
<label for="account_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
|
||||
<input type="text" class="input-text" name="account_first_name" id="account_first_name" value="<?php esc_attr_e( $user->first_name ); ?>" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label for="account_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
|
||||
<input type="text" class="input-text" name="account_last_name" id="account_last_name" value="<?php esc_attr_e( $user->last_name ); ?>" />
|
||||
</p>
|
||||
<p class="form-row form-row-wide">
|
||||
<label for="account_email"><?php _e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
|
||||
<input type="email" class="input-text" name="account_email" id="account_email" value="<?php esc_attr_e( $user->user_email ); ?>" />
|
||||
</p>
|
||||
<p class="form-row form-row-first">
|
||||
<label for="password_1"><?php _e( 'Password (leave blank to leave unchanged)', 'woocommerce' ); ?></label>
|
||||
<input type="password" class="input-text" name="password_1" id="password_1" />
|
||||
</p>
|
||||
<p class="form-row form-row-last">
|
||||
<label for="password_2"><?php _e( 'Confirm new password', 'woocommerce' ); ?></label>
|
||||
<input type="password" class="input-text" name="password_2" id="password_2" />
|
||||
</p>
|
||||
<div class="clear"></div>
|
||||
|
||||
<p><input type="submit" class="button" name="save_account_details" value="<?php _e( 'Save changes', 'woocommerce' ); ?>" /></p>
|
||||
|
||||
<?php $woocommerce->nonce_field('save_account_details')?>
|
||||
<input type="hidden" name="action" value="save_account_details" />
|
||||
</form>
|
|
@ -18,7 +18,7 @@ $woocommerce->show_messages(); ?>
|
|||
printf(
|
||||
__( 'Hello, <strong>%s</strong>. From your account dashboard you can view your recent orders, manage your shipping and billing addresses and <a href="%s">edit your password and account details</a>.', 'woocommerce' ),
|
||||
$current_user->display_name,
|
||||
get_permalink( woocommerce_get_page_id( 'change_password' ) )
|
||||
woocommerce_customer_edit_account_url()
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
|
|
@ -333,7 +333,7 @@ if ( ! function_exists( 'woocommerce_get_page_id' ) ) {
|
|||
/**
|
||||
* WooCommerce page IDs
|
||||
*
|
||||
* retrieve page ids - used for myaccount, edit_address, change_password, shop, cart, checkout, pay, view_order, terms
|
||||
* retrieve page ids - used for myaccount, edit_address, shop, cart, checkout, pay, view_order, terms
|
||||
*
|
||||
* returns -1 if no page is found
|
||||
*
|
||||
|
@ -348,6 +348,11 @@ if ( ! function_exists( 'woocommerce_get_page_id' ) ) {
|
|||
|
||||
$page = 'checkout';
|
||||
}
|
||||
if ( $page == 'change_password' ) {
|
||||
_deprecated_argument( __CLASS__ . '->' . __FUNCTION__, '2.1', 'The "change_password" page is no-longer used - an endpoint is added to the my-account instead. To get a valid link use the woocommerce_customer_edit_account_url() function instead.' );
|
||||
|
||||
$page = 'myaccount';
|
||||
}
|
||||
|
||||
$page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) );
|
||||
|
||||
|
@ -531,7 +536,7 @@ if ( ! function_exists( 'is_account_page' ) ) {
|
|||
* @return bool
|
||||
*/
|
||||
function is_account_page() {
|
||||
return is_page( woocommerce_get_page_id( 'myaccount' ) ) || is_page( woocommerce_get_page_id( 'edit_address' ) ) || is_page( woocommerce_get_page_id( 'change_password' ) ) || is_page( woocommerce_get_page_id( 'lost_password' ) ) || apply_filters( 'woocommerce_is_account_page', false ) ? true : false;
|
||||
return is_page( woocommerce_get_page_id( 'myaccount' ) ) || is_page( woocommerce_get_page_id( 'edit_address' ) ) || is_page( woocommerce_get_page_id( 'lost_password' ) ) || apply_filters( 'woocommerce_is_account_page', false ) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ function woocommerce_template_redirect() {
|
|||
}
|
||||
|
||||
// My account page redirects (logged out)
|
||||
elseif ( ! is_user_logged_in() && ( is_page( woocommerce_get_page_id( 'edit_address' ) ) || is_page( woocommerce_get_page_id( 'change_password' ) ) ) ) {
|
||||
elseif ( ! is_user_logged_in() && ( is_page( woocommerce_get_page_id( 'edit_address' ) ) ) ) {
|
||||
wp_redirect( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) );
|
||||
exit;
|
||||
}
|
||||
|
@ -118,7 +118,6 @@ function woocommerce_nav_menu_items( $items, $args ) {
|
|||
if ( ! is_user_logged_in() ) {
|
||||
|
||||
$hide_pages = array();
|
||||
$hide_pages[] = (int) woocommerce_get_page_id( 'change_password' );
|
||||
$hide_pages[] = (int) woocommerce_get_page_id( 'logout' );
|
||||
$hide_pages[] = (int) woocommerce_get_page_id( 'edit_address' );
|
||||
$hide_pages = apply_filters( 'woocommerce_logged_out_hidden_page_ids', $hide_pages );
|
||||
|
@ -831,6 +830,27 @@ function woocommerce_process_registration() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to the edit account details page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function woocommerce_customer_edit_account_url() {
|
||||
$edit_account_url = get_permalink( woocommerce_get_page_id( 'myaccount' ) );
|
||||
|
||||
if ( get_option( 'permalink_structure' ) )
|
||||
$edit_account_url = trailingslashit( $edit_account_url ) . 'edit-account/';
|
||||
else
|
||||
$edit_account_url = add_query_arg( 'edit-account', '', $edit_account_url );
|
||||
|
||||
return apply_filters( 'woocommerce_customer_edit_account_url', $edit_account_url );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Place a previous order again.
|
||||
|
@ -1553,40 +1573,58 @@ function woocommerce_price_filter($filtered_posts) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Save the password and redirect back to the my account page.
|
||||
* Save the password/account details and redirect back to the my account page.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function woocommerce_save_password() {
|
||||
function woocommerce_save_account_details() {
|
||||
global $woocommerce;
|
||||
|
||||
if ( 'POST' !== strtoupper( $_SERVER[ 'REQUEST_METHOD' ] ) )
|
||||
return;
|
||||
|
||||
if ( empty( $_POST[ 'action' ] ) || ( 'change_password' !== $_POST[ 'action' ] ) )
|
||||
if ( empty( $_POST[ 'action' ] ) || ( 'save_account_details' !== $_POST[ 'action' ] ) )
|
||||
return;
|
||||
|
||||
$woocommerce->verify_nonce( 'change_password' );
|
||||
$woocommerce->verify_nonce( 'save_account_details' );
|
||||
|
||||
$update = true;
|
||||
$errors = new WP_Error();
|
||||
$user = new stdClass();
|
||||
|
||||
$user->ID = (int) get_current_user_id();
|
||||
$current_user = get_user_by( 'id', $user->ID );
|
||||
|
||||
if ( $user->ID <= 0 )
|
||||
return;
|
||||
|
||||
$_POST = array_map( 'woocommerce_clean', $_POST );
|
||||
$account_first_name = ! empty( $_POST[ 'account_first_name' ] ) ? woocommerce_clean( $_POST[ 'account_first_name' ] ) : '';
|
||||
$account_last_name = ! empty( $_POST[ 'account_last_name' ] ) ? woocommerce_clean( $_POST[ 'account_last_name' ] ) : '';
|
||||
$account_email = ! empty( $_POST[ 'account_email' ] ) ? woocommerce_clean( $_POST[ 'account_email' ] ) : '';
|
||||
$pass1 = ! empty( $_POST[ 'password_1' ] ) ? woocommerce_clean( $_POST[ 'password_1' ] ) : '';
|
||||
$pass2 = ! empty( $_POST[ 'password_2' ] ) ? woocommerce_clean( $_POST[ 'password_2' ] ) : '';
|
||||
|
||||
$pass1 = ! empty( $_POST[ 'password_1' ] ) ? $_POST[ 'password_1' ] : '';
|
||||
$pass2 = ! empty( $_POST[ 'password_2' ] ) ? $_POST[ 'password_2' ] : '';
|
||||
$user->first_name = $account_first_name;
|
||||
$user->last_name = $account_last_name;
|
||||
$user->user_email = $account_email;
|
||||
$user->display_name = $user->first_name;
|
||||
|
||||
if ( $pass1 )
|
||||
$user->user_pass = $pass1;
|
||||
|
||||
if ( empty( $pass1 ) || empty( $pass2 ) )
|
||||
$woocommerce->add_error( __( 'Please enter your password.', 'woocommerce' ) );
|
||||
if ( empty( $account_first_name ) || empty( $account_last_name ) )
|
||||
$woocommerce->add_error( __( 'Please enter your name.', 'woocommerce' ) );
|
||||
|
||||
if ( $pass1 !== $pass2 )
|
||||
if ( empty( $account_email ) || ! is_email( $account_email ) )
|
||||
$woocommerce->add_error( __( 'Please provide a valid email address.', 'woocommerce' ) );
|
||||
|
||||
elseif ( email_exists( $account_email ) && $account_email !== $current_user->user_email )
|
||||
$woocommerce->add_error( __( 'This email address is already registered.', 'woocommerce' ) );
|
||||
|
||||
if ( ! empty( $pass1 ) && empty( $pass2 ) )
|
||||
$woocommerce->add_error( __( 'Please re-enter your password.', 'woocommerce' ) );
|
||||
|
||||
elseif ( ! empty( $pass1 ) && $pass1 !== $pass2 )
|
||||
$woocommerce->add_error( __( 'Passwords do not match.', 'woocommerce' ) );
|
||||
|
||||
// Allow plugins to return their own errors.
|
||||
|
@ -1600,16 +1638,16 @@ function woocommerce_save_password() {
|
|||
|
||||
wp_update_user( $user ) ;
|
||||
|
||||
$woocommerce->add_message( __( 'Password changed successfully.', 'woocommerce' ) );
|
||||
$woocommerce->add_message( __( 'Account details changed successfully.', 'woocommerce' ) );
|
||||
|
||||
do_action( 'woocommerce_customer_change_password', $user->ID );
|
||||
do_action( 'woocommerce_save_account_details', $user->ID );
|
||||
|
||||
wp_safe_redirect( get_permalink( woocommerce_get_page_id('myaccount') ) );
|
||||
wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'template_redirect', 'woocommerce_save_password' );
|
||||
add_action( 'template_redirect', 'woocommerce_save_account_details' );
|
||||
|
||||
/**
|
||||
* Save and and update a billing or shipping address if the
|
||||
|
|
|
@ -460,6 +460,7 @@ class Woocommerce {
|
|||
add_rewrite_endpoint( 'order-pay', EP_PAGES );
|
||||
add_rewrite_endpoint( 'order-received', EP_PAGES );
|
||||
add_rewrite_endpoint( 'view-order', EP_PAGES );
|
||||
add_rewrite_endpoint( 'edit-account', EP_PAGES );
|
||||
|
||||
// Load class instances
|
||||
$this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances
|
||||
|
|
Loading…
Reference in New Issue