如何在woocommerce中添加多个选项卡?

如何在woocommerce中添加多个选项卡?,woocommerce,tabs,Woocommerce,Tabs,使用官方文档,我在woocommerce中添加了自定义选项卡: /** * Add a custom product data tab */ add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' ); function woo_new_product_tab( $tabs ) { // Adds the new tab $tabs['test_tab'] = array( 'title' => __(

使用官方文档,我在woocommerce中添加了自定义选项卡:

/**
* Add a custom product data tab
*/
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>';

}
/**
*添加自定义产品数据选项卡
*/
添加过滤器(“woocommerce\u product\u tab”、“woo\u new\u product\u tab”);
功能woo_新产品_选项卡($tabs){
//添加新选项卡
$tabs['test_tab']=数组(
'title'=>uuuu('newproducttab','woocommerce'),
“优先级”=>50,
“回调”=>“求购新产品”选项卡“内容”
);
返回$tabs;
}
功能woo_新产品_选项卡_内容(){
//新的标签内容
echo“新产品标签”;
echo'这是您的新产品标签。

; }
问题是,如果我尝试使用此代码添加另一个选项卡,则会出现错误

您试图保存的代码段在第17行产生了致命错误:

无法重新声明woo_new_product_tab()(以前在/var/www/html/sport print.online/wp content/plugins/code snippets/php/snippet ops.php(352):eval()d code:5中声明)

您能告诉我如何添加另一个选项卡吗?

我理解我的错误=)

工作代码:

/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {

// Adds the new tabs

$tabs['new_tab_1'] = array(
    'title'     => __( 'new_tab_1', 'woocommerce' ),
    'priority'  => 11,
    'callback'  => 'new_tab_1'
);



$tabs['new_tab_2'] = array(
        'title' => "new_tab_2",
        'priority' => 12,
        'callback' => 'new_tab_2'
    );

$tabs['new_tab_3'] = array(
        'title' => "new_tab_3",
        'priority' => 13,
        'callback' => 'new_tab_3'
    );

return $tabs;

}

function new_tab_1() {

// The new tab content

echo '<ol>
    <li>content new_tab_1</li>
</ol>';
}

function new_tab_2() {
echo'
<h3>content new_tab_2</h3>';
}

function new_tab_3() {
echo'<p style="font-weight: bold;">content new_tab_3</p>';
}
/**
*添加自定义产品数据选项卡
*/
添加过滤器(“woocommerce\u product\u tab”、“woo\u new\u product\u tab”);
功能woo_新产品_选项卡($tabs){
//添加新选项卡
$tabs['new_tab_1']=数组(
“title'=>”(“新建”选项卡“1”,“woocommerce”),
“优先级”=>11,
“回调”=>“新建选项卡1”
);
$tabs['new_tab_2']=数组(
“标题”=>“新建选项卡2”,
“优先级”=>12,
“回调”=>“新建选项卡2”
);
$tabs['new_tab_3']=数组(
“标题”=>“新建选项卡3”,
“优先级”=>13,
“回调”=>“新建选项卡3”
);
返回$tabs;
}
函数新选项卡1(){
//新的标签内容
回声'
  • 内容新选项卡1
  • '; } 函数新选项卡2(){ 回声' 内容新建_选项卡_2'; } 函数新选项卡3(){ echo'

    内容新选项卡3

    ; }
    问题解决了。

    我理解我的错误=)

    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
    // Adds the new tab
        $tabs['desc_tab'] = array(
            'title'     => __( 'Additional Information', 'woocommerce' ),
            'priority'  => 50,
            'callback'  => 'woo_new_product_tab_content'
        );
    }
    
    工作代码:

    /**
    * Add a custom product data tab
    */
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
    
    // Adds the new tabs
    
    $tabs['new_tab_1'] = array(
        'title'     => __( 'new_tab_1', 'woocommerce' ),
        'priority'  => 11,
        'callback'  => 'new_tab_1'
    );
    
    
    
    $tabs['new_tab_2'] = array(
            'title' => "new_tab_2",
            'priority' => 12,
            'callback' => 'new_tab_2'
        );
    
    $tabs['new_tab_3'] = array(
            'title' => "new_tab_3",
            'priority' => 13,
            'callback' => 'new_tab_3'
        );
    
    return $tabs;
    
    }
    
    function new_tab_1() {
    
    // The new tab content
    
    echo '<ol>
        <li>content new_tab_1</li>
    </ol>';
    }
    
    function new_tab_2() {
    echo'
    <h3>content new_tab_2</h3>';
    }
    
    function new_tab_3() {
    echo'<p style="font-weight: bold;">content new_tab_3</p>';
    }
    
    /**
    *添加自定义产品数据选项卡
    */
    添加过滤器(“woocommerce\u product\u tab”、“woo\u new\u product\u tab”);
    功能woo_新产品_选项卡($tabs){
    //添加新选项卡
    $tabs['new_tab_1']=数组(
    “title'=>”(“新建”选项卡“1”,“woocommerce”),
    “优先级”=>11,
    “回调”=>“新建选项卡1”
    );
    $tabs['new_tab_2']=数组(
    “标题”=>“新建选项卡2”,
    “优先级”=>12,
    “回调”=>“新建选项卡2”
    );
    $tabs['new_tab_3']=数组(
    “标题”=>“新建选项卡3”,
    “优先级”=>13,
    “回调”=>“新建选项卡3”
    );
    返回$tabs;
    }
    函数新选项卡1(){
    //新的标签内容
    回声'
    
  • 内容新选项卡1
  • '; } 函数新选项卡2(){ 回声' 内容新建_选项卡_2'; } 函数新选项卡3(){ echo'

    内容新选项卡3

    ; }
    问题解决了

    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
    // Adds the new tab
        $tabs['desc_tab'] = array(
            'title'     => __( 'Additional Information', 'woocommerce' ),
            'priority'  => 50,
            'callback'  => 'woo_new_product_tab_content'
        );
    }
    
    将此代码粘贴到活动主题

    将此代码粘贴到活动主题