简体   繁体   中英

Change the Number of Products that Display on WooCommerce 'xyz' category page

I have 19 items in the "xyz" category currently but I am only able to see 5 of them at a time and shows pagination I don't want pagination.

Is there a way to make it to where more than 5 items show up on your first page of your xyz category ?

i added following code to my function.php of template

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 10;' ), 19 );

but still its displaying 5 products .

as of php 7.2 create_function is depricated . following filter is available to change the amount of products in the archive pages (i would only suggest to use that one, if it is different from your wordpress setting under settings>reading)

/**
  * WC: change products per page
  * @return int
  */
function so22835795_loop_shop_per_page() {
    return -1; //return any number, -1 === show all
};
add_filter('loop_shop_per_page', 'so22835795_loop_shop_per_page', 10, 0);

This can be changed in the Reading Settings section of the Settings tab on the dashboard.

The option Blog pages show at most controls how many products can be seen. Changing that to 19 will allow all 19 products to be shown.

EDIT

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 19;' ), 20 );

ANOTHER EDIT:

In the woocommerce/includes/class-wc-query.php page there is the following on line ~365

$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ) );

Change it to:

$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', '19') );

add this code to our theme's function.php file

add_filter('loop_shop_per_page', create_function('$cols', 'return 19;'));

it is working for me. Thakns

The loop_shop_per_page filter did not work for me as the theme was overriding it. So I used the woocommerce_product_query filter as follows:

<?php
add_action( 'woocommerce_product_query', 'so22835795_woocommerce_products_per_page', 1, 50 );

function so22835795_woocommerce_products_per_page( $query ) {
    if ( $query->is_main_query() ) {
        $query->set( 'posts_per_page', '5' );
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM