1. Home
  2. Knowledge Base
  3. WooCommerce Product Table
  4. Advanced Usage

Code snippet: Change the Page Length dropdown options

Please note: this article is aimed at developers. We have provided an article on how to add code snippets. If you're not comfortable using them then you can use our plugin customization service.

WooCommerce Product Table has options to set the number of products per page and choose where the products per page control appears. By default, the Page Length dropdown includes 10, 25, 50, 100, the table's selected products-per-page value if different, and All.

If you want to change the choices in this dropdown, or remove the All option, then you can use the following code snippet.

Code snippet

Add this PHP code to your theme or child theme, or with a code snippets plugin:

add_filter( 'wc_product_table_data_config', 'barn2_wpt_change_page_length_options' );

function barn2_wpt_change_page_length_options( $config ) {
    $page_lengths = [ 10, 20, 30 ];

    $config['lengthMenu'] = [ $page_lengths, $page_lengths ];

    return $config;
}

This example changes the Page Length dropdown to 10, 20, and 30 products per page, and removes the All option.

Make sure the table's Products per page setting matches one of the values in the snippet, or add that value to the $page_lengths array.

Including the All option

If you want to keep the All option, use this version instead:

add_filter( 'wc_product_table_data_config', 'barn2_wpt_change_page_length_options' );

function barn2_wpt_change_page_length_options( $config ) {
    $config['lengthMenu'] = [
        [ 10, 20, 30, -1 ],
        [ 10, 20, 30, __( 'All', 'woocommerce-product-table' ) ],
    ];

    return $config;
}

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.