Skip to content

Instantly share code, notes, and snippets.

@woogist
Created February 10, 2015 08:06
Show Gist options
  • Save woogist/57eed17e6cb26626e2fc to your computer and use it in GitHub Desktop.
Save woogist/57eed17e6cb26626e2fc to your computer and use it in GitHub Desktop.
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['key'] ) || ! isset( $_GET['order'] ) ) {
return $content;
}
$order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $_GET['order'] ) );
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
$order = wc_get_order( $order_id );
if ( $order->id != $order_id || $order->order_key != $order_key ) {
return $content;
}
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