Closed ned-bs closed 5 months ago
@ned-bs Can you pls clarify - its two tasks?
@voodoo911 I didn't understand what do you mean.
In this case; Go to woocommerce products page (Or post, which I don't need) and add 2 buttons with next and previous page links.
I guess, code should be something like this
<?php
/*
Plugin Name: Custom Admin Pagination for WooCommerce Products and Orders
Plugin URI: https://yourwebsite.com
Description: Adds custom next and previous page buttons to the WooCommerce Products and Orders admin pages, at both the top and bottom of the lists.
Version: 1.0
Author: Your Name
Author URI: https://yourwebsite.com
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
// Only execute in admin dashboard
if (is_admin()) {
add_action('admin_footer', 'custom_pagination_buttons');
}
function custom_pagination_buttons() {
global $pagenow;
// Ensure the script only runs on the WooCommerce product or order admin pages
if ('edit.php' !== $pagenow || !in_array($_GET['post_type'], ['product', 'shop_order'])) {
return;
}
// Determine the current page
$page = isset($_GET['paged']) ? absint($_GET['paged']) : 1;
// Generate the URLs for previous and next pages
$prev_link = add_query_arg('paged', max(1, $page - 1));
$next_link = add_query_arg('paged', $page + 1);
// JavaScript to inject pagination buttons
echo "<script type='text/javascript'>
jQuery(document).ready(function($) {
var paginationHTML = '<div style=\"padding: 10px 0; display: inline-block;\">";
// Add 'Previous' button if not on the first page
if ($page > 1) {
paginationHTML += " <a href=\"" + '" . esc_url($prev_link) . "' + "\" class=\"button custom-pagination\">Previous Page</a>";
}
// Add 'Next' button
paginationHTML += " <a href=\"" + '" . esc_url($next_link) . "' + "\" class=\"button custom-pagination\">Next Page</a>";
paginationHTML += "</div>';
// Prepend to top and append to bottom of the product or order list
$('.tablenav.top').first().prepend(paginationHTML);
$('.tablenav.bottom').last().append(paginationHTML);
});
</script>";
}
@voodoo911 -
When scalability pro remove admin SQL CALC ROWS is enabled, pagination on wp-admin > products or wp-admin orders etc is broken.
When that option is enabled, simply add a NEXT PAGE and PREVIOUS page button where the pagination used to be.
@dhilditch Wrote you request about issue with pagination set
Hi, any plan?
@ned-bs Fix already applied
I am on SPRO 5.53 and woocommerce 8.9.0, I don't see anything like next page or previous page on products page.
@dhilditch seems fix not merged yet?
Fixed in 5.55
Suggest to add it to media page too. /wp-admin/upload.php page
Remove SQL_CALC_ROWS remove pagination on admin page
"When WP_Query fetches posts/products, it also calculates the total number of matching items. This is useful to display at the top of your shop/page/edit.php, e.g. Showing 1 - 50 of 650,000. However, this count requires either an index scan or table scan. Removing it, can result in ultra-fast WP_Query speed. Depending on your setup, you may need to switch to the natural sort order above too for successful use of the indexes. Since most users only need to view page 1, this is a recommended option but you should be aware that page counts will be incorrect as a result. Because of this, most people combine this option with an infinite scroll plugin."
Also on edit.php, SQL_CALC_ROWS is used. If you remove it, you remove pagination on these pages, but searching is unaffected and your pages will load far faster.
Describe the solution you'd like It make admin panel fast but also remove functionality. What if add next page and previous page links on top of wp-admin products page. /wp-admin/edit.php?post_type=product It can help to move next page, even there is no next page it is harmless