Skip to content

Instantly share code, notes, and snippets.

@manchumahara
Created December 30, 2019 12:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save manchumahara/388e64886fe34c280e909346c763bc03 to your computer and use it in GitHub Desktop.
Save manchumahara/388e64886fe34c280e909346c763bc03 to your computer and use it in GitHub Desktop.
display order status list in my orders in woocommerce https://codeboxr/.com
add_action( 'woocommerce_before_account_orders', 'woo_my_orders_display_status' );
function woo_my_orders_display_status( $has_orders = false ) {
//if($has_orders){
$post_status = isset( $_REQUEST['post_status'] ) ? sanitize_text_field( $_REQUEST['post_status'] ) : 'all';
$order_page_url = get_permalink( wc_get_page_id( 'orders' ) );
echo '<div class="clear clearfix"></div>';
echo '<ul style="list-style: none; padding: 0; margin: 20px 0;">';
$status_style_extra = ( $post_status == 'all' ) ? 'font-weight: bold;' : '';
$status_order_page_url = add_query_arg( 'post_status', 'all', $order_page_url );
echo '<li style="list-style: none; display: inline; margin-right: 5px; ' . $status_style_extra . '"><a href="' . esc_url( $status_order_page_url ) . '">All</a></li>';
//$order_statuses = get_terms( 'shop_order_status', array( 'hide_empty' => false ) );
/*$order_statuses = get_terms( array(
'taxonomy' => 'shop_order_status',
'hide_empty' => false,
) );*/
$order_statuses = wc_get_order_statuses();
foreach ( $order_statuses as $status_key => $status_name ) {
//$status->slug, $status->name
$status_style_extra = ( $post_status == $status_key ) ? 'font-weight: bold;' : '';
$status_order_page_url = add_query_arg( 'post_status', esc_attr( $status_key ), $order_page_url );
echo '<li style="list-style: none; display: inline; margin-right: 5px; ' . $status_style_extra . '"><a href="' . esc_url( $status_order_page_url ) . '">' . esc_attr( $status_name ) . '</a></li>';
}
echo '</ul>';
echo '<div class="clear clearfix"></div>';
//}
}
add_filter( 'woocommerce_my_account_my_orders_query', 'woo_my_orders_display_per_status' );
function woo_my_orders_display_per_status( $args = array() ) {
$post_status = isset( $_REQUEST['post_status'] ) ? sanitize_text_field( $_REQUEST['post_status'] ) : 'any';
$args['post_status'] = $post_status;
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment