Skip Navigation

[Resolved] Upsell and cross sell filter

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 13 replies, has 3 voices.

Last updated by dmitryK-2 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1165513
Schermafdruk 2018-12-13 14.49.49.png

Hi,

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();

return join(",",$upsells);

}
add_shortcode( 'get_upsell_ids', 'func_get_product_upsell_ids' );

Page template:

[wpv-view name="Family products" ids="[get_upsell_ids]"]

Example page: hidden link

For the registert shortcode please see the image.

I need the exact same filter for upsells and cross sells.

Upsells is called Family in my example and Cross sell is called related.

Thanks.

#1165554
Screen Shot 2018-12-13 at 9.46.16 AM.png

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:

Upsell IDs test: [get_upsell_ids]<br />
View test: [wpv-view name="Family products" ids="[get_upsell_ids]"]

Check the front-end of the site and confirm these IDs correspond to the correct posts.

#1165582
Schermafdruk 2018-12-13 16.01.48.png

Hi Christian,

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?

What should I do now?

#1165642
Schermafdruk 2018-12-13 17.24.14.png
Schermafdruk 2018-12-13 17.19.11.png

Hi Christian,

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.

#1165707

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.

#1165729

Of course.. hope this is what you mean:

[wpv-layout-start]
[wpv-items-found]
<div id="related" class="related">
<h2>Family products</h2>
<!-- wpv-loop-start -->
<ul class="products columns-4">
<wpv-loop>
[wpv-post-body view_template="loop-item-in-family"]
</wpv-loop>

<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
</div>
[/wpv-no-items-found]
[wpv-layout-end]

Template:

<li class="post-[wpv-post-id] product type-product status-publish has-post-thumbnail product_cat-recessed-luminaires product_cat-adjustable-round first instock shipping-taxable purchasable product-type-variable has-default-attributes">
<div class="product-h">

<h2>[wpv-post-title]</h2>
</div>

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;)

#1165767

Okay I see a couple of things.
1. The "related" div in the Loop Editor is not closed correctly. The Loop should probably be like this:

[wpv-layout-start]
[wpv-items-found]
<div id="related" class="related">
<h2>Family products</h2>
<!-- wpv-loop-start -->
<ul class="products columns-4">
<wpv-loop>
[wpv-post-body view_template="loop-item-in-family"]
</wpv-loop>

<!-- wpv-loop-end -->
[/wpv-items-found]
</div>
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

2. Nesting double quotes like this can cause unexpected problems:

<img src="[wpv-woo-product-image size="shop_catalog" output="raw"]" alt="" />

I would replace the nested double quotes with single quotes:

<img src="[wpv-woo-product-image size='shop_catalog' output='raw']" alt="" />

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.

#1165787

Hi,

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?

#1165800

May I log in to your wp-admin area and see how things are set up? I will activate private reply fields here.

#1167157

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.

#1167160

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.

#1167161

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]

#1167192

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.

#1811345

Hi, Christian

I have. more or less same issue - upsells are not filtered ( -> https://toolset.com/forums/topic/upsells-products-are-not-filtered/)
is it possible to have a. look at corrections made in functions.php