Tell us what you are trying to do?
Just need to add a view to my single product template page that lists upsell products- how do I filter for that? Cheers.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - to get upsell product IDs you need to use custom shortcode that returns all the upsell product IDs.
For example:
function func_get_product_upsell_ids() {
global $post;
$product = new WC_Product($post->ID);
$upsells = $product->get_upsell_ids();
return join(",",$upsells);
}
add_shortcode( 'get_upsell_ids', 'func_get_product_upsell_ids' );
And create a view, add Query filter and filter it by Post Id and select filter by shortcode attribute:
[wpv-view name="view-name" ids="[get_upsell_ids]"]
Where:
- ids is a view's shortcode attribute that contains the value returns by shortcode [get_upsell_ids].
- Please DO NOT FORGET to register the shortcode name get_upsell_ids at:
=> Toolset => Settings => Front-end Content => Third-party shortcode arguments
More info:
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/#source-for-compare-value