Redirect to checkout after pressing the "Add to Cart" button When a user presses the "add to cart" button on a product page, I want to automatically redirect the user to the checkout page.

Drupal 7 has an issue for doing this programatically and an issue for doing this with the Rules module.

Rules is still in alpha for D8, and I tried to make a rule that acts on after saving a new order, but I'm getting an error when I try to add an action:

Error: Call to a member function getDataType() on null in Drupal\rules\Plugin\RulesAction\EntityCreateDeriver-&gt;getDerivativeDefinitions() (line 99 of modules/contrib/rules/src/Plugin/RulesAction/EntityCreateDeriver.php).


So I want to redirect from add to cart to the checkout page programatically.

But there is no documentation yet.  So if anyone can explain how to do this, I would be much obliged.
you could do something like this:

use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;

function MYMODULE_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  if (strpos($form_id, 'commerce_order_item_add_to_cart_form_commerce_product') !== false) {
    $form['actions']['submit']['#submit'][] = 'MYMODULE_cart_alter_sub';
 }
}
function MYMODULE_cart_alter_sub(&amp;$form, FormStateInterface $form_state) {
  $responce =  new RedirectResponse('/cart');
  $responce-&gt;send();
}