2

I want to change the text of the "completion message" that is shown when an order is paid for successfully. I also want to translate this message.

By default, the completion message text is:

Your order number is 1. 
You can view your order on your account page when logged in. 

I'm using Commerce 2 with Drupal 8.4.1.

By default, at /admin/commerce/config/checkout-flows/manage/default, the checkout flow looks like this:

commerce_default_checkout_flow

There is no option to edit the completion message. Also, there is a translate link at the top of the page, but this translate link only lets me translate the name of the checkout flow, not the completion message.

So how do I edit/translate the completion message?

6

Template approach (recommended)

As revealed in the comment by @bojanz, you can just make a copy of the template file in your theme:

commerce/modules/checkout/templates/commerce-checkout-completion-message.html.twig

Custom checkout pane approach

There is documentation for this.

You can create your own custom checkout pane, which can be done with drupal console or by hand.

/MYMODULE/src/Plugin/Commerce/CheckoutPane

<?php

namespace Drupal\my_checkout_pane\Plugin\Commerce\CheckoutPane;

use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * @CommerceCheckoutPane(
 *  id = "custom_completion_message",
 *  label = @Translation("Custom completion message"),
 *  admin_label = @Translation("Custom completion message"),
 * )
 */
class CustomCompletionMessage extends CheckoutPaneBase implements CheckoutPaneInterface {

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $pane_form['message'] = [
      '#markup' => $this->t('This is a custom completion message.'),
    ];
    return $pane_form;
  }

}
| improve this answer | |
  • 1
    You don't need to create a custom checkout pane. The entire completion message is a Twig template that you can override: github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/… – Bojan Zivanovic Nov 5 '17 at 16:09
  • @BojanZivanovic Thanks, added to the answer so that people won't be guided to do something extra complicated. – Patrick Kenny Nov 6 '17 at 11:42
  • @PatrickKenny I appreciate your answer, and also the custom checkout pane information. I'm going to try this. I would really love to see a detailed tutorial on implementing a custom commerce experience, including your custom module. I don't think the Drupal Commerce docs are detailed enough. – Jav Apr 5 at 16:28
  • Thanks Bojan, this worked perfectly. – hockey2112 Apr 16 at 23:08
  • 1
    This is helpful, but I'm wondering why content is hard-coded in a template file. Could the content be sourced from the database and be configurable like it is elsewhere? – imclean May 13 at 1:47

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.