By default Woocommerce orders table displays all available order status on the My Account page which is not sortable by customer, therefore I need to have a separate table for every unique order statue (example : ‘on-hold’ ) to display orders table based on only required statue.
I tried this code but it doesn’t output the table:
/* Shortcode To Display Only On-hold Orders On A Custom Page */
add_shortcode('account_on_hold', 'get_customer_orders_on_hold');
function get_customer_orders_on_hold() {
if( $user = wp_get_current_user() ){
// Get 'on-hold' customer ORDERS
$on_hold_orders = wc_get_orders( array(
'limit' => -1,
'customer_id' => $user->ID,
'status' => array('on-hold'),
) );
}
return $on_hold_orders ;
}
Related Topic : Get customer “on-hold” order status total amount in Woocommerce
Your advice would be appreciated!
2
Answers
You could use woocommerce table template to generate the html table. You only need to put a conditional check before generating it.
So you could set this up in multiple ways, for example it could be something like this:
Tested and works.
Ruvee’s way is good to customize.
Alternatively, if you want output just the same as "my-account/orders", there is also the method to call the template.
(Addition) The way to add custom menu on the myaccount.