I'm using the plugin woocommerce for my wordpress site, and need a section where member can see their order history. Are there any shortcodes or page in woocommerce that shows the order history of a member?
Asked
Active
Viewed 3.8k times
2 Answers
22
My Account shortcode:
[woocommerce_my_account order_count="-1"]
Shows the ‘my account’ section where the customer can view past orders and update their information. You can specify the number or order to show, it’s set by default to 15 (use -1 to display all orders.)
Reference: Woocommerce Shortcodes
Update
If you need only the orders I don't know if there's already a shortcode, but I made one taking woocommerce_my_account as example:
function shortcode_my_orders( $atts ) {
extract( shortcode_atts( array(
'order_count' => -1
), $atts ) );
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'order_count' => $order_count
) );
return ob_get_clean();
}
add_shortcode('my_orders', 'shortcode_my_orders');
Add this to your functions.php file and then use it like [my_orders order_counts=10]
(order_counts
is optional, if missing it lists all the orders).

d79
- 3,699
- 1
- 22
- 36
-
actually it just sent me to the my accounts page where user can see their shipping addresses and the welcome message when in your my account page. – dave May 01 '15 at 02:00
-
ok i tried to place that above code in ROOT/wp-includes/functions.php but it gave me " Fatal error: Call to undefined function add_shortcode() in C:\xampp\htdocs\localpressjuicery\wp-includes\functions.php " – dave May 01 '15 at 03:12
-
No it's the functions.php file in your theme folder – d79 May 01 '15 at 03:18
-
well its showing nothing because i currently have no orders so let me setup some fake account/credit card and get back to you. thanks thus far. – dave May 01 '15 at 03:33
-
how do I filter orders by specific coupon codes only ? – govindak Oct 27 '15 at 04:28
-
@d79 Hi, the `myaccount/my-orders.php` template is deprecated as of 2.6.0, yet the shortcode still works. Please update your answer to inform users of that. A workaround would be having the template file overridden in `yourtheme/woocommerce/myaccount/my-orders.php` just in case if WC decides to remove the template. Another update to the solution would be using the newer template at `myaccount/orders.php`. :) – XTard Jan 18 '23 at 04:34
2
I was reading about extract and apparently its not recommended by Wordpress anymore. I found this soloution, hope this helps:
function shortcode_my_orders( $atts ) {
$args= shortcode_atts(
array(
'order_count' => -1
),
$atts
);
$order_count = esc_attr( $args['order_count'] );
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'order_count' => $order_count
) );
return ob_get_clean();
}

A.Sh
- 21
- 1