• Resolved Moobs

    (@nickyb713)


    I’m in the process of creating a new WooCommerce store and I would like to add pagination to the orders section of the customer area. I have been unable to find a guide that explains how to do this with the latest version of WC.

    (My Account > View Orders > Recent Orders)

    I believe that I need to implement woo_pagination() into woocommerce/templates/myaccount/my-orders.php, but I’m not yet sure of the best way to do so.

    https://docs.woothemes.com/document/woo_pagination/

    I did change [woocommerce_my_account] tag to [woocommerce_my_account order_count=”all”] to display all orders instead of only the last 15, which is the default setting.

    If anyone can help or point me in the right direction it would be greatly appreciated.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Moobs

    (@nickyb713)

    Any ideas? You would think by this version of WC something like this would have been implemented already by default.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Recent orders does not paginate results. I’ll pitch the idea. Logged on https://github.com/woothemes/woocommerce/issues/10387

    Thread Starter Moobs

    (@nickyb713)

    Thanks

    If you want to display all orders and want to add pagination then do the following.
    Replace below code above loop

    $customer_orders1 = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
        'numberposts' => -1,
        'meta_key' => '_customer_user',
        'meta_value' => get_current_user_id(),
        'post_type' => wc_get_order_types('view-orders'),
        'post_status' => array_keys(wc_get_order_statuses())
            )));
    $total_records = count($customer_orders1);
    $posts_per_page = 20;
    $total_pages = ceil($total_records / $posts_per_page);
    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    $customer_orders = get_posts(array(
        'meta_key' => '_customer_user',
        'meta_value' => get_current_user_id(),
        'post_type' => wc_get_order_types('view-orders'),
        'posts_per_page' => $posts_per_page,
        'paged' => $paged,
        'post_status' => array_keys(wc_get_order_statuses())
        ));

    and after loop completed add pagination

    <div class="pagination">
                <?php
                $args = array(
                    'base' => '%_%',
                    'format' => '?page=%#%',
                    'total' => $total_pages,
                    'current' => $paged,
                    'show_all' => False,
                    'end_size' => 5,
                    'mid_size' => 5,
                    'prev_next' => True,
                    'prev_text' => __('? Previous'),
                    'next_text' => __('Next ?'),
                    'type' => 'plain',
                    'add_args' => False,
                    'add_fragment' => ''
                );
                echo paginate_links($args);
                ?>
            </div>

    hello the code above works well but the previous button cannot show a correct link , can you help fix it ?

    thank you

    b0n4r, I had the same problem with the previous and first page link not working correctly.

    Fixed by changing the pagination type to array, manipulated the array based on page num, then echo the output manually.

    So my change was:

    <div class="pagination">
    	<?php
    		$args = array(
    		    'base' => '%_%',
    		    'format' => '?page=%#%',
    		    'total' => $total_pages,
    		    'current' => $paged,
    		    'show_all' => True,
    		    'end_size' => 1,
    		    'mid_size' => 5,
    		    'prev_next' => True,
    		    'prev_text' => __('? Previous'),
    		    'next_text' => __('Next ?'),
    		    'type' => 'array',
    		    'add_args' => False,
    		    'add_fragment' => ''
    		);
    
    		$olinks = paginate_links($args);
    
    		if($paged>1){
    			$olinks[1] = "<a class='page-numbers' href='" . get_permalink( get_option('woocommerce_myaccount_page_id') ) . "'>1</a>";
    		}
    
    		if($paged==2){
    			$olinks[0] = "<a class='prev page-numbers' href='" . get_permalink( get_option('woocommerce_myaccount_page_id') ) . "''>Previous</a>";
    		}
    
    		foreach( $olinks as $olink){
    			echo $olink . " ";
    		}
    	?>
    </div>

    @khushbupadalia @herchen thank you , code is working fine.

    @deeps22 you most welcome.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WooCommerce – Order History Pagination’ is closed to new replies.