Related product array with user input
-
I am using woocommerce (but this is a general question regardless) and I am using the following code as the footer of my single-product.php page (I’ve created a “Related Products” section) and I am wondering if there is a way that I can alter it to make it possible for admin to be able to add values from the product admin page; I want certain products to show closer related products instead of totally random ones.
Is there a way I can create a custom field for something like product ID or tag and then add that custom field as the
orderby
value so those products/tags have a better change of showing up vs. random products?If not, is there anything else I can do? I am simply looking for a way to allow an admin to choose closer related products to appear.
$args = apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => 5, 'orderby' => rand, 'post__in' => $related, 'post__not_in' => array( $product->id ) ) );
Here is my related-footer.php file with the complete code that includes the above snippet.
- The topic ‘Related product array with user input’ is closed to new replies.