0

I'm trying to write a shortcode to display users woocommerce order history. I've found an answer here in woocommerce, is there a shortcode/page to view all orders? , but that does'nt work anymore.

If i follow the current answer it gives me a fatal error.

Fatal error: Call to undefined function wc_get_account_orders_actions() in /wp-content/themes/wrapgate/woocommerce/myaccount/my-orders.php on line 72

Anybody knows updated code to get my shortcode to work? Here's the shortcode function i've tried

add_shortcode( 'woocommerce_history', 'woo_order_history' );

function woo_order_history() {
    ob_start();
    wc_get_template( 'myaccount/my-orders.php', array(
        'current_user'  => get_user_by( 'id', get_current_user_id() ),
        'order_count'   => -1
    ));
    return ob_get_clean();
}

Same error occurs if i try to use

woocommerce_account_orders( -1 );

Woocommerce as well as wordpress are on the latest version. I've tried to call the shortcode function from my themes functions.php

Thanks in advance for every help.

aerosoul
  • 1
  • 2

1 Answers1

1

my-orders.php is deprecated after version 2.6.0. Woocommerce my-account uses orders.php now. To create a shortcode to display order history

function woo_order_history( $atts ) {
extract( shortcode_atts( array(
    'order_count' => -1
), $atts ) );

ob_start();
$customer_orders = wc_get_orders( apply_filters( 'woocommerce_my_account_my_orders_query', array(
    'customer' => get_current_user_id(),
    'page'     => $current_page,
    'paginate' => true,
) ) );
wc_get_template(
    'myaccount/orders.php',
    array(
        'current_page'    => absint( $current_page ),
        'customer_orders' => $customer_orders,
        'has_orders'      => 0 < $customer_orders->total,
    )
);
return ob_get_clean();
}
add_shortcode('woocommerce_history', 'woo_order_history');

Add this code to your theme->functions.php or child-theme->functions.php (if you have child theme enabled). Now where you want to display the order just add the shortcode [woocommerce_history]

pankaj7621
  • 21
  • 1
  • 7