Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in woocommerce, is there a shortcode/page to view all orders?

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?

like image 380
dave Avatar asked May 01 '15 01:05

dave


People also ask

How do I show all products in a WooCommerce shortcode?

These two shortcodes will display your product categories on any page. [product_category] – Will display products in a specified product category. [product_categories] – Will display all your product categories.

How do I use WooCommerce shortcodes?

Go to your admin dashboard and click on Plugin > Add New on the right side. Then search for WooCommerce shortcodes, and then you just have to install and activate it. When you install a shortcode plugin for WooCommerce, you will find a new shortcode button in your page editor and post editor.


2 Answers

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).

like image 198
d79 Avatar answered Sep 25 '22 06:09

d79


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();

}

like image 23
A.Sh Avatar answered Sep 26 '22 06:09

A.Sh