Products Per Page - Something Overriding?

sage8
woocommerce

#1

I just setup Sage 8 and started building out a simple eCommerce site for myself and ran into an issue. I’m trying to make use of this plugin here:

For whatever reason though, no matter what I do, the products list out at 12 products per page. Even if I use the function provided by WooCommerce it seems to refuse to change:

Is these something by default in Sage 8 that would cause this? I’ve got light customizations and the only plugins installed at the moment are WooCommerce 3.3.5 and the one mentioned above.

Thanks!


#2

You probably checked this but maybe the wordpress reading settings still overwrites it despite what they say? Happened to me a lot of times.


#3

Yeah, I checked - that’s set to 9 - but it shows 12.

I have no idea where the 12 is coming from. :thinking:


#4

There is nothing at all in a default Sage install that would cause this. Check your code for any references to pre_get_posts. Please use WordPress Stack Exchange or some other avenue for general WordPress questions :slight_smile:


#5

Thanks! I’ll post there (and sorry!).

I didn’t think so - however - I figured I’d post in here to see since inevitably someone will tell me to check with the theme developers.

I did a grep for “pre_get_posts” and can’t find anything, so strange.

Thanks tho! That’s what I needed to know. :grin:


#6

Actually - sorry to ping back here - but it does seem to be something with Sage even on a default install. I just setup a blank install of Sage 8.5.4 and tried using the following snippet:

Regardless of the priority and with nothing else installed it just seems to show 12 products.

I also installed this on a blank Sage 8.5.4 + WooCommerce 3.4 install and it didn’t work the same:

So it doesn’t seem to be anything I added, but rather, something in Sage messing it up. :thinking:

Does anyone have any idea at all what it could be?


#7

Your number 12 may be coming from that plugin: https://plugins.trac.wordpress.org/browser/woocommerce-products-per-page/trunk/woocommerce-products-per-page.php#L180

I don’t have WooCommerce in front of me to dig into, but if it is interacting strangely with Sage, my guess would be that the filters/actions that WC uses are getting confused by Blade, or (less likely) by Sage’s filters.


#8

It’s in the theme customizer settings. Appearance -> Customize -> WooCommerce -> Product Catalog then Products per row and Rows per page settings :+1:t2:


#9

Thanks for the replies!

To be clear…

“Products Per Page” is what I WANT to work - but - it’s NOT working on a default Sage 8 install. The only things installed are WooCommerce and that plugin and it’s not functioning.

On that same note, for Keshy’s comment – those are not default functions of the latest version of WooCommerce as far as I can tell but I am familiar with the add-on you’re talking about that adds them as I’ve used it in the past:

The “Page Per Post” functionality of that plugin doesn’t work either on a default install of Sage 8. Just tried it out.

Something must be up, I know it’s a conflict of something in the theme – but – just trying to figure out WHAT it could be. I reached out to the developers of both of those addons and they’ve essentially pointed to something in Sage.

Thanks for all your help, I still have not figured this out. ¯_(ツ)_/¯


#10

It’s not a Sage issue guaranteed.

They are default in the WP admin Customizer, there not add-on required. I just make confirm with fresh Sage 8 and Sage 9 installs + Woo and also no other pluggos installed.

This setting not in WooCommerce settings, please check the theme Customizer located at /wp-admin/customize.php. From then you click WooCommerce -> Product Catalog then Products per row and Rows per page and change those setting.

Those plugin you say tried probably don’t work because I think Customizer overrides filter hooks (you really don’t need it plugin for such a simple changes anyway). However, the plugins may work if you remove the settings controls from the Customizer.

If you want to remove some settings anyway it’s pretty easy:

function remove_woo_catalog_count_customizer($wp_customize) {
  $wp_customize->remove_control('woocommerce_catalog_columns');
  $wp_customize->remove_control('woocommerce_catalog_rows');
}
add_action('customize_register', __NAMESPACE__.'\\remove_woo_catalog_count_customizer', 20, 1);

#11

Thanks so much for your help! Truly appreciate you trying to help me out here! :slight_smile:

This setting not in WooCommerce settings, please check the theme Customizer located at /wp-admin/customize.php. From then you click WooCommerce -> Product Catalog then Products per row and Rows per page and change those setting.

I’m sorry about that, I didn’t mean to imply I thought it was in the WooCommerce settings. I didn’t explain myself well. I specifically want Products Per Page. This functionality is NOT default in WooCommerce 3.4.0 in the Theme Customizer. What you are showing me there (which do seem to be there, yes) are Products Per Row and Rows Per Page – while super similar, it’s not quite the same thing. I actually want the visitor to be able to define the amount of products per page on the front end specifically. I actually didn’t realize those were there - sorry about that - that must be semi new as they were not the last time I looked – but – again it’s not what I want anyways.

EDIT: It seems when you add something like the snippet I tried WooCommerce automatically hides it from the customize screen, which, is why I didn’t see those two - sorry for the confusion! Those are deff new-ish, the last time I setup a WooCommerce site a plugin was common to add those there. That’s what I was thinking. :stuck_out_tongue:

you really don’t need it plugin for such a simple changes anyway

I agree with you! However, I’m not simply trying to change the settings. If I were just going to override it and have it be static that’d be something I’d be fine to do. I want the functionality of Products Per Page specifically that has a dropdown that allows the viewer to change it themselves. Otherwise I’d just make due with the Products Per Row / Rows Per Page to set it how I wanted it.

It’s not a Sage issue guaranteed.

I hear you, however, I’m looking at a fresh install of WordPress, Sage 8.5.4, and WooCommerce 3.4.0 right now and when I attempt to use the plugin I showed above:

It doesn’t work. Also when I attempt to do it without a plugin and use this snippet from WooCommerce:

It also doesn’t work – however – if I switch to twentyeleven or twentytwelve it works completely fine…

So, if it’s not something in Sage blocking it, what am I missing here? I’d very much love to just be a total idiot who’s missing something easy but I just don’t see it.


#12

Where are you putting the code from the Woocommerce docs? Perhaps you’re getting caught in not understanding namespaces…


#13

I have just try that snippet in your link and it works 100% with no other changed.


#14

functions.php - as per the documentation.

When I put that at the bottom, default WooCommerce 3.4 + Sage 8.5.4 it doesn’t work for me. No other plugins installed.

Believe it or not I’m really not much of an idiot with this stuff, I rarely ever get this stuck.


#15

Like Kale says you need to add the namespace to that add_filter(). Without the namespace you should see an PHP error, if you not see the error then means you have debug turned off it’s not good.

Please look at first line:

add_filter( 'loop_shop_per_page', __NAMESPACE__.'\\new_loop_shop_per_page', 20 );

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 = 9;
  return $cols;
}

And if you want know more about this namespaces you can look here for Sage: https://roots.io/upping-php-requirements-in-your-wordpress-themes-and-plugins/


#16

Nah, I’m familiar with Namespaces and all of that was fine! I finally figured this out though –

It wasn’t actually any of that, weirdly, all I needed to do was declare WooCommerce support as per the directions here:

Then just like that both the snippet as well as the plugin worked out of the box. Both on my development and blank install.

I’ve never had that issue in the past (something not working because I hadn’t declared support with WooCommerce). I’ll make a note of that should I have to do it again in the future…

Thanks for your help all! Appreciated yinz putting up with me while I sorted it!