Last active
September 19, 2024 12:40
-
-
Save woogist/5975638 to your computer and use it in GitHub Desktop.
WooCommerce - Change number of related products on product page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WooCommerce Extra Feature | |
* -------------------------- | |
* | |
* Change number of related products on product page | |
* Set your own value for 'posts_per_page' | |
* | |
*/ | |
function woo_related_products_limit() { | |
global $product; | |
$args['posts_per_page'] = 6; | |
return $args; | |
} | |
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' ); | |
function jk_related_products_args( $args ) { | |
$args['posts_per_page'] = 4; // 4 related products | |
$args['columns'] = 2; // arranged in 2 columns | |
return $args; | |
} |
+1 for suggesting to add the priority to the add_filter() function. Got it working for me!
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args', 20 );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Derek, that did the trick with priority. So, I wanted to change the number of products per row and ended up with this:
/* ADD 4 RELATED PRODUCTS */
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args', 20 );
function jk_related_products_args( $args ) {
$args['posts_per_page'] = 4; // 4 related products
$args['columns'] = 4; // arranged in 4 columns
return $args;
}
I figured I'd post it here in case someone else is looking to do the same.