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; ?>
status, array('pending', 'failed'))) : ?>
countries->countries->countries[get_user_meta( get_current_user_id(), 'billing-country', true )])) $country = $woocommerce->countries->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->countries[get_user_meta( get_current_user_id(), 'shipping-country', true )])) $country = $woocommerce->countries->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)) );
echo sprintf( __('. Order status: %s ', 'woothemes'), $order->status );
echo '.
';
?>
get_customer_order_notes();
if ($notes) :
?>
get_subtotal_to_display(); ?>
order_shipping>0) : ?>
get_shipping_to_display(); ?>
get_total_tax()>0) : ?>
get_total_tax()); ?>
order_discount>0) : ?>
-order_discount); ?>
order_total); ?>
customer_note) : ?>
customer_note)); ?>
items)>0) :
foreach($order->items as $item) :
if (isset($item['variation_id']) && $item['variation_id'] > 0) :
$_product = &new woocommerce_product_variation( $item['variation_id'] );
else :
$_product = &new woocommerce_product( $item['id'] );
endif;
echo '
'.$item['name'];
if (isset($item['item_meta'])) :
echo woocommerce_get_formatted_variation( $item['item_meta'] );
endif;
echo '
'.$item['qty'].'
'.woocommerce_price( $item['cost']*$item['qty'], array('ex_tax_label' => 1) ).'
';
endforeach;
endif;
?>
billing_email) echo ''.__('Email:', 'woothemes').' '.$order->billing_email.' ';
if ($order->billing_phone) echo ''.__('Telephone:', 'woothemes').' '.$order->billing_phone.' ';
?>
formatted_shipping_address) _e('N/A', 'woothemes'); else echo $order->formatted_shipping_address;
?>
formatted_billing_address) _e('N/A', 'woothemes'); else echo $order->formatted_billing_address;
?>
comment_date)); ?>