14/9/17

Product data tabs trong woocommerce

Product data tabs trong woocommerce chính là thanh chức năng hiển thị description của product, reviews..
Như thế nào để anh chị tùy biến thanh này, hôm nay tôi sẽ chia sẽ các code để làm việc này
Xóa tab:
add_filter( ‘woocommerce_product_tabs’, ‘woo_remove_product_tabs’, 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs[‘description’] ); // Xóa  tab description
unset( $tabs[‘reviews’] ); // Xóa tab reviews
return $tabs;
}
Thay đổi tên tab:
add_filter( ‘woocommerce_product_tabs’, ‘woo_rename_tabs’, 98 );
function woo_rename_tabs( $tabs ) {
$tabs[‘description’][‘title’] = __( ‘Mô tả’ );
$tabs[‘reviews’][‘title’] = __( ‘Ý kiến khách hàng’ );
return $tabs;
}
Thay đổi thứ tự tab
add_filter( ‘woocommerce_product_tabs’, ‘woo_reorder_tabs’, 98 );
function woo_reorder_tabs( $tabs ) {
$tabs[‘reviews’][‘priority’] = 5; // Tab Reviews ở vị trí đầu tiên thay vì ở vị trí thứ 2
$tabs[‘description’][‘priority’] = 10; // Tab Description ở vị trí 1
return $tabs;
}
Thêm tab vào thanh tab
Điều này thì hữu ích khi ta muốn thêm một tab để hiển thị các image của sản phẩm chẳn hạn
add_filter( ‘woocommerce_product_tabs’, ‘image_product_tab’ );
function image_product_tab( $tabs ) {
//thêm vào tab để chứa image sản phẩm
$tabs[‘image_sp’] = array(
‘title’ => __( ‘Hình ảnh sản phẩm’, ‘woocommerce’ ),
‘priority’ => 50,
‘callback’ => ‘function_lay_image_sp’
);
return $tabs;
}
function function_lay_image_spt() {
// Viết code lấy image của sản phẩm tại đây
}
Chỉ sửa tab hiện có của woocommerce
add_filter( ‘woocommerce_product_tabs’, ‘custom_description_tab’, 98 );
function woo_custom_description_tab( $tabs ) {
$tabs[‘description’][‘callback’] = ‘function_lam_viec_nay’; // hàm để thay đổi cách hiển thị description
return $tabs;
}
function function_lam_viec_nay() {
// viết code làm điều này tại đây
}
Hị vọng sẽ giúp được anh chị qua bài viết Product data tabs trong woocommerce là gì?
Từ khóa tìm kiếm trên google:
-Product data tabs trong woocommerce là gì?
-Thay đổi tabs description trong woocommerce
-Thay đổi tabs review trong woocommerce
-Thêm tabs mới vào thanh tabs woocommerce
Nguồn:fcwordpress.net
Bạn đang đọc bài viết Product data tabs trong woocommerce tại Website: Học Lập Trình

0 nhận xét: