Bạn cần thêm mã vào tệp chủ đề con của mình hoặc thông qua một plugin cho phép thêm các chức năng tùy chỉnh, chẳng hạn như plugin Đoạn mã. Vui lòng không thêm mã tùy chỉnh trực tiếp vào tệp chủ đề mẹ của bạn vì mã này sẽ bị xóa hoàn toàn khi bạn cập nhật chủ đề.functions.php
functions.php
Tắt tất cả các bảng định kiểu
WooCommerce xếp hàng 3 bảng định kiểu theo mặc định. Bạn có thể vô hiệu hóa tất cả chúng bằng đoạn mã sau:
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
Đây là quy trình được khuyến nghị nếu bạn đang xây dựng một chủ đề tùy chỉnh. Việc xóa biểu định kiểu WooCommerce mặc định và đặt biểu định kiểu của riêng bạn sẽ bảo vệ bạn trong các bản cập nhật cốt lõi của WooCommerce.
Tắt các bảng định kiểu cụ thể
Nếu bạn muốn vô hiệu hóa các biểu định kiểu cụ thể (tức là nếu bạn không muốn bao gồm biểu định kiểu cầm tay), bạn có thể sử dụng các cách sau:
/**
* Set WooCommerce image dimensions upon theme activation
*/
// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
// Or just remove them all in one line
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
Sau đó, sắp xếp bảng định kiểu của riêng bạn như sau:
/**
* Enqueue your own stylesheet
*/
function wp_enqueue_woocommerce_style(){
wp_register_style( 'mytheme-woocommerce', get_template_directory_uri() . '/css/woocommerce.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'mytheme-woocommerce' );
}
}
add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' );