Skip to content

Instantly share code, notes, and snippets.

@wpbean
Created October 26, 2019 20:02
Show Gist options
  • Select an option

  • Save wpbean/24be60348a7ceba18fb519887d819377 to your computer and use it in GitHub Desktop.

Select an option

Save wpbean/24be60348a7ceba18fb519887d819377 to your computer and use it in GitHub Desktop.
Add Custom Related Products Globally to all the Related Products
<?php
// Add the following code on your theme or child theme functions.php file -
if( !function_exists('wpb_wrps_add_custom_related_products') ){
function wpb_wrps_add_custom_related_products( $args ) {
global $product;
$number_of_related_products = wpb_wrps_get_option( 'wpb_wrps_number_of_products', 'wpb_wrps_general', 100 );
$default_related = apply_filters( 'wpb_wrps_related_products_ids', wc_get_related_products( $product->get_id(), $number_of_related_products, $product->get_upsell_ids() ));
$args['post__in'] = array_merge( $default_related, array(14, 20, 25) ); // Your custom related products ids here
return $args;
}
}
add_filter( 'wpb_wrps_related_products_args', 'wpb_wrps_add_custom_related_products' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment