shortcode_wrapper('woocommerce_my_account', $atts);
}
function woocommerce_my_account( $atts ) {
global $woocommerce;
extract(shortcode_atts(array(
'recent_orders' => 5
), $atts));
$recent_orders = ('all' == $recent_orders) ? -1 : $recent_orders;
global $post, $current_user;
get_currentuserinfo();
$woocommerce->show_messages();
if (is_user_logged_in()) :
?>
%s. From your account dashboard you can view your recent orders, manage your shipping and billing addresses and change your password .', 'woothemes'), $current_user->display_name, get_permalink(get_option('woocommerce_change_password_page_id'))); ?>
customer->get_downloadable_products()) : ?>
get_customer_orders( get_current_user_id(), $recent_orders );
if ($woocommerce_orders->orders) foreach ($woocommerce_orders->orders as $order) :
?>
id; ?>
order_date)); ?>
formatted_shipping_address) echo $order->formatted_shipping_address; else echo '–'; ?>
order_total); ?>
status, 'shop_order_status');
echo $status->name;
?>
status, array('pending', 'failed'))) : ?>
countries->countries[get_user_meta( get_current_user_id(), 'billing_country', true )])) $country = $woocommerce->countries->countries[get_user_meta( get_current_user_id(), 'billing_country', true )]; else $country = '';
$address = array(
get_user_meta( get_current_user_id(), 'billing_first_name', true ) . ' ' . get_user_meta( get_current_user_id(), 'billing_last_name', true )
,get_user_meta( get_current_user_id(), 'billing_company', true )
,get_user_meta( get_current_user_id(), 'billing_address', true )
,get_user_meta( get_current_user_id(), 'billing_address-2', true )
,get_user_meta( get_current_user_id(), 'billing_city', true )
,get_user_meta( get_current_user_id(), 'billing_state', true )
,get_user_meta( get_current_user_id(), 'billing_postcode', true )
,$country
);
$address = array_map('trim', $address);
$formatted_address = array();
foreach ($address as $part) if (!empty($part)) $formatted_address[] = $part;
$formatted_address = implode(', ', $formatted_address);
if (!$formatted_address) _e('You have not set up a billing address yet.', 'woothemes'); else echo $formatted_address;
?>
countries->countries[get_user_meta( get_current_user_id(), 'shipping_country', true )])) $country = $woocommerce->countries->countries[get_user_meta( get_current_user_id(), 'shipping_country', true )]; else $country = '';
$address = array(
get_user_meta( get_current_user_id(), 'shipping_first_name', true ) . ' ' . get_user_meta( get_current_user_id(), 'shipping_last_name', true )
,get_user_meta( get_current_user_id(), 'shipping_company', true )
,get_user_meta( get_current_user_id(), 'shipping_address', true )
,get_user_meta( get_current_user_id(), 'shipping_address-2', true )
,get_user_meta( get_current_user_id(), 'shipping_city', true )
,get_user_meta( get_current_user_id(), 'shipping_state', true )
,get_user_meta( get_current_user_id(), 'shipping_postcode', true )
,$country
);
$address = array_map('trim', $address);
$formatted_address = array();
foreach ($address as $part) if (!empty($part)) $formatted_address[] = $part;
$formatted_address = implode(', ', $formatted_address);
if (!$formatted_address) _e('You have not set up a shipping address yet.', 'woothemes'); else echo $formatted_address;
?>
shortcode_wrapper('woocommerce_edit_address');
}
function woocommerce_edit_address() {
global $woocommerce;
$validation = &new woocommerce_validation();
$user_id = get_current_user_id();
if (is_user_logged_in()) :
if (isset($_GET['address'])) $load_address = $_GET['address']; else $load_address = 'billing';
if ($load_address == 'billing') $load_address = 'billing'; else $load_address = 'shipping';
if ($_POST) :
/* Validate */
$_POST = array_map('woocommerce_clean', $_POST);
// Required Fields
if (empty($_POST['address_first_name'])) : $woocommerce->add_error( __('First name is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_last_name'])) : $woocommerce->add_error( __('Last name is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_address'])) : $woocommerce->add_error( __('Address is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_city'])) : $woocommerce->add_error( __('City is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_postcode'])) : $woocommerce->add_error( __('Postcode is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_country'])) : $woocommerce->add_error( __('Country is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_state'])) : $woocommerce->add_error( __('State is a required field.', 'woothemes') ); endif;
// Billing only
if ($load_address == 'billing') :
if (empty($_POST['address_email'])) : $woocommerce->add_error( __('Email is a required field.', 'woothemes') ); endif;
if (empty($_POST['address_phone'])) : $woocommerce->add_error( __('Phone number is a required field.', 'woothemes') ); endif;
// Email
if (!$validation->is_email( $_POST['address_email'] )) : $woocommerce->add_error( __('Please enter a valid email address.', 'woothemes') ); endif;
// Phone
if (!$validation->is_phone( $_POST['address_phone'] )) : $woocommerce->add_error( __('Please enter a valid phone number.', 'woothemes') ); endif;
endif;
// Postcode
if (!$validation->is_postcode( $_POST['address_postcode'], $_POST['address_country'] )) : $woocommerce->add_error( __('Please enter a valid postcode/ZIP.', 'woothemes') );
else :
$_POST['address_postcode'] = $validation->format_postcode( $_POST['address_postcode'], $_POST['address_country'] );
endif;
/* Save */
if ($user_id>0 && $woocommerce->verify_nonce('edit_address') && $woocommerce->error_count() == 0 ) :
update_user_meta( $user_id, $load_address . '_first_name', $_POST['address_first_name'] );
update_user_meta( $user_id, $load_address . '_last_name', $_POST['address_last_name'] );
update_user_meta( $user_id, $load_address . '_company', $_POST['address_company'] );
update_user_meta( $user_id, $load_address . '_address', $_POST['address_address'] );
update_user_meta( $user_id, $load_address . '_address2', $_POST['address_address2'] );
update_user_meta( $user_id, $load_address . '_city', $_POST['address_city'] );
update_user_meta( $user_id, $load_address . '_postcode', $_POST['address_postcode'] );
update_user_meta( $user_id, $load_address . '_country', $_POST['address_country'] );
update_user_meta( $user_id, $load_address . '_state', $_POST['address_state'] );
if ($load_address == 'billing') :
update_user_meta( $user_id, $load_address . '_email', $_POST['address_email'] );
update_user_meta( $user_id, $load_address . '_phone', $_POST['address_phone'] );
update_user_meta( $user_id, $load_address . '_fax', $_POST['address_fax'] );
endif;
wp_safe_redirect( get_permalink(get_option('woocommerce_myaccount_page_id')) );
exit;
else :
$address = array(
'first_name' => $_POST['address_first_name'],
'last_name' => $_POST['address_last_name'],
'company' => $_POST['address_company'],
'email' => $_POST['address_email'],
'phone' => $_POST['address_phone'],
'fax' => $_POST['address_fax'],
'address' => $_POST['address_address'],
'address2' => $_POST['address_address2'],
'city' => $_POST['address_city'],
'state' => $_POST['address_state'],
'postcode' => $_POST['address_postcode'],
'country' => $_POST['address_country']
);
endif;
else :
$address = array(
'first_name' => get_user_meta( get_current_user_id(), $load_address . '_first_name', true ),
'last_name' => get_user_meta( get_current_user_id(), $load_address . '_last_name', true ),
'company' => get_user_meta( get_current_user_id(), $load_address . '_company', true ),
'email' => get_user_meta( get_current_user_id(), $load_address . '_email', true ),
'phone' => get_user_meta( get_current_user_id(), $load_address . '_phone', true ),
'fax' => get_user_meta( get_current_user_id(), $load_address . '_fax', true ),
'address' => get_user_meta( get_current_user_id(), $load_address . '_address', true ),
'address2' => get_user_meta( get_current_user_id(), $load_address . '_address2', true ),
'city' => get_user_meta( get_current_user_id(), $load_address . '_city', true ),
'state' => get_user_meta( get_current_user_id(), $load_address . '_state', true ),
'postcode' => get_user_meta( get_current_user_id(), $load_address . '_postcode', true ),
'country' => get_user_meta( get_current_user_id(), $load_address . '_country', true )
);
endif;
$woocommerce->show_messages();
?>
shortcode_wrapper('woocommerce_change_password');
}
function woocommerce_change_password() {
global $woocommerce;
$user_id = get_current_user_id();
if (is_user_logged_in()) :
if ($_POST) :
if ($user_id>0 && $woocommerce->verify_nonce('change_password')) :
if ( $_POST['password-1'] && $_POST['password-2'] ) :
if ( $_POST['password-1']==$_POST['password-2'] ) :
wp_update_user( array ('ID' => $user_id, 'user_pass' => $_POST['password-1']) ) ;
wp_safe_redirect( get_permalink(get_option('woocommerce_myaccount_page_id')) );
exit;
else :
$woocommerce->add_error( __('Passwords do not match.', 'woothemes') );
endif;
else :
$woocommerce->add_error( __('Please enter your password.', 'woothemes') );
endif;
endif;
endif;
$woocommerce->show_messages();
?>
shortcode_wrapper('woocommerce_view_order');
}
function woocommerce_view_order() {
global $woocommerce;
$user_id = get_current_user_id();
if (is_user_logged_in()) :
if (isset($_GET['order'])) $order_id = (int) $_GET['order']; else $order_id = 0;
$order = &new woocommerce_order( $order_id );
if ( $order_id>0 && $order->user_id == get_current_user_id() ) :
echo '' . sprintf( __('Order #%s made on %s ', 'woothemes'), $order->id, date(get_option('date_format'), strtotime($order->order_date)) );
$status = get_term_by('slug', $order->status, 'shop_order_status');
echo sprintf( __('. Order status: %s ', 'woothemes'), $status->name );
echo '.
';
$notes = $order->get_customer_order_notes();
if ($notes) :
?>
comment_date)); ?>