• linahammad

    (@linahammad)


    Hi, I am new WordPress and wooCommerce developer.I’m trying to create a custom payment method. But I have a problem, how can I make a redirect to a page in the same plugin.
    To clarify more; inside the function process_payment($order_id) I prepare the request’s parameter and I want to send them to form has an input hidden files in order to submit the form automatically using POST method.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Hmmm, I’m not sure of the context from where you are redirecting. Since you need to override the process_payment() method of the abstract payment gateway class, you can do whatever you need to do. As with any redirect, to do so with wp_redirect(), it must be done prior to any output. If you need to do so after output you need to do it with javascript.

    There is also the question of where to redirect. Do not hardcode this. The permalink ought to be stored somewhere in the DB. WC stores permalinks of certain key pages. If where you’re going is not one of these, you may need to store the permalink yourself when the page is created.

    You said you want to “redirect to a page in the same plugin”. Is this your plugin you are referring to? If so, good. Otherwise, I would deduce you are altering someone else’s plugin, a gateway or WC itself. That would not be good. You will lose your changes when the plugin is updated.

    Thread Starter linahammad

    (@linahammad)

    Hi bcworkz, Thanks for your answer.
    I made all changes on my own plugin, Insides the override process_payment() I want to redirect to another page, is that applicable? or how can I retrieve specific URL to make the redirect on?

    Moderator bcworkz

    (@bcworkz)

    I don’t know if process_payment() is the correct place to redirect or not. I’m not familiar with payment gateways, sorry. You could simply try a PHP redirect and see if it works. You will either be redirected or you will get a headers already sent error. If you get an error, it’s the wrong place 🙂 You would then need to use JavaScript to redirect.

    How you retrieve a target URL depends on where and how it’s stored. For example, the shop page is saved in options as “woocommerce_shop_page_id”. After you get this option, use the ID with get_the_permalink() to get the URL.

    If you need more specific details about the internal workings of WooCommerce, I suggest you ask in the dedicated support forum. I can only help you with general coding questions.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Redirect to page in the plugin’ is closed to new replies.