Chào các bạn, đã lâu mình không viết blog. Giờ mình hướng dẫn các bạn custom lại các widget mặc định của Woocommerce hoặc widget mặc định của WordPress cũng được.

Trước tiên thêm dòng sau vào file funciton.php của theme. Ở đây mình custom lại widget hiển thị sản phẩm (Product)

include get_template_directory() . '/widget/widget-custom-product.php';

add_action("widgets_init", "load_custom_widgets");
function load_custom_widgets() {
unregister_widget("WC_Widget_Products");
register_widget("WC_Widget_Custom_Products");
}

-Sau đó,tạo folder widget hoặc thư mục gì cũng được tùy bạn, nằm ngang hàng với file funciton.php nha bạn.

-Copy file ở path /plugins/woocommerce/includes/widgets/class-wc-widget-products.php vào folder mới vừa tạo

-Rename file vừa copy thành widget-custom-product.php. Tiến hành custom widget ở file đó theo ý bạn.

-Mở file widget-custom-product.php lên, edit tên class : ‘WC_Widget_Products’ thành ‘WC_Widget_Custom_Products’

* Đối với widget mặc định WordPress, bạn vào path sau để copy file /wp-includes/widgets

0 CommentsClose Comments

Leave a comment

Đăng ký – Tôi sẽ giúp bạn xây dựng từ A-Z!

Muốn có website bán hàng, giới thiệu, landing page?

NGUYỄN PHÚC GIA LINH © Copyright from 2018. All Rights Reserved. Powered by WordPress

    Gia Linh sẽ liên hệ lại trong vòng 2 giờ làm việc