使用正式文档,我在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>';
}问题是,如果我尝试使用此代码添加另一个选项卡,则会得到错误。
您要保存的代码片段在第17行产生了一个致命错误: 无法重新声明/var/www/html/sport-print.online/wp-content/plugins/code-snippets/php/snippet-ops.php(352) ()(以前在/var/www/html/sport-print.online/wp-content/plugins/code-snippets/php/snippet-ops.php(352):eval()'d代码:5中声明)
你能告诉我怎么再加一个标签吗?
发布于 2018-09-17 13:13:57
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'
);
}粘贴此代码为您的活动主题。
发布于 2018-09-17 09:10:57
我明白我的错误。
工作代码:
/**
* 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>';
}问题解决了。
https://stackoverflow.com/questions/52363611
复制相似问题