Giới thiệu các hook có trong single product page woocommerce

Trong quá trình xây dựng một website bán hàng thì không thể không nhắc đến woocommerce. Đối với ae dev mới tiếp cận woocommerce thì các hook mà nó hỗ trợ sẽ rất quan trọng để ae có thể phát triển thêm các tính năng trên website. Bài viết này mình sẽ giới thiệu các hook có trong single product page woocommerce.

Trước tiên Woocommerce là gì ?

WooCommerce là một plugin thương mại điện tử mã nguồn mở cho WordPress. Nó được sử dụng trên các website thương mại điện tử với quy mô từ nhỏ đến lớn. Ra mắt vào ngày 27 tháng 9 năm 2011, plugin nhanh chóng trở nên phổ biến vì đơn giản để cài đặt, tùy chỉnh và hoàn toàn miễn phí.

Giới thiệu các hook có trong single product page woocommerce

Hook là gì ?

Hooks trong WordPress nói chung và woocommerce nói riêng là những tính năng quan trọng cho phép các nhà phát triển mở rộng chức năng hệ thống  mà không cần phải sửa đổi các file cốt lõi của nó. Điều này giúp việc cập nhật theme hoặc plugin trở nên đơn giản và dễ dàng mà không vi phạm đến các tùy chỉnh thay đổi sau khi cập nhật.

Hình ảnh vị trí các hook đang có trong single product woocommerce

Woocommerce là một plugin tuyệt vời với đầy đủ các chức năng giúp chúng ta tạo một web thương mại, tuy nhiên nếu bạn muốn cấu hình lại các trang của woocommerce cho phù hợp với nhu cầu thì các hàm hook của woocommerce là một công cụ thích hợp để bạn tùy biến.

Giới thiệu các hook có trong single product page woocommerce

Danh sách các hook của single product woocommerce

// Before content
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
add_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
add_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );

// Left column
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );

// Right column
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

// Right column - add to cart
do_action( 'woocommerce_before_add_to_cart_form' );
do_action( 'woocommerce_before_add_to_cart_button' );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

add_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
add_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
add_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
add_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
do_action( 'woocommerce_before_quantity_input_field' );
do_action( 'woocommerce_after_quantity_input_field' );
do_action( 'woocommerce_after_add_to_cart_button' );
do_action( 'woocommerce_after_add_to_cart_form' );

// Right column - meta
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
do_action( 'woocommerce_product_meta_start' );
do_action( 'woocommerce_product_meta_end' );

// Right column - sharing
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
do_action( 'woocommerce_share' );

// Tabs, upsells and related products
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
do_action( 'woocommerce_product_after_tabs' );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

// Reviews
add_action( 'woocommerce_review_before', 'woocommerce_review_display_gravatar', 10 );
add_action( 'woocommerce_review_before_comment_meta', 'woocommerce_review_display_rating', 10 );
add_action( 'woocommerce_review_meta', 'woocommerce_review_display_meta', 10 );
do_action( 'woocommerce_review_before_comment_text', $comment );
add_action( 'woocommerce_review_comment_text', 'woocommerce_review_display_comment_text', 10 );
do_action( 'woocommerce_review_after_comment_text', $comment );

// After content
do_action( 'woocommerce_after_single_product' );
do_action( 'woocommerce_after_main_content' );

Lời kết

Trên đây là các hook có trong single product page của woocommerce, hi vọng bài viết giới thiệu các hook có trong single product page woocommerce của mình sẽ giúp ích phần nào đó cho các bạn có thể dễ dàng tùy biến và phát triển các tính năng trên website một cách nhanh và tốt hơn.

Các bạn có thể tham khảo các bài viết về cách up sản phẩm trong woocommerce ở đây  và ở đây