pagination does not work in orders WooCommerce
-
hello
i have been dealing with this problem for about 6 days, i did a lot of searching, but i didn’t get any results, i asked my question at the address below, but no one could give a detailed answer. i tried on several sites but it didn’t work, i even installed WordPress and WooCommerce from the beginning and used the default twentytwentytwo template, but it still didn’t work.https://stackoverflow.com/questions/73105735/pagination-does-not-work-in-orders-woocommerce
please guide me, thank you very much
-
Hi @socialreza
If I am understanding correctly, pagination is not working on your orders page (WooCommerce > Orders).
This is an unusual behavior, and it is likely that this is being caused by a conflict.
If you switch the Screen Orders > Pagination option to something like 20 per page, does this affect anything?
If it makes no difference, then I’d recommend performing a full conflict test to try and narrow down to the potential culprit. This will involve deactivating all plugins apart from WooCommerce and switching to a default WP theme like Twenty Twenty-One or Storefront. Here’s the conflict test guide for reference: https://docs.woocommerce.com/document/how-to-test-for-conflicts/
* If you don’t want to run the test on your live production site, you can create a duplicate/staging site. Many hosting providers offer site staging facilities, but if you don’t have such a feature, you can create one with the WP Staging plugin.
I hope this leads to a resolution.
i’m sorry, you did not understand correctly
if you refer to the link i sent, you will fully understand my problem
https://stackoverflow.com/questions/73105735/pagination-does-not-work-in-orders-woocommerce
now i will explain here too
i changed the pagination of WooCommerce orders as follows :
before : example.com/my-account/orders/2
after : example.com/my-account/orders/page/2i added pagination to WooCommerce orders
path : /plugins/woocommerce/templates/myaccount/orders.php
<?php /** * Orders * * Shows orders on the account page. * * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/orders.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce\Templates * @version 3.7.0 */ defined( 'ABSPATH' ) || exit; do_action( 'woocommerce_before_account_orders', $has_orders ); ?> <?php if ( $has_orders ) : ?> <table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table"> <thead> <tr> <?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?> <th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th> <?php endforeach; ?> </tr> </thead> <tbody> <?php foreach ( $customer_orders->orders as $customer_order ) { $order = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $item_count = $order->get_item_count() - $order->get_item_count_refunded(); ?> <tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?> order"> <?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>"> <?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?> <?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?> <?php elseif ( 'order-number' === $column_id ) : ?> <a href="<?php echo esc_url( $order->get_view_order_url() ); ?>"> <?php echo esc_html( $order->get_order_number() ); ?> </a> <?php elseif ( 'order-date' === $column_id ) : ?> <time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time> <?php elseif ( 'order-total' === $column_id ) : ?> <?php echo $order->get_formatted_order_total(); ?> <?php elseif ( 'order-status' === $column_id ) : ?> <?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?> <?php elseif ( 'order-actions' === $column_id ) : ?> <?php $actions = wc_get_account_orders_actions( $order ); if ( ! empty( $actions ) ) { foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited echo '<a href="' . esc_url( $action['url'] ) . '" class="woocommerce-button button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>'; } } ?> <?php endif; ?> </td> <?php endforeach; ?> </tr> <?php } ?> </tbody> </table> <?php do_action( 'woocommerce_before_account_orders_pagination' ); ?> <?php if ( 1 < $customer_orders->max_num_pages ) : ?> <nav class="woocommerce-pagination"> <?php $args = array( 'total' => $customer_orders->max_num_pages ); echo paginate_links( $args ); ?> </nav> <?php endif; ?> <?php else : ?> <p class="woocommerce_message"><?php esc_html_e( 'No order has been made yet.', 'woocommerce' ); ?></p> <?php endif; ?> <?php do_action( 'woocommerce_after_account_orders', $has_orders ); ?>
i also added the following code to functions :
function woocommerce_my_account_my_orders_query1() { $current_page = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; $customer_orders = array( 'customer' => get_current_user_id(), 'page' => $current_page, 'paginate' => true, ); return $customer_orders; } add_filter( 'woocommerce_my_account_my_orders_query', 'woocommerce_my_account_my_orders_query1', 10, 1 );
problem : after clicking on any of the page numbers, it will go to the correct address, that is:
example.com/my-account/orders/page/2
example.com/my-account/orders/page/3
example.com/my-account/orders/page/4but in all pages it brings the same results as the first page
if you would like to answer my question, thanks
Hi @socialreza
Thanks for clarifying.
I understand what is happening, but since this involves custom coding, I’m afraid, there isn’t much we can help with.
Kindly be informed that support for custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.
For help with custom code, we recommend the WooCommerce Developer Resources Portal.
You can also visit the WooCommerce Facebook group or the
#developers
channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.Lastly, for direct assistance with code customizations, we recommend consulting with the WooCommerce Customizations Partners. https://woocommerce.com/customizations/
Nevertheless, I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out here.
You should also be receiving updates from the StyackOverflow thread started.
Cheers
- The topic ‘pagination does not work in orders WooCommerce’ is closed to new replies.