Maybe this would work?
function ps_pre_get_products_query( $query ) {
$per_page = filter_input(INPUT_GET, 'perpage', FILTER_SANITIZE_NUMBER_INT);
if ( ! is_admin() && is_woocommerce() && is_page() ) {
$query->set( 'posts_per_page', $per_page );
}
}
I tested your code and the if statement didn’t seem to work with is_page() (but that could also be because my local WP sandbox is a mess). To my knowing posts_per_page expects int and var_dump showed that $per_page was a string.
EDIT My local WP sandbox is a mess, so that’s why is_page wasn’t working. I tested the code again on another install.
EDIT 2 Let’s see how many times I can get this wrong. I updated the code to something that works (at least on another local WP sandbox).
Related Posts:
- WooCommerce create new product and add to cart on form submit
- Over write plugin templates
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- Change wordpress current_time function to different timezone
- How to enable specific plugin only based around shop manager role?
- Replacing a plugin function with a custom renamed function doesn’t work
- Redirect to another page using contact form 7? [closed]
- Replacing global wp_query
- wc_get_template new template does not showing up
- WordPress Stock Update Programatically
- Woocommerce singe product custom gallery output works just on the first slide
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- How to get custom minimum price in Woocommerce
- How to make WooCommerce payment method field optional?
- Create category for each user
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- ACF Fields are not showing up on Homepage
- Adding discount functionality to the cart
- How to assign a specific service to a specific provider based on location
- Make modification of add_to_cart button specific to single page
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- Securing langugae folder
- Configuring default woo commerce login with modal popup
- Move related products after product summary? [closed]
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- WooCommerce custom query and paging: Not Found error
- Woocommerce – Product Description heading [closed]
- Woocommerce disable checkout on specific day
- Adding a script & php to functions.php
- Override the plugin class and function
- Product customizing quiz – quiz adding products to the cart
- Show WooCommerce products based on query parameters on redirect
- add to cart linking to add to cart page
- How to remove WPML Generator Meta Tag by theme’s functions.php (override plugin function)? [closed]
- WooCommerce – Load Templates From Plugin For All Template Files
- Change destination author link
- How to set value/term of a Woocommerce attribute text field in admin panel?
- How to call a plugin function in footer.php
- How does WooCommerce display a custom comment_type in Comment Admin?
- Override plugin functions in functions.php
- ajax front-end increment views on click
- Display a text message if the field is not found and not if found
- Scope for PHP Variables Assigned in functions.php or a plugin
- Override the filter from plugin in child theme
- How To Hide Filters On Specific Categories with WooCommerce Products Filter(WOOF)
- Add a plugin before main container
- Woocommerce email template customization [closed]
- How to create TEMPORARY Download links in a wordpress POST?
- Infinite Scroll for both Index, Category and Archive
- Conditionally add apt. Open Graph meta data to different pages on WordPress site
- Absolute Image URL in srcset is appended to the upload dir
- How to append to title via functions.php for auto-posting plugin [duplicate]
- Bootstrap Drop Down menu is not working
- Pagination Broken on Static Pages but Works on Blog Articles
- How to change constants in WordPress wp-config.php programmatically?
- Override Plugin Script Fucnction in WordPress
- custom payment gateway in woocommerce failed to connect to remote api server
- Want to Show Sub categories under Categories section using Woo Commerce [closed]
- Conditional attributes and logic per product category
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- How to over-ride a file in a plugin? [closed]
- Overwrite category head title
- execute function after one completed
- Restrict content based on buy woocommerce product
- Product count in archive page Title in WooCommerce [closed]
- 5 PHP Fatal error: Uncaught ArgumentCountError (Cannot Find)
- get_term_meta returns false in widget
- same user role or copy the user role to be same as the other role
- How can i listing current category and Featured Category post list?
- grab or load text on demand
- sliding/fading header plugin or approach suggestion
- Woocommerce Export and import Orders
- Grouping imported products and showing variations based on selected product
- How would I get the new plugin version on this function?
- Add a Custom email notification to WC actions
- How would I Redirect an existing WooCommerce customer to a specific url after Checkout
- Changing wordpress/woocommerce notices default message to other languages (text)
- Search in WordPress
- WooCommerce Checkout Issue specific to Instagram In-App Browser
- Modify function output in a plugin
- How to capture customer’s credit card details via PayPal on my checkout page?
- How to make the first letter of a post title uppercase, in a plugin?
- Payment failed but order is placed on wp site
- How to change the product short description for each product with PHP?
- Help needed with woocommerce (wc stripe) filter
- Code fails in plugin file but works in functions.php
- WordPress plugin options need to delete after deactivate & uninstall
- WordPress function to add text
- Doing action based on input from options menu
- How ACF Advanced Custom Field works with Woocommerce Single Product [closed]
- The plugin generated xxx characters of unexpected output during activation
- How to Allow Users to Select Recipients In a WordPress Comment section?
- How often should I execute add_filter and function declaration in Code Snippets?
- WooCommerce REST API aborts connection [closed]
- How to change all the urls of the WordPress site?
- Automatic assignment of multi images to products in WooCommerce/WordPress with SKU
- Conclude woocommerce-shipping-totals
- Create custom Header and Footer for a page that uses diffrent theme then the rest of the website
- Re-use date format on different template
- Remove and strip html tag values