当产品的长描述字段为空时,我想隐藏 WooCommerce 产品的“描述”标题。
我试过这个:
// Remove Empty Tabs
add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_tabs', 20, 1 );
function yikes_woo_remove_empty_tabs( $tabs ) {
if ( ! empty( $tabs ) ) {
foreach ( $tabs as $title => $tab ) {
if ( empty( $tab['content'] ) && strtolower( $tab['title'] ) !== 'description' ) {
unset( $tabs[ $title ] );
}
}
}
return $tabs;
}
Run Code Online (Sandbox Code Playgroud)
但这并没有最终隐藏标题。该标题似乎不是实际的选项卡。
在渲染的源中看起来像这样:
<div class="product-description">
<h3 class="summary-description-title">Description</h3>
</div>
Run Code Online (Sandbox Code Playgroud) php wordpress woocommerce hook-woocommerce woocommerce-theming