Site logo

Archived topic

change products per page on specific pages woocommerce

3 replies · Started by johnaps on December 11, 2020

Viewing posts 1–4 of 4

Hello!

I have found the bellow two codes but i cant get them to work...
I want to change the number of displayed products in specifically 5 product categories (change the number from 12 to 30)
Only on those 5 though and not in any other!

add_filter( 'option_generate_woocommerce_settings', 'tu_custom_wc_columns' );
function tu_custom_wc_columns( $options ) {
    if ( ! is_product_category( 'audio' ) ) {
        $options['columns'] = 2;
    }

    return $options;
}

From Tom (past thread)

/**
 * Change number of products that are displayed per page (shop page)
 */
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );

function new_loop_shop_per_page( $products ) {
  // Return the number of products you wanna show per page.
  $products = 100;
  return $products;
}

From wordpress.stack-exchange

I made those 2 like this

add_filter( 'option_generate_woocommerce_settings', 'tu_custom_wc_columns' );
function tu_custom_wc_columns( $products ) {
    if ( ! is_product_category( 'νοσοκομειακα-κρεβατια' ) ) {
        $products = 30;
    }

    return $products;
}

And i did some other combinations with no luck... This one breaks the styling, and the other one i tried changed it globally to 30 and not just to the one i tested it...

Do you have any insights on this?
Thank you for your time!

Hi there,

That is handled by WooCommerce itself so GP's filter wouldn't work.

The GP's filter you've shown above only changes the number of columns and not number of products.

I believe this is what you are after:
https://docs.woocommerce.com/document/change-number-of-products-displayed-per-page/

You would just need to add the appropriate conditional tags.

If that doesn't help, any chance you can check with WooCommerce support team first?

Thanks!

I also tried them, but they werent much of help because i am not a premium user...
If Tom or someone can tell me if this is even possible i would very much appreciate it!

Thank you for your time, though!

This archived topic is closed to new replies.