Chào mừng bạn đến với hướng dẫn đầy đủ về tùy chỉnh trang cảm ơn WooC Commerce. Nếu bạn nghĩ rằng tôi quên đề cập đến điều gì đó trong đó, chỉ cần để lại nhận xét bên dưới
URL trang cảm ơn
Tôi cho rằng đó là điều đầu tiên tôi muốn nói đến trong hướng dẫn này. Tôi muốn chỉ cho bạn cách thay đổi URL trang cảm ơn mặc định và cách lấy nó cho một đơn đặt hàng cụ thể
Làm cách nào để thay đổi URL trang nhận được đơn đặt hàng?
Trước khi tôi chỉ cho bạn cách làm điều đó, tôi muốn nhắc bạn rằng theo mặc định, URL này trông giống như
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
1, trong đó 123 là ID đơn hàng và XYZ là khóa đơn hàng. Và chúng ta chỉ có thể thay đổi hai điều ở đây- Slug
0 là sên của trang thanh toán trong cửa hàng WooC Commerce của bạn, vì vậy bạn chỉ cần truy cập Trang và thay đổi nó giống như bạn thay đổi nó cho bất kỳ trang WordPress nào/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
- Sên
1, là điểm cuối thanh toán, để thay đổi nó, vui lòng chuyển đến cài đặt WooC Commerce, sau đó chuyển đến tab Nâng cao/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
Hãy đổi nó thành
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
2 chẳng hạn/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
3Nhưng nếu bạn muốn thay đổi URL của trang cảm ơn thành một cái gì đó như
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
4? Nhận url trang cảm ơn
Tôi đã có một hướng dẫn trên trang web của mình, nơi tôi trình bày cách lấy URL trang WooC Commerce theo cách lập trình, như trang cửa hàng, giỏ hàng hoặc trang thanh toán, nhưng không có đề cập đến URL trang nhận đơn đặt hàng WooC Commerce. Vì vậy, hãy đi sâu vào nó ngay bây giờ
Khi chúng tôi xem xét URL của trang cảm ơn mặc định, là
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
1, chúng tôi đã nhận ra rằng URL này chứa ID đơn đặt hàng. Đối với chúng tôi, điều đó có nghĩa là nếu chúng tôi muốn tạo URL cho trang cảm ơn theo chương trình, chúng tôi phải biết ID của đơn đặt hàng$order = wc_get_order[ $order_id ];
echo $order->get_checkout_order_received_url[];
Cảm ơn móc trang
Điều tiếp theo tôi muốn nói về – Hành động WooC Commerce và móc bộ lọc được hiển thị trên trang nhận đơn đặt hàng. Có rất nhiều thứ bạn có thể làm với móc, hãy xem chi tiết một số trong số chúng
Chuyển hướng đến trang Cảm ơn tùy chỉnh
Có thể có nhiều lý do khác nhau mà bạn có thể cần một trang nhận đơn đặt hàng tùy chỉnh trên cửa hàng WooC Commerce của mình – có thể bạn chỉ muốn URL của trang giống như
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
4 hoặc thậm chí có thể bạn muốn các trang cảm ơn khác nhau cho các phương thức thanh toán khác nhauBất kể bạn có lý do gì, giải pháp sẽ giống nhau – để thực hiện chuyển hướng trên hook hành động
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
8. Vâng, tôi biết rằng /**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
8 không chính xác là một hook trang cảm ơn, nó được trình bày trên bất kỳ trang web WordPress nào, nhưng tôi nghĩ rằng tôi nên đề cập đến nó ở đây, bởi vì nó cực kỳ hữu ích/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
Bạn cũng có thể sử dụng một số điều kiện ở đây. Tôi đã đề cập đến hướng dẫn của mình về cách tạo chuyển hướng đến một trang khác tùy thuộc vào phương thức thanh toán được sử dụng. Chuyển hướng có thể áp dụng cho các sản phẩm đã mua
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
1- Xin lưu ý rằng các mặt hàng và sản phẩm đặt hàng là những thứ khác nhau,
- Sự khác biệt giữa
10 và/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
11 là cái đầu tiên cho phép chuyển hướng đến bất kỳ URL bên ngoài nào và cái thứ hai – chỉ đến miền trang web của bạn, mặc dù bạn có thể thay đổi điều đó bằng hook/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
- Mã có thể được chèn vào tệp
12 chủ đề hiện tại của bạn/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
Thay đổi tiêu đề trang Cảm ơn
Bây giờ, hãy thực hiện một số thay đổi đối với nội dung trang Cảm ơn. Và chúng ta sẽ bắt đầu với tiêu đề. Nhân tiện, bạn chắc chắn có thể tìm thấy một hướng dẫn trên internet, nơi bạn nên sử dụng móc nối WordPress
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
13. Tôi không chắc đó là một ý kiến hay trong ngữ cảnh của chúng ta. Có tốt hơn không khi sử dụng hook WooC Commerce được tạo riêng cho mục đích này? Và tôi cũng đang nghĩ tại sao không cho bạn xem móc lọc
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
15 cho phép thay đổi phụ đề trang cảm ơn/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
14 cho phép thay đổi văn bản “Đã nhận đơn đặt hàng”, móc thứ hai /**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
15 – “Xin cảm ơn. Đơn đặt hàng của bạn đã được nhận; Đã nhận được đơn đặt hàng của bạn. ”Hãy làm điều đó 💪 Tất cả mã từ hướng dẫn này bạn có thể chèn vào chủ đề hiện tại của mình
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
12 nhưng tôi khuyên bạn nên sử dụng chủ đề con hoặc plugin tùy chỉnh/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
1Bạn có thấy [Dòng 3] rằng hook này chỉ có một đối số –
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
19, nhưng còn chi tiết đơn hàng thì sao? Móc thứ hai
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
15 giúp dễ dàng hơn vì đối tượng /**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
14 có sẵn dưới dạng đối số hàm/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
8và đây là kết quả
Thêm nội dung hoặc mã ngắn vào trang Cảm ơn
Có ba móc có thể giúp bạn với điều đó
15 – chúng tôi đã xem nhanh ở trên,/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
16 – chạy ngay sau chi tiết đơn đặt hàng,/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
17 – giống như cái trước, nhưng có thể được kết nối với sên phương thức thanh toán/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
Tôi sẽ sử dụng móc
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
16 để hiển thị một số sản phẩm mới nhất ngay bên dưới chi tiết đơn hàng/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
3Mẫu trang cảm ơn
Trong tất cả các ví dụ bạn đã thấy trong hướng dẫn này, tôi đã sử dụng móc. Móc có thể được áp dụng rất dễ dàng – chỉ cần chèn nó vào
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
12 / chủ đề con của /**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
12 / plugin tùy chỉnhNhưng không phải lúc nào móc cũng cho phép chúng tôi thực hiện các tùy chỉnh mà chúng tôi cần. Nếu bạn mở thư mục plugin WooC Commerce của mình, bạn sẽ tìm thấy thư mục
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
81 ở đó. Nhưng về mặt hướng dẫn này, chúng tôi quan tâm đến các tệp sau
82/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
83/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
84/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
85/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
Tất nhiên, bạn không phải thay đổi nội dung của các tệp này trực tiếp trong thư mục plugin WooC Commerce. Tất cả những gì bạn cần làm là chọn tệp bạn muốn thay đổi và sao chép tệp đó trong thư mục
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
86 của chủ đề hiện tại của bạnFromTo____282____288Sau đó, bạn có thể thực hiện các thay đổi trong tệp này. Nhưng hãy cẩn thận – tất nhiên là móc là cách an toàn hơn để thực hiện các thay đổi. Chỉ cần tưởng tượng bạn đã thay đổi rất nhiều tệp mẫu WooC Commerce và… phiên bản WooC Commerce mới đã xuất hiện. Bạn sẽ không mất các thay đổi của mình nhưng có thể mã của bạn sẽ không hoạt động với phiên bản WooC Commerce mới đó như mong đợi, vì vậy bạn sẽ phải kiểm tra mọi mẫu đã thay đổi
Thu thập thêm thông tin chi tiết về khách hàng trên trang Cảm ơn của bạn
1. Thêm biểu mẫu HTML
Vì vậy, chúng ta cần một hình thức, phải không?
Ok, vì vậy hình thức của tôi sẽ cực kỳ đơn giản
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
6Một số lưu ý
- Dòng 1 – Nếu bạn đặt mức độ ưu tiên hook thành
31 trở xuống, biểu mẫu sẽ được hiển thị trước phần Chi tiết đơn hàng, nếu/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
32 trở lên – sau phần địa chỉ/** * @snippet Custom Thank You Page Redirect * @author Misha Rudrastyh * @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page */ add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ]; function rudr_redirect_custom_thank_you[]{ // do nothing if we are not on the order received page if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] { return; } wp_safe_redirect[ site_url[ 'thank-you' ] ]; }
- Bạn không thấy nút gửi – Tôi không quên nó, chúng tôi sẽ gửi biểu mẫu này bằng AJAX
- Dòng 11 – Đừng quên nonce, chúng tôi cần nó vì lý do bảo mật
2. Gửi yêu cầu AJAX
Bạn có thể thêm mã vào một. js, nhưng trong trường hợp đó, đừng quên truyền chính xác tham số url
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
9Vì vậy, nếu bạn đã làm đúng mọi thứ, thì đây là những gì bạn nên có
3. Xử lý yêu cầu AJAX
Bây giờ điều duy nhất còn lại là xử lý biểu mẫu. Nhân tiện, bạn có thể đọc thêm về các yêu cầu AJAX trong danh mục này
/**
* @snippet Custom Thank You Page Redirect
* @author Misha Rudrastyh
* @url //rudrastyh.com/woocommerce/thank-you-page.html#custom-thank-you-page
*/
add_action[ 'template_redirect', 'rudr_redirect_custom_thank_you' ];
function rudr_redirect_custom_thank_you[]{
// do nothing if we are not on the order received page
if[ ! is_wc_endpoint_url[ 'order-received' ] || empty[ $_GET[ 'key' ] ] ] {
return;
}
wp_safe_redirect[ site_url[ 'thank-you' ] ];
}
0Chuyển đến trang chỉnh sửa đơn hàng và tìm metabox Ghi chú đơn hàng. Tất nhiên bạn cũng có thể thay đổi chi tiết đơn hàng với mẫu đó
# WooC Commerce, quản trị viên-ajax. php
Misha Rudrastyh
Chào các bạn và chào mừng đến với trang web của tôi. Trong hơn 10 năm, tôi đã cố gắng hết sức để chia sẻ miễn phí với bạn một số hướng dẫn và mẹo tuyệt vời về WordPress