Product archives only bring back 4 items, functions.php has been modified too

Posted in: Newspaper
Post count: 9

Hello,

I have a website that the products only show 4 results per product archives. I’ve tried modifying the functions.php file to bring more products in a loop, but it does nothing.

https://mobilevrxxx.com/shop/

// Number of product per page 8
add_filter(‘loop_shop_per_page’, create_function(‘$cols’, ‘return 12;’));

if (!function_exists(‘woocommerce_output_related_products’)) {
// Number of related products
function woocommerce_output_related_products() {
woocommerce_related_products(array(
‘posts_per_page’ => 12,
‘columns’ => 4,
‘orderby’ => ‘rand’,
)); // Display 4 products in rows of 1
}
}

Thanks

Post count: 9

A little help please …

Post count: 59

Did you figure it out? I would really like to have this info.

Post count: 9

Nope, and my shop is still jammed up. There hasn’t been any answer to my problem, it’s the holiday season so i understand, however it’s the holiday season and I feel I’m losing potential sales too … grrr

Post count: 9544

As much as I hate plugins for stuff like this ….

you might temporarily try this to avoid “losing sales”…

https://wordpress.org/plugins/woocommerce-products-per-page/

but yes, this *should* work if you put it at bottom of your main (not child) theme functions.php file:


// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );

Your version of code looks a little different than the official filter above, however.
REF:
https://docs.woothemes.com/document/change-number-of-products-displayed-per-page/

  • This reply was modified 10 years by simchris.
Post count: 9

The code i posted above is the theme’s default functions.php code. On Themeforest I made a comment for help there too, and i was directed to post here for help. I still await to hear on Themeforest for a solution.

I did try your override code that you referenced, and it still didn’t work.

I agree, i don’t like using plugins for small hackable tasks as well.

EDIT: That plugin you suggested works fine, thank you.

  • This reply was modified 10 years by fliporium.
Post count: 7909

Hi,


@fliporium

I have checked your shop page and you display 12 products there like you changed in the code.
Please clear all the caches and provide more details if you still have this issue or other issues related to the theme.

Thanks!

Post count: 200

This solution works only for desktop: https://wordpress.org/plugins/woocommerce-products-per-page/

How about changing the number of products per page on mobile?

Post count: 200

For example: On desktop I had 4 products per row (I think that’s by default) and was able to successfully change it to 3 products per row using the suggested code in functions.php. I changed the total number of products per page to 15 (3×5).

But on mobile, there are 2 products per row by default. After changing the total number of products per page, on mobile there’s 1 product on the last row of each page. This doesn’t look nice.

Any ideas how to change the total number of products per page on mobile or how to switch from 2 products per row to 1 product/row on mobile? Both are possible solutions.

Thanks!

Post count: 23312

Hello DaveS,

At the moment, if you will check our demo preview with Woocommerce template, on mobile will be displayed two images on the row, which looks great, as you can see here -> https://www.screencast.com/t/PeKK67UjCO7j Notice that template was custom made. Provide your website URL so I can take a closer look at it on the mobile version.

Thanks.

Post count: 200

Hi Catalin,

I’m using a child theme with custom functions.php where the following was added in order to show 3 products per row + sidebar on desktop instead of the default 4:

function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 15;
return $cols;
}

// Change number or products per row to 3
add_filter(‘loop_shop_columns’, ‘loop_columns’);
if (!function_exists(‘loop_columns’)) {
function loop_columns() {
return 3; // 3 products per row
}
}

The thing is – the number of products per page on mobile also changed to 15 and so the last row on every category page contains only one product.

Post count: 20688

Hi,

You could simply enlarge the single product with some CSS, to make it occupy the full row on mobile
https://www.screencast.com/t/jvzgjPYqO
This is the code used, give it a try

.woocommerce .columns-3 ul.products[class*=columns-] li.product, .woocommerce-page ul.products[class*=columns-] li.product {
width: 100%;
}

Thanks

Post count: 200

Works perfectly! Thanks a lot Simion!

Post count: 200

After doing some tests, it turns out that the last suggested code:
.woocommerce .columns-3 ul.products[class*=columns-] li.product, .woocommerce-page ul.products[class*=columns-] li.product {
width: 100%;
}
changes the design of the desktop version too. It shows 1 product per row on both mobile and desktop.

It should keep showing 3 products per row on desktop, which was achieved using this code:
// Change number or products per row to 3
add_filter(‘loop_shop_columns’, ‘loop_columns’);
if (!function_exists(‘loop_columns’)) {
function loop_columns() {
return 3; // 3 products per row
}
}

Changing the total number of products per page for mobile would also be a solution. This way we can keep showing 2 products per row, just need to define somehow a total number of lets say 16 products so that there no single product left at the end of each page. Any ideas how to achieve?

Post count: 20688

Enter the code in the phones field only – https://www.screencast.com/t/XqTEiIRKORa

It will make the products display one per row. The code is meant for the phones viewport, on desktop the products look fine as they are.

Post count: 200

Thanks Simion! It actually works this way. The thing is – always when opening a woocommerce category page or going to the next page, it flashes initially the default 2 products/row, and then shows only one, bigger product image, according to the new css added for phones. It’s not quite the optimal solution for the case. Is there a way to change the number of products per page for phones?

Having in mind that I already have this in functions.php:

function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 15;
return $cols;
}

// Change number or products per row to 3
add_filter(‘loop_shop_columns’, ‘loop_columns’);
if (!function_exists(‘loop_columns’)) {
function loop_columns() {
return 3; // 3 products per row
}
}

Post count: 20688

I see the code you use, but I don’t know of an easy way to detect device used and make cases to display products accordingly.
You could search online for some ways to detect when a mobile is used and in that case display one product per row.
Maybe try with this and make some tests
https://codex.wordpress.org/Function_Reference/wp_is_mobile

Post count: 200

Lets say I don’t want to show that 1 product per row on mobile, but keep the default 2. Is there an easy way to edit the total number of products per page for mobile so that there’s no single product on the last row of each page?
Thanks!

Post count: 20688

That would require to detect mobile as well. Both solutions require that mobile is detected.

I made a quick test with the WordPress function mentioned above
https://www.screencast.com/t/jO9ZU21QO
So if is mobile show a number of products, if is not mobile show a different number, seems to work in my tests.
I get 9 products on desktop – https://www.screencast.com/t/iecjqw9FR
And 1 on mobile, as I set it – https://www.screencast.com/t/amrPLBemg

Post count: 200

Hi Simion,

sorry for the late update. It works perfectly after adding the above code to functions.php! Thanks for your support, much appreciated!

Viewing 20 posts - 1 through 20 (of 20 total)
The forum ‘Newspaper’ is closed to new topics and replies.