WooCommerce 单品自定义 Tab 显示页面内容 [英] WooCommerce single product custom Tab displaying a page content
本文介绍了WooCommerce 单品自定义 Tab 显示页面内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为单个产品创建了一个自定义选项卡,并想通过下面的代码了解是否有办法指定某个页面作为该选项卡的内容?
I have created a custom tab for a single product and would like to know with the code below if there is a way to specify a certain page to act as the content for that 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' => __( '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>';
}
推荐答案
可以通过这种方式为定义的帖子 ID(页面)调用经典的 WordPress 帖子内容:
This is possible calling a classic WordPress post content for a defined post ID (page) this way:
//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 文件中.
此代码已经过测试并有效.
This code Is tested and works.
这篇关于WooCommerce 单品自定义 Tab 显示页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文