I'm following the exact steps mentioned on this page: https://toolset.com/forums/topic/need-to-get-upsell-pro/
This is exactly what I need. But it is not working. I have registert the shortcode and placed it in the view. Instead of filtering the results it show all the available products. What am i doing wrong?
This is the code in functions.php:
function func_get_product_upsell_ids() {
global $post;
$product = new WC_Product($post->ID);
$upsells = $product->get_upsell_ids();
Hi, please confirm there is a Post ID Query Filter added in the View editor screen in wp-admin. This filter must be configured to include posts whose IDs are passed into a shortcode attribute ids. Please see the attachment here for an example.
If you cannot see the Query Filter in your View editor screen, scroll to the top right corner and click "Screen Options". You can enable the Query Filter panel here.
If this does not solve the problem, please move the custom upsell IDs shortcode outside of the View shortcode to confirm it is returning the correct IDs:
Thanks. I can confirm the filter is there, please see the screenshot for confirmation.
The test is returning nothing like you can see on: hidden link for this product that's oke actualy, this product does return 1 value: hidden link that's correct. Why is the filter returning all the products if there's no value available or "" empty? It should sow nothing right?
I think I have found another issue as well with the filter. On this page: hidden link
The tests return different results for the cross sell items (or related as I call them here). The id test returns 51721 and the view returns: No items found. The cross sell field in WooCommerce is empty as it should in this case, so the views items test looks correct to me and I'm not sure where the value 51721 is coming from.
Can you copy + paste the code from the Loop Editor for me to review? If there is a content template used in this Loop, please copy + paste the code from that template as well.
I'm using the exact same loop and template for cross sell (related) but with different template set of course. I'm not sure if this is necessary but that's off topic I guess. Just starting with Toolset;)
If that doesn't solve the problem, let's simplify the template code. We have the code here as a backup. Please delete everything inside the template, and replace it with a simple [wpv-post-link] shortcode.
I made the improvements you suggested incl. The template modification, but is doesn’t seem to work unfortunatly.. wat should I do now. Template code is now returning the pagetitle and all of them in case the filter returns no or an empty result like before. Seems like the filter isn’t working as it should?
Okay I have fixed the problem where all products were showing when the up-sell or cross-sell shortcode returns no results. Please download the latest version of functions.php to your local repository to get those updates. However, there is a problem I'm not sure how to solve. You have already noticed here: hidden link
The cross-sell shortcode returns the ID 51721, which should be a valid cross-sell product ID. However, you can see in wp-admin, this product does not exist: hidden link
So the View tries to find this post by ID but cannot find it, hence the difference between the shortcode results and the View results. This seems to be a problem with the cross sell API, and I'm not sure how to fix it because it's 3rd party code.
Hi Christian. Thanks a lot. I've checked right away and it looks really good. Very happy with it. What do you mean by downloading it to my local repository? For back-up or local use? I assume you modified it already in the production environment on products.light4u.io? Or at least it looks like it?
I will contact the people that implemented the api for further investigation. It looks like this particular cross-sell product id is stored somewhere out of sight but visible for the shortcode.. I'll get back to you if I have some answers.
One other thing. I have some shortcut buttons on the product page that rely on the outcome of the upsell/cross-sell filters. Seems like the default value or the value that's given when there are no products is now "0" instead "" correct? I guess I need to modify my conditional statements accordingly? Like this?
[wpv-conditional if="( '[get_upsell_ids]' ne '0' )"][us_btn text="Family" link="url:%23family|||" size="" icon="fas|boxes"][/wpv-conditional][wpv-conditional if="( '[get_cross_sell_ids]' ne '0' )"][us_btn text="Related" link="url:%23related|||" size="" icon="fas|link"][/wpv-conditional]
What do you mean by downloading it to my local repository? For back-up or local use?
Yes, I mean both for backup and for local use. If you don't download the updates, next time you push changes to the server you will overwrite the changes I made.
Seems like the default value or the value that's given when there are no products is now "0" instead "" correct?
Correct, the shortcodes must return 0 or else the View's post ID filters will show all results.