Trang chủ Blog Website Share Code Tách Product Tabs thành các section riêng biệt

Tách Product Tabs thành các section riêng biệt

Tách product tabs thành các section riêng biệt

Lại là mì tôm đây. Vì chưa có tiền mua tên miền share code riêng, nên tạm thời chia sẻ luôn trên trang này :v

À, bài này thì mục đích là phân tách nguyên cái product tabs (hay gồm mô tả nè, review nè, thông tin bổ sung nè….). Nhiều người không thích nó gom 1 cục như vậy.

Thành thử tách nó ra cho cái trang dài dài :v nhìn chuyên nghiệp với đẹp mắt , rõ ràng hơn.

Ok zô thôi. Đầu tiên là filter lại cái hàm woocommerce_output_product_data_tabs

if ( ! function_exists( 'woocommerce_output_product_data_tabs' ) ) {
   function woocommerce_output_product_data_tabs() {
      wc_get_template( 'single-product/tabs/tabs.php' );
   }
}

Tiếp theo là viết lại function trên như sau

function woocommerce_output_product_data_tabs() {
   $product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
   if ( empty( $product_tabs ) ) return;
   echo '<div class="woocommerce-tabs wc-tabs-wrapper">';
   foreach ( $product_tabs as $key => $product_tab ) {
      ?>
         <div id="tab-<?php echo esc_attr( $key ); ?>">
            <?php
            if ( isset( $product_tab['callback'] ) ) {
               call_user_func( $product_tab['callback'], $key, $product_tab );
            }
            ?>
         </div>
      <?php         
   }
   echo '</div>';
}

Lụm kẹo. Quăng hết code trên zô function.php là chạy thôi. Full code nè!

if ( ! function_exists( 'woocommerce_output_product_data_tabs' ) ) {
   function woocommerce_output_product_data_tabs() {
      wc_get_template( 'single-product/tabs/tabs.php' );
   }
}
function woocommerce_output_product_data_tabs() {
   $product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
   if ( empty( $product_tabs ) ) return;
   echo '<div class="woocommerce-tabs wc-tabs-wrapper">';
   foreach ( $product_tabs as $key => $product_tab ) {
      ?>
         <div id="tab-<?php echo esc_attr( $key ); ?>">
            <?php
            if ( isset( $product_tab['callback'] ) ) {
               call_user_func( $product_tab['callback'], $key, $product_tab );
            }
            ?>
         </div>
      <?php         
   }
   echo '</div>';
}

Thành quả nè

Tách product tabs thành các section riêng biệt
Tách product tabs thành các section riêng biệt

Chúc A/C thành công! 😀

5/5 - (100 bình chọn)
Bài viết liên quan