Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Last active September 5, 2022 11:07
Show Gist options
  • Save pramodjodhani/f0ffa5836f0a6963bd904e7c0127ef7f to your computer and use it in GitHub Desktop.
Save pramodjodhani/f0ffa5836f0a6963bd904e7c0127ef7f to your computer and use it in GitHub Desktop.
Orderable - Fix issue where addons are not working for some product.
<?php
/**
* Orderable - Fix issue where addons are not working for some product.
* This issue happens because by default for performance reasons,
* orderable only loads the first 100 product addons posts (orderable_addons)
* This snippet would force load 500 addons.
*
* @param WP_Query $q Query.
*
* @return void
*/
function orderable_fix_increase_addons_limit( $q ) {
$post_type = $q->get( 'post_type' );
if ( 'orderable_addons' === $post_type && 100 == $q->get( 'posts_per_page' ) ) {
$q->set( 'posts_per_page', 500 );
}
}
add_action( 'pre_get_posts', 'orderable_fix_increase_addons_limit' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment