WooCommerce有关于如何在woocommerce产品页面底部添加一个额外标签的文档。代码被插入到functions.php中并且是可编辑的。
我只是想知道如何在functions.php中添加更多标签而不会相互冲突。我需要为第二个和第三个额外选项卡添加什么代码。
以下是第一个标签的woocommerce代码:
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
&#13;
答案 0 :(得分:1)
保留初始函数,只需添加第二个函数的副本,然后将它们添加到第一个函数的$tabs
数组中。
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
$tabs['test_tab_two'] = array(
'title' => __( 'Another New Product Tab', 'woocommerce' ),
'priority' => 60,
'callback' => 'woo_new_product_tab_content_two'
);
$tabs['test_tab_three'] = array(
'title' => __( 'Yet Another New Product Tab', 'woocommerce' ),
'priority' => 70,
'callback' => 'woo_new_product_tab_content_three'
);
return $tabs;
}
function woo_new_product_tab_content() {
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
function woo_new_product_tab_content_two() {
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
function woo_new_product_tab_content_three() {
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
答案 1 :(得分:1)
这是修改后的代码---
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab_one'] = array(
'title' => __( 'New Product Tab 1', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content_one'
);
$tabs['test_tab_two'] = array(
'title' => __( 'New Product Tab 2', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content_two'
);
return $tabs;
}
function woo_new_product_tab_content_one() {
// The new tab content for 1
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
function woo_new_product_tab_content_two() {
// The new tab content for 2
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}