在Woocommerce中隐藏特定产品的相关产品单页 [英] Hide Related Products from specific products single pages in Woocommerce
问题描述
好的,所以我试图隐藏产品页面上的相关产品"部分,但仅针对特定产品而不是所有产品.
Okay so I am trying to hide the 'Related Products' section on the product page, BUT only for a specific product not all products.
我找到了以下文档来隐藏所有产品页面的部分: https://docs.woocommerce.com/document/remove-related-posts -output/
I have found the following documentation to hide the section for all product pages: https://docs.woocommerce.com/document/remove-related-posts-output/
但是正如我提到的,这是如何在所有产品页面上隐藏相关产品"部分的方法.但我正在寻找一种仅在特定产品页面上隐藏此部分的方法.
But as I mentioned this is how to hide the 'Related Products' section on all product pages. But I am looking for a way to hide this section ONLY on a specific product page.
是否有人对如何实现这一目标有任何想法.我将不胜感激.
Does anyone have any idea on how this can be achieved. I would greatly appreciate any help.
推荐答案
尝试以下操作,这些操作将从特定的已定义产品ID页中删除相关产品:
Try the following that will remove related products from specific defined product ID(s) page(s):
add_action( 'woocommerce_after_single_product_summary', 'remove_related_products_conditionally', 1 );
function remove_related_products_conditionally(){
global $product;
// HERE Define your targeted product Id(s) (in the array)
$targeted_products = array( 37 );
if( in_array( $product->get_id(), $targeted_products ) )
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
}
代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试和工作.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
这篇关于在Woocommerce中隐藏特定产品的相关产品单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!