Tìm theo từ khóa

Các loại trang (Conditional Tags) được định nghĩa trong woocommerce



Định nghĩa trang (Conditional Tags) là gì?

Conditional Tags thực ra là các hàm điều kiện trả về kiểu của trang hiện hành, ví dụ như bạn đang ở trang sản phẩm thì Conditional Tags sẽ báo cho bạn biết trang hiện tại là sản phẩm.

WooCommerce page

is_woocommerce() :  Kiểm tra xem nếu trang hiện tại đang dùng trang mẫu của woocommerce không? (trang Cart và Checkout là các trang cơ bản với shortcoe không bao gồm trong này)

 

Main shop page

is_shop() : True khi trang hiện hành là trang danh mục sản phẩm (shop)

Product category page

  • is_product_category() : True khi trang hiện tại là trang danh mục sản phẩm
  • is_product_category( ‘shirts’ ):  True khi trang hiện tại là danh mục sản phẩm ‘shirts’
  • is_product_category( array( ‘shirts’, ‘games’ ) ): True khi trang hiện tại là danh mục ‘shirts’ hoặc ‘games’

Product tag page

  • is_product_tag() : True nếu trang là danh mục tag
  • is_product_tag( ‘shirts’ ) : True nếu danh mcụ tag ‘shirts’
  • is_product_tag( array( ‘shirts’, ‘games’ ) ) : True nếu danh mục tag là ‘shirts’ hoặc ‘games’

Single product page

  • is_product() : True nếu là trang sản phẩm

Cart page

  • is_cart() : True nếu là trang giỏ hàng

Checkout page

  • is_checkout() : True nếu là trang thanh toán

Customer account pages

  • is_account_page() : True nếu là trang tài khoản

Endpoint

  • is_wc_endpoint_url() : Returns true when viewing a WooCommerce endpoint
  • is_wc_endpoint_url( ‘order-pay’ ) : When the endpoint page for order pay is being displayed.
  • is_wc_endpoint_url( ‘order-received’ ) : When the endpoint page for order received is being displayed.
  • is_wc_endpoint_url( ‘view-order’ ) : When the endpoint page for view order is being displayed.
  • is_wc_endpoint_url( ‘edit-account’ ) : When the endpoint page for edit account is being displayed.
  • is_wc_endpoint_url( ‘edit-address’ ) : When the endpoint page for edit address is being displayed.
  • is_wc_endpoint_url( ‘lost-password’ ) : When the endpoint page for lost password is being displayed.
  • is_wc_endpoint_url( ‘customer-logout’ ) : When the endpoint page for customer logout  is being displayed.
  • is_wc_endpoint_url( ‘add-payment-method’ ) : When the endpoint page for add payment method is being displayed.

Ajax request

  • is_ajax() : True nếu trang load bằng ajax

Ví dụ

Bên dưới là code ví dụ sử dụng các hàm trên (trong function.php)

 

5/5 - (1 bình chọn)
0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest
0 Góp ý
Phản hồi nội tuyến
Xem tất cả bình luận
0
Rất thích suy nghĩ của bạn, hãy bình luận.x