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
- WooCommerce Checkout – Validate User Role
- Possible to overwrite load_template function in plugin using functions.php
- Only Homepage not loading properly
- WooCommerce shop page orderby [closed]
- How can you include a theme template file from within a plugin (i.e. WooCommerce’s Shop page)?
- Inserting HTML tag with ACF into shortcode
- woocommerce 3.2.1 not sending order notification emails
- Integrating non-WooCommerce and WooCommerce Orders together [closed]
- Change the method of a class from child function.php
- Executing my function once on a specific time
- Override Javascript in a Plugin?
- WooCommerce Custom Product to checkout
- Woocommerce – How to populate custom select field with stored values on checkout page?
- How to append to title via functions.php for auto-posting plugin [duplicate]
- How to stop or remove an action being called inside a function of an extended class
- Missing Argument
- load_plugin_textdomain error
- Automatically add attributes to woocommerce product?
- Reduce Drop down Menu Width in WordPress
- How to override a plugin function wrapped in a class?
- Bootstrap Drop Down menu is not working
- How to Display a Plugin function (content) on frontpage using index.php
- wordpress plugin is not activating from widget
- Theme my Login plugin, how to update fields
- Edit Yoast SEO breadcrumbs output [closed]
- Adding Shortcode to Text Widget
- Date calculations from 2 custom fields
- Admin Panel pagination link styles
- Snippets: is it better to add them in functions.php or make site-specific plugins?
- Does WordPress validate inputs to all functions? (such as get_user_meta and insert_user_meta)
- Custom random quote widget breaks when used in multiple sidebars
- Using a function to change favorites listing
- Display post lists in 2nd paragraph
- How to debug error message: Cannot modify header information
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- Using a post-signup hook to get user details
- Pagination Broken on Static Pages but Works on Blog Articles
- How to change constants in WordPress wp-config.php programmatically?
- What are wsm tables for?
- WordPress automatically removes line break
- Restrict media upload size by format
- How to use a class from another plugin
- Why required field not working in Country dropdown in WooCommerce –
- Override Plugin Script Fucnction in WordPress
- Woocommerce API HTTP Response 401
- How to display custom sidebar in wordpress 5.5.2
- woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax
- How to use WP-CLI / WC-CLI to bulk import 1000s of products (variable and simple)?
- Add woocommerce variation images in gallery?
- Calling plugin function inside custom plugin for onclick event
- woocommerce payment gateway callback not firing [closed]
- Show function to super admin
- How to modify WCMP Rest API response?
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- WordPress Keeps Logging Out – What Tests Can I Run to Solve This?
- Woocommerce dependent plugin
- How to check current user before all actions and filters?
- New databes tables with – WooCommerce – for developers [closed]
- How to send an automated email to the customers when product is added woocommerce
- creating html reusable blocks via shortcodes
- get current date + 90 days and checking every day
- Modifying a .js Function for Print [QZ Tray, WooCommerce POS]
- WooCommerce: Building a page with user input which is used to query order status and external API and return a result
- woocommerce product countdown not showing in variable product? [closed]
- Change commission_status paid when withdraw_status vendor is completed
- I want to disable Cash on delivery based on product tag in woocommerce Checkout Page [closed]
- Is there a way to create custom product templates based on category on WooCommerce?