Home›Toolset Professional Support›[Resolved] Split: Custom View to display Upsell/Related Products – display upsell and related product when upcell is product is less than eight
[Resolved] Split: Custom View to display Upsell/Related Products – display upsell and related product when upcell is product is less than eight
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Is there any way I could have a View of 8 Upsell/Related products where the upsell products are displayed first and then, if room for related products, those are added?
Like 3 upsell products and then 5 related products inside the grid of 2x4? Now the 8 related products are dangling a bit silly below the upsell products.
And then I've edit your existing elementor product template:
- hidden link
And removed the related product view widget from your elementor template and adjusted the code added to content template as given under:
=> hidden link
Thank you for providing that code.
2 issues I run into:
- on a product with upsell items hidden link, could you reverse the order so that the upsell products come first and after those the remaining related products? Upsells are more important than related items.
- on a product without upsell items hidden link, the page is broken due to the snippet if I insert either [upsells] or [wpv-post-body view_template="upsell-product-view-container"]
2 issues I run into:
- on a product with upsell items hidden link, could you reverse the order so that the upsell products come first and after those the remaining related products? Upsells are more important than related items.
===>
I've adjusted the code added to "Custom Code" section as given under:
add_filter('wpv_filter_query_post_process', 'func_show_upsell_related_products', 99, 3);
function func_show_upsell_related_products( $query, $view_settings, $view_id ) {
global $post;
if($view_id == 3680 ){
$min_num_of_products_display = 8;
$upsell_count = 0;
$upsell_ids = get_post_meta( $post->ID, '_upsell_ids', true );
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'post__in'=>$upsell_ids);
$upsell_posts = get_posts( $args );
$upsell_count = count($upsell_posts);
if( $upsell_count < $min_num_of_products_display ) {
$rel_products = get_view_query_results( 3937 ); /// 3937 is the related product view ID
$get_related_count = $min_num_of_products_display - $upsell_count;
$related_ids = array();
for($i=0;$i<$get_related_count;$i++){
$related_ids[]=$rel_products[$i];
}
$total_found_posts = array_merge($upsell_posts,$related_ids);
$query->posts = $total_found_posts; // add the default post to the posts result array
$query->found_posts = count($total_found_posts); // modify the count of found posts
$query->post_count = $total_found_posts; // modify the count of displayed posts
}
}
return $query;
}
- on a product without upsell items hidden link, the page is broken due to the snippet if I insert either [upsells] or [wpv-post-body view_template="upsell-product-view-container"]
===>
I've removed the shortcode added to your elementor template [upsells] and I can see now page is loaded as expected.
- hidden link
Products without Upsell or Related items, like hidden link or hidden link are still broken. Probably because that is the only product in that category.
Wow, excellent, thank you!
I need to transfer all settings to the live site, so I guess I'll have to edit the view_id to reflect the ID on the live site.
Also, do I still need "upsells" under Functions inside conditional evaluations?