Created
October 26, 2019 20:02
-
-
Save wpbean/24be60348a7ceba18fb519887d819377 to your computer and use it in GitHub Desktop.
Add Custom Related Products Globally to all the Related Products
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 | |
| // 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