Skip to content

Instantly share code, notes, and snippets.

@woogist
Created January 21, 2015 15:47
Show Gist options
  • Save woogist/0d7c507c66a46a714367 to your computer and use it in GitHub Desktop.
Save woogist/0d7c507c66a46a714367 to your computer and use it in GitHub Desktop.
Filters the page content adding the Thank you page contents
add_filter( 'the_content', 'wc_custom_thankyou' );
function wc_custom_thankyou( $content ) {
// Check if is the correct page
if ( ! is_page( {PAGE_ID} ) ) {
return $content;
}
// check if the order ID exists
if ( ! isset( $_GET['order'] ) ) {
return $content;
}
// intval() ensures that we use an integer value for the order ID
$order = wc_get_order( intval( $_GET['order'] ) );
ob_start();
// Check that the order is valid
if ( ! $order ) {
// The order can't be returned by WooCommerce - Just say thank you
?><p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p><?php
} else {
if ( $order->has_status( 'failed' ) ) {
// Order failed - Print error messages and ask to pay again
/**
* @hooked wc_custom_thankyou_failed - 10
*/
do_action( 'wc_custom_thankyou_failed', $order );
} else {
// The order is successfull - print the complete order review
/**
* @hooked wc_custom_thankyou_header - 10
* @hooked wc_custom_thankyou_table - 20
* @hooked wc_custom_thankyou_customer_details - 30
*/
do_action( 'wc_custom_thankyou_successful', $order );
}
}
$content .= ob_get_contents();
ob_end_clean();
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment