4
votes

I'm creating a Woocommerce custom Payment Gateway plugin (it basically redirects the user to the payment service page and then the payment service page redirects the user back to an especified URL), everything is working as expected but I can't seem to create a custom thank-you page FROM THE PLUGIN.

What I mean with "from the plugin" is that if someone installs my Payment Gateway plugin they should be able to see the custom thank-you page without any aditional operation like adding a Woocommerce theme or page in WP.

Here is what I'm currently using to handle the default thank-you page:

The redirect URL is given by: $this->get_return_url($order))

The thank you page is hooked with:

add_action('woocommerce_thankyou_'.$this->id, array( $this, 'return_handler' ) );

And here is my function that should handle the thankyou page messages:

public function return_handler() {
  $order_id = get_query_var('order-received');
  global $woocommerce;
  $order = new WC_Order( $order_id );
  //NEXT I JUST CHECK THE ORDER AND SHOW MESSAGES DEPENDING ON THE RESULT
}

EDIT: also if there is another way of returning the user to an URL that will trigger one of my plugins function, that could be a valid option.

1

1 Answers

4
votes

I think the filter you need to target is woocommerce_payment_successful_result which is in the WC_Checkout class.

function so_27024470_paypal_redirect( $return, $order_id ){
    $order = new WC_Order( $order_id );
    if( $order->payment_method == 'your-gateway-id' ){
        $return['redirect'] = 'http://your-redirect.com';
    }
    return $return;
}
add_action( 'woocommerce_payment_successful_result, 'so_27024470_paypal_redirect', 10, 2 );

I haven't tested this, so use at your own risk.