admin管理员组文章数量:1129101
I want to remove the "additional information" tab, and append its content to the "description" tab. I had no problems adding new tabs or removing existing one. The problem is that, since I have to use a callback for the content of the tab, I do not know how to fetch the original content. My code:
add_filter( 'woocommerce_product_tabs', 'exetera_custom_product_tabs', 98 );
function exetera_custom_product_tabs( $tabs ) {
$tabs['description']['callback'] = function ( ) {
$description = "Original content of the description tab here";
$additional_information = "Original content of the Additional Information tab here";
echo $description;
echo $additional_information;
}; // Custom description callback
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
I don't know how to get the right content for the $description and $additional_information variables from the original content of the respective product tabs.
I want to remove the "additional information" tab, and append its content to the "description" tab. I had no problems adding new tabs or removing existing one. The problem is that, since I have to use a callback for the content of the tab, I do not know how to fetch the original content. My code:
add_filter( 'woocommerce_product_tabs', 'exetera_custom_product_tabs', 98 );
function exetera_custom_product_tabs( $tabs ) {
$tabs['description']['callback'] = function ( ) {
$description = "Original content of the description tab here";
$additional_information = "Original content of the Additional Information tab here";
echo $description;
echo $additional_information;
}; // Custom description callback
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
I don't know how to get the right content for the $description and $additional_information variables from the original content of the respective product tabs.
Share Improve this question asked Mar 1, 2019 at 17:24 DavidTonariniDavidTonarini 2113 silver badges9 bronze badges1 Answer
Reset to default 0The callback used to render the "Description" tab is woocommerce_product_description_tab()
, which simply loads the template file single-product/tabs/description.php
. And for the "Additional Information" tab, the callback is woocommerce_product_additional_information_tab()
and the template is single-product/tabs/additional-information.php
.
So if you want to merge the two tabs, you can copy the "relevant" contents from the template file, like so:
add_filter( 'woocommerce_product_tabs', 'exetera_custom_product_tabs', 98 );
function exetera_custom_product_tabs( $tabs ) {
// Custom description callback.
$tabs['description']['callback'] = function() {
global $post, $product;
// Display the content of the Description tab.
the_content();
// Display the heading and content of the Additional Information tab.
echo '<h2>Additional Information</h2>';
do_action( 'woocommerce_product_additional_information', $product );
};
// Remove the additional information tab.
unset( $tabs['additional_information'] );
return $tabs;
}
Alternate Version
Here we simply call the default callbacks and for the "Description" tab, we disable the default heading text.
add_filter( 'woocommerce_product_tabs', 'exetera_custom_product_tabs', 98 );
function exetera_custom_product_tabs( $tabs ) {
// Custom description callback.
$tabs['description']['callback'] = function() {
// Disable the "Description" heading.
add_filter( 'woocommerce_product_description_heading', '__return_empty_string' );
// Display the content of the Description tab.
woocommerce_product_description_tab();
// Enable the "Description" heading.
remove_filter( 'woocommerce_product_description_heading', '__return_empty_string' );
// Display the heading and content of the Additional Information tab.
woocommerce_product_additional_information_tab();
};
// Remove the additional information tab.
unset( $tabs['additional_information'] );
return $tabs;
}
本文标签: woocommerce offtopicMerge quotdescriptionquot and quotadditional informationsquot product tab
版权声明:本文标题:woocommerce offtopic - Merge "description" and "additional informations" product tab 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736698781a1948321.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论