Bài này là bài hướng dẫn tiếp theo của bài [WooCommerce extension] Hướng dẫn Product Documents, trước khi các bạn tìm hiểu về bài này thì các bạn cần xem trước bài:
Xem thêm: [WooCommerce extension] Hướng dẫn Product Documents
1. Thay đổi kiểu hiển thị
Trước khi thay đổi:
Sau khi chép code:
Để được như hình trên các bạn chỉ cần chép code dưới vào cuối đoạn của file style.css (trong theme)
Xem thêm: Những điều cần biết về theme Storefront (Mục 7.1 Cài đặt và kích hoạt Plugin Theme Customisations)
Đây là plugin chỉ có chức năng chép code php, js, css của theme Storefront tránh sửa hoặc thêm code vào trực tiếp theme vì nó sẽ mất sạch khi bạn update phiên bản theme mới sau này.
Code thay đổi kiểu hiển thị
.ui-accordion .ui-accordion-icons {
background: #005dab;
color: #ffffff;
}
2. Cách mở một cửa sổ (Tab) mới khi khách hàng tải về tập tin trong Tài liệu sản phẩm
Bạn chép code dưới vào cuối đoạn của file functions.php (trong theme)
<?php
add_filter( 'wc_product_documents_link_target', 'wc_product_documents_open_link_in_new_window', 10, 4 );
/**
* Opens all product documents links in new window/tabs
*/
function wc_product_documents_open_link_in_new_window( $target, $product, $section, $document ) {
return '_blank';
}
3. Cách ẩn Tài liệu sản phẩm cho đến khi khách hàng đăng nhập
Bạn chép code dưới vào cuối đoạn của file functions.php (trong theme)
<?php
add_filter( 'wc_product_documents_get_sections', 'show_documents_only_for_logged_in_users', 10, 3 );
/**
* Don't return document sections unless there is a logged in user.
*
* @param array $sections array of sections
* @param WC_Product_Documents_Collection $collection the collection object
* @param boolean $include_empty whether to include empty sections in the result
* @return array sections for display
*/
function show_documents_only_for_logged_in_users( $sections, $collection, $include_empty ) {
// this check can be made as specific (by user role, etc) as desired
if ( ! get_current_user_id() ) {
return array();
}
return $sections;
}
4. Cách di chuyển Tài liệu sản phẩm đến bất kỳ vị trí nào trên trang sản phẩm
Để di chuyển Tài liệu sản phẩm đến bất kỳ vị trí nào trên trang sản phẩm bạn cần dùng WooCommerce hooks. Đây là ví dụ di chuyển Tài liệu sản phấm đến vị trí cuối cùng trên trang sản phẩm
// Remove the default documents location and add it to the bottom of the product page remove_action( 'woocommerce_single_product_summary', array( wc_product_documents(), 'render_product_documents' ), 25 ); add_action( 'woocommerce_after_single_product', array( wc_product_documents(), 'render_product_documents' ), 10 );
Như vậy là chúng ta đã kết thúc một bài viết về Các code cần thiết cho WooCommerce Product Documents
The post Các code cần thiết cho WooCommerce Product Documents appeared first on Blog Wordpress.
from WordPress http://ift.tt/2c0l0FQ
via IFTTT
Không có nhận xét nào:
Đăng nhận xét