- ๐ฎ๐ฑIsrael jsacksick
The reason why the submit button label gets changed to "Complete checkout" for free orders is the logic in the payment process pane (PaymentProcessPane::isVisible).
Basically, when the order is free, the payment process pane is marked as not vislble, and therefore the payment step is skipped. When there is no payment step, the next checkout step is "complete".
See the following code in CheckoutFlowBase::getSteps():
return [ 'payment' => [ 'label' => $this->t('Payment'), 'next_label' => $this->t('Pay and complete purchase'), 'has_sidebar' => FALSE, 'hidden' => TRUE, ], 'complete' => [ 'label' => $this->t('Complete'), 'next_label' => $this->t('Complete checkout'), 'has_sidebar' => FALSE, ], ];
Unfortunately, we can't apply the same logic for manual payments. Because the manual payment is created by the payment process pane so the payment step & the payment process pane have to be visible.
The other option could be a
hook_form_alter()
implementation, but it'd be hard to figure out when to actually alter the label as you could have other steps after the review (who knows). So while it may sound trivial, this feature request isn't actually trivial. - ๐ณ๐ฌNigeria chike Nigeria
hook_form_alter()
didn't work I guess for the same reason given by FrankDesign in the comment here, https://drupal.stackexchange.com/questions/308223/drupal-9-commerce-chan...Here is the code I used,
function mymodule_alters_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form_id == "commerce-checkout-flow-multistep-default") { $form['actions']['submit']['#value'] = t('Complete checkout'); } }
This does not work.
- ๐ฎ๐ฑIsrael jsacksick
@chike: Are you saying you can't target a specific checkout step? You should be able to?
- ๐ณ๐ฌNigeria chike Nigeria
I want to target the submit button, should be the last step I guess. What can I adjust in my code to target the button and change the text?
- ๐ฎ๐ฑIsrael jsacksick
This is the hook you need to implement:
```
hook_form_BASE_FORM_ID_alter().
```
Commerce PayPal alters the checkout form like this:
commerce_paypal_form_commerce_checkout_flow_alter()
So if your module name is "mymodule_alters", it should be mymodule_alters_form_commerce_checkout_flow_alter().
You access the checkout step like the following:
if ($form['#step_id'] === 'review') { $form['actions']['next']['#value'] = t('Complete checkout'); }