Custom Thank you page
Bricks allows you to create a custom Thank you template via Templates. It results in thank you page that will be under URL: /checkout/order-received/ where you can change the order-received slug in Woocommerce settings.
Bricks Boilerplate uses a different approach so the result URL will be only: /order-received/ and you can change this to anything else, e.g. /thank-you/
Setting redirect to new custom page
Add this code to Code snippet plugin:
// Check if WooCommerce is active before adding the action hook
if (class_exists('WooCommerce')) {
/**
* Custom Thank You Page Redirect
*/
add_action('template_redirect', 'bt_custom_redirect_to_custom_thank_you');
function bt_custom_redirect_to_custom_thank_you() {
// Check if we are on the WooCommerce order received (thank you) page
if (!is_wc_endpoint_url('order-received') || empty($_GET['key'])) {
return; // Exit if not on the default "Thank You" page
}
// Get the order ID from the order key in the URL
$order_id = wc_get_order_id_by_order_key($_GET['key']);
if (!$order_id) {
return; // Exit if order ID is not found
}
// Construct the URL of your custom "Thank You" page and append the order ID as a query parameter
$custom_thankyou_page_url = add_query_arg(
array(
'order_id' => $order_id,
'order_key' => $_GET['key'],
),
site_url('thank-you') // Ensure the URL matches your custom page slug
);
// Perform the redirect to the custom "Thank You" page
wp_safe_redirect($custom_thankyou_page_url);
exit;
}
}In the part:
Make sure to change thank-you with the actual slug of your custom thank you page.
This snippet will pass order ID and key to our new URL when new order is placed.
Designing with Bricks
Design your layout with Bricks builder and retrieve dynamic data via codeblock.
Product table:
Order summary
Order billing and shipping details:
Failed orders
Sometimes, customer can fail the payment so the order will get status "failed". We need to display a different content for this scenario.
First, we need a snippet to return order status (add to Code snippet plugin):
Now you can use dynamic tag {echo:bt_custom_check_order_status} to apply condition to show/hide elements based on order status.
true = everything except failed
false = failed
You can extend the code to check more statusses and show more options based on that.

Last updated