Woocommerce custom related, cross-sell, upsell products

We need customize the list of “related products”, “cross-sells”, “upsells”.
As I see searching in the forum, there are lot of people looking for a way to make custom list for “related products”, “cross-sell” or “upsell” lists of products.

There is a semi solution here: Layout - wc single - related product looper
but it is going to show only products in the same category (the native “related products” query also takes in account tags).

Looks like it could be a condition for templates of kind “Woocommerce archive” for “related products”, “cross-sell”,… so it could be easy to override the template for this lists of products (like there is a condition “Store”).

Other way maybe with a looper that use the native query for these lists of products.

thank you

Hi @llribas,

Thanks for reaching out.
It is not very clear what kind of customized cross-sells, upsells, and related products you are trying to get here. You can use the custom Query String to get a specific set of Products, or else you can create a custom Looper Provider that will return the set of products for Related, Cross Sells, and Upsells.
For more details about the Looper Provider Custom kindly check this out: https://theme.co/docs/loopers#custom You can also go through the following thread on custom loopers, which may help you with this.


Thanks

Yes, I want to create a custom Looper Provider that will return the set of products for Related , Cross Sells , and Upsells .

Ok, I think I’m very close to do it:

I did a custom hook:

add_filter( 'cs_looper_custom_my_related_products', function($result) {
    global $product;
    $product_id = $product->get_id();
    $result = wc_get_related_products( $product_id );
    return $result;
});

and the custom Looper Provider, with the hook: my_related_products

Then, in the Looper Consumer I have a test “text” with:

{{dc:looper:item}}<br>
{{dc:post:title}}

where I can see the {{dc:looper:item}} that corresponds to the correct ids of the “related products”, but the {{dc:post:title}} is always the Title of the current Product, not the “related products Title”.

So I think I’m missing a last piece to get it working.
What needs the looper? is not correct a list of id’s?

Thank you for your help

Hello @llribas,

Thanks for updating in!

The $result should be returning the WP Object so that you can use the {{dc:post:title}}. I would recommend that you do a debug first by adding {{dc:looper:debug_consumer}}. Clicking the debug icon should display the Object and you’ll be able to find out the fields which you can use like {{dc:looper:field key="title"}}.

Be advised that custom PHP coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.