3

How to redirect the user to a product page (node) after payment is made?

I'm using the Commerce Express Checkout module. That's why in the Shopping cart can be just one product.

0

One option is to use hook_menu_alter in a custom module to override your current destination page with a redirect.

<?php

function mymodule_menu_alter(&$items) { 

    $items['current/checkout/path'] = array(
        'page callback' => 'drupal_goto',
        'page arguments' => array('new/checkout/path'),
        'access callback' => TRUE,
      );

}

Update:

To use the above code, you'll have to create a module.

1) Create a directory to be used for this module, e.g. /sites/all/modules/MYMODULE

2) Create MYMODULE.info, e.g. /sites/all/modules/MYMODULE/MYMODULE.info. Paste the following into the file.

name = MYMODULE
description = "Module description."
package = Custom
core = 7.x

3) Create MYMODULE.module, e.g. /sites/all/modules/MYMODULE/MYMODULE.module. Paste the following into the file.

<?php

function MYMODULE_menu_alter(&$items) { 

    $items['current/checkout/path'] = array(
        'page callback' => 'drupal_goto',
        'page arguments' => array('node/123'),
        'access callback' => TRUE,
      );

}

4) Replace all instances of MYMODULE with your desired module name. Replace current/checkout/path with the current path of the checkout. Replace node/123 with the new checkout path. Lastly, enable your new module.

This will tell Drupal to replace the current checkout page with a redirection to the new one.

  • Thanks a lot for an answer! I do not understand how to write the url of node page to redirect. Should I use token? My product page is /goods/NID – Eri Dec 2 '14 at 11:16
  • You'll need to use the actual URL, not its alias, e.g. 'page arguments' => array('node/NID'),. – timofey.com Dec 3 '14 at 0:55
  • I have just one more question. How to tell Drupal 7 which NID to use? – Eri Dec 3 '14 at 18:39
  • Not sure if I understand. If you're asking how to implement the above, I've updated the question for you. Let me know if that answers your question. – timofey.com Dec 3 '14 at 20:46
  • When I use a code: 'page arguments' => array('node/NID'), should the user be redirected to the node display of that product after payment? It doesn't work for me. Each time the NID is different. I'm doing something not correct. – Eri Dec 3 '14 at 22:33
0

Another option is to add a rule, based on the event 'checkout complete' / 'first paid in full'.

  • How would the rules conditions / actions look like? – Pierre.Vriens Jun 21 '17 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.