【发布时间】:2021-07-12 20:18:15
【问题描述】:
我在 ACF 插件中创建了一个字段。我添加了下面的代码以将数据显示为自定义选项卡,但即使该字段为空,该选项卡也始终可见。我错过了什么?
// 1.Displays the tab on every product page
add_filter( 'woocommerce_product_tabs', 'woo_new_tab' );
function woo_new_tab( $tabs ) {
// Adds the new tab
if (!empty(get_the_content())) {
$tabs['application'] = array(
'title' => __( 'Application', 'woocommerce' ),
'priority' => 20,
'callback' => 'woo_new_tab_content'
);
return $tabs;
}
}
// the callback (refer to https://www.advancedcustomfields.com/resources/code-examples/) for more info
function woo_new_tab_content() {
// The new tab content
//Working with Array values (checkbox, select, relationship, repeater) use below
$values = get_field('application'); //field name
if($values){
echo '<ul>';
foreach($values as $value){
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
}
【问题讨论】:
标签: php wordpress woocommerce product advanced-custom-fields