WordPress filter hook

woocommerce_related_products_args

Fired by 8 WordPress plugins, running on 10K+ sites between them.

How to use woocommerce_related_products_args

It's a filter: your callback receives the value, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'woocommerce_related_products_args', function( $value ) {
	// Change $value here.
	return $value;
}, 10, 1 );

Argument names come from WooLayout's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

8 plugins that fire woocommerce_related_products_args

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Solace Extra icon Solace Extra10,000+ installs apply_filters( 'woocommerce_related_products_args', [ 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $limit, 'post__in' => $related_ids, 'post__not_in' => [$product_id], ] ) elementor/widgets/widget/shop/related-product.php:1213
  2. Wishlist and Waitlist for WooCommerce icon Wishlist and Waitlist for WooCommerce100+ installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'posts_per_page' => $product_count, 'orderby' => 'rand', 'post__in' => $related, 'post__not_in' => $current_wait ) ) templates/widget.php:20
  3. Frequently Bought Together Product For WooCommerce icon Frequently Bought Together Product For WooCommerce70+ installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'post__not_in' => array( $pro_id ), 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => -1, 'tax_query' => $tax_query ) ) main/frontend/fbtpfw-common-functions.php:281
  4. Educat Elementor LMS Addon icon Educat Elementor LMS Addon20+ installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $settings['posts']['size'], 'post__in' => $related, ) ) includes/widgets/woocommerce/woo-related-product/grid.php:18
  5. WooLayout icon WooLayout10+ installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related, 'post__not_in' => array( $product->id ) ) ) lib/woolayout/single-product/related.php:28
  6. Comparis icon Comparis10+ installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related, 'post__not_in' => array( $product->id ) ) ) templates/woocommerce/single-product/related.php:22
  7. Woo Custom Related Products Slider [Lite] by AU icon Woo Custom Related Products Slider [Lite] by AUFewer than 10 installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related, 'post__not_in' => array($product->id) ) ) inc/related-products.php:362
  8. WEBD Woo Event Bookings icon WEBD Woo Event BookingsFewer than 10 installs apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related, 'post__not_in' => array( $product->get_id() ) ) ) templates/related.php:37

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.