仅用于WooCommerce单一产品页面中的某些产品的隐藏选项卡
问题描述:
我想知道如何才能隐藏或移除某些单一产品页面上的WooCommerce选项卡(如果可能,请将它们保留在使用css或jquery的其他页面上)?仅用于WooCommerce单一产品页面中的某些产品的隐藏选项卡
Woocommerce DIV标签:class="woocommerce-tabs wc-tabs-wrapper"
答
这很容易消除对某些单一产品WooCommerce标签。您可以使用CSS轻松完成此操作。每个WC产品都有一个唯一的产品ID,请检查此http://prntscr.com/dp2c79,您会发现这使用浏览器检查元素或源代码。 查找产品ID,然后使用该产品ID的“显示:无”标签。
实例:#产品-834 .tabs:;
问候,
答
可以使用专用woocommerce_product_tabs
滤波器钩去掉突出部只对一些产品(在{显示无重要!}单品页):
add_filter('woocommerce_product_tabs', 'conditionaly_removing_product_tabs', 98);
function conditionaly_removing_product_tabs($tabs) {
// Get the global product object
global $product;
// Get the current product ID
$product_id = method_exists($product, 'get_id') ? $product->get_id() : $product->id;
// Define HERE your targetted products IDs in this array <=== <=== <===
$target_products_ids = array(123,152,162);
// If the current product have the same ID than one of the defined IDs in your array,…
// we remove the tab.
if(in_array($product_id, $target_products_ids)){
// KEEP BELOW ONLY THE TABS YOU NEED TO REMOVE <=== <=== <=== <===
unset($tabs['description']); // (Description tab)
unset($tabs['reviews']); // (Reviews tab)
unset($tabs['additional_information']); // (Additional information tab)
}
return $tabs;
}
代码放在function.php
文件您的活动柒的d主题(活动主题或任何插件文件)。
此代码已经过测试并可正常工作。
根据原来的WooCommerce片段:Editing product data tabs