WoocommerceWordpress

[Woocommerce] Hướng Dẫn Tách Product Tabs thành các section

Bài này hnitmedia mục đích là phân tách nguyên cái product tabs gồm mô tả, đánh giá, …. 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.

Đầ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>';
}

Tổng hợp 2 đoạn code trên bỏ vào file functions.php

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>';
}

Kết quả

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Back to top button