本帖最后由 小米虾 于 2020-10-18 19:39 编辑
首先,需要将以下对应的代码添加到主题或子主题下的functions.php文件中,或者通过允许添加自定义功能的插件(例如代码片段等相关插件)添加。请不要将自定义代码直接添加到父主题的functions.php文件中,因为当您更新主题时,该代码将被完全删除。
1.要删除指定TAB选项卡中的标签,代码如下:
- /**
- * 删除产品TAB选项卡
- */
- add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
- function woo_remove_product_tabs( $tabs ) {
- unset( $tabs['description'] ); //删除描述的项选卡
- unset( $tabs['reviews'] ); //删除评论的项选卡
- unset( $tabs['additional_information'] ); //删除附加信息的选项卡【这个应该用的比较多】
- return $tabs;
- }
复制代码 2.对TAB选项卡标签进行命名,代码如下:
- /**
- * 重命名产品TAB选项卡
- */
- add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
- function woo_rename_tabs( $tabs ) {
- $tabs['description']['title'] = __( 'More Information' ); //重命名描述的项选卡
- $tabs['reviews']['title'] = __( 'Ratings' ); //重命名评论的项选卡
- $tabs['additional_information']['title'] = __( 'Product Data' ); //重命名附加信息的选项卡
- return $tabs;
- }
复制代码 3.重新排序产品TAB选项卡,代码如下:
- /**
- * 重新排序产品TAB选项卡
- */
- add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
- function woo_reorder_tabs( $tabs ) {
- $tabs['reviews']['priority'] = 5; // 将评论选项卡排在第一
- $tabs['description']['priority'] = 10; // 描述标签排在第二
- $tabs['additional_information']['priority'] = 15; // 附加信息排在最后
- return $tabs;
- }
复制代码 4.添加一个新的产品TAB选项卡,代码如下:
- /**
- * 添加一个新的产品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' ),
- 'priority' => 50,
- 'callback' => 'woo_new_product_tab_content' // 这里是写对应的新选项卡对应内容的函数名称,不明白,可直接复制即可
- );
- return $tabs;
- }
- //这里是写对应的新选项卡对应内容的函数具体内容
- function woo_new_product_tab_content() {
- // 这里可以输出具体的内容,以下是PHP代码格式,echo表示输出的意思,可按格式对应的添加多行HTML代码内容,需要一定的代码基础
- echo '<h2>New Product Tab</h2>';
- echo '<p>Here\'s your new product tab.</p>';
-
- }
复制代码
|