我创建了一个自定义选项卡的单品,想知道下面是否有指定的某一页,以作为该选项卡的内容的方式的代码?
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'Seller Disclosure', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>Coming Soon</h2>';
}
这是可能的调用一个经典的WordPress的帖子内容进行定义后ID(页)是这样的:
//Add a new tab in single product pages
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['test_tab'] = array(
'title' => __( 'Seller Disclosure', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
// The tab content (with the page content)
function woo_new_product_tab_content() {
// ==> ==> ==> ==> ==> ==> ==> Replace the ID HERE by your page ID
$page_id = 324;
$page_post_object = get_post( $page_id );
// Get the page content
$page_content = $page_post_object->post_content;
// (optionally Get the page title
$page_title = $page_post_object->post_title;
// The title (Or the page title)
echo '<h2>Coming Soon</h2>'; // Or: echo '<h2>' . $page_title . '</h2>';
// The page content
echo '<div class="page-content-container">' . $page_content . '</div>';
}
代码放在您的活动子主题(或主题)的任何PHP文件或也是任何一个插件php文件。
这个代码是测试和工程。