dsfasdfsda234234 2018-04-18 23:48
浏览 261

Woocommerce中的合并描述和附加信息选项卡

I am trying to merge the additional information tab with the description tab in woo commerce.

Basically the intention is to display information from both tabs side by side in possibly a 2 column layout where the first column displays the description and the second column the additional information.

Can this be achieved with a piece of code that can be placed in functions.php.

Thanks

  • 写回答

2条回答 默认 最新

  • doujiao7520 2018-04-19 13:29
    关注

    Here is the way to make it (code is well commented):

    // Manipulating product tabs
    add_filter('woocommerce_product_tabs', 'change_product_tab', 98);
    function change_product_tab($tabs){
        global $product;
    
        // Save the tabs to keep
        $reviews = $tabs['reviews'];
    
        // Remove tabs
        unset($tabs['description']);
        unset($tabs['additional_information']);
        unset($tabs['reviews']);
    
        // Add a new tab
        $tabs['other_details'] = array(
            'title'     => __( 'Details', 'woocommerce' ),
            'priority'  => 10,
            'callback'  => 'other_details_tab_content'
        );
    
        // Set the good priority to existing "reviews" tab
        $reviews['priority'] = 20;
    
        // Add back "reviews" tab
        $tabs['reviews'] = $reviews;
    
        return $tabs;
    }
    
    // Tab content (two columns)
    function other_details_tab_content() {
        global $product;
    
        $heading = esc_html( apply_filters( 'woocommerce_product_description_heading', __( 'Description', 'woocommerce' ) ) );
        $heading2 = esc_html( apply_filters( 'woocommerce_product_additional_information_heading', __( 'Additional information', 'woocommerce' ) ) );
    
        ?>
        <!-- Temporary styles (to be removed and inserted in the theme styles.css file) -->
        <style>
            .single-product .half-col{float:left; width:48%;}
            .single-product .half-col.first{margin-right:4%;}
            .single-product .half-col > h3{font-size:1.3em;}
        </style>
    
        <h2><?php _e("Product details", "woocommerce"); ?></h2>
    
        <!-- 1. Product description -->
    
        <div class="half-col first">
    
        <?php if ( $heading ) : ?>
          <h3><?php echo $heading; ?></h3>
        <?php endif; ?>
    
        <?php the_content(); ?>
    
        </div>
    
        <!-- 2. Product Additional information -->
    
        <div class="half-col last">
    
        <?php if ( $heading2 ) : ?>
        <h3><?php echo $heading2; ?></h3>
        <?php endif; ?>
    
        <?php do_action( 'woocommerce_product_additional_information', $product ); ?>
    
        </div>
        <?php
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。