简体   繁体   中英

Display related products based on tags only in Woocommerce 3

By default Woocommerce on single product page displays related products based on category - related product slider will display the same category products.

Woocommerce documentation states this - "Related Products is a section on some templates that pulls products from your store that share the same tags or categories as the current product. These products cannot be specified in the admin, but can be influenced by grouping similar products in the same category or by using the same tags."

My shop has 2 categories - "men" and "women", so this Woocommerce related product condition does not work for me. My related products should be more specific, therefore I added tags.

So - I would like to display related products based on tags only, not on categories. How can I do that?

There have been similar questions on this forum, but none of the provided codes worked, maybe because of several Woocommerce updates.

Thank you!

This can be done with this little hooked function:

add_filter( 'woocommerce_get_related_product_cat_terms', 'remove_related_product_categories', 10, 2 );
function remove_related_product_categories( $terms_ids, $product_id  ){
    return array();
}

Code goes in function.php file of the active child theme (or active theme).

Tested and works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM