0

I wrote a small module to display an "agree-to-the-terms"-checkbox in Drupal Commerce checkout pane, following the documentation HERE and tweaked it to my needs.

My PHP looks like this:

<?php

namespace Drupal\checkout_terms\Plugin\Commerce\CheckoutPane;

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

/**
 * AGB-Zustimmung für den Checkout.
 *
 * @CommerceCheckoutPane(
 *   id = "checkout_terms_agb_zustimmung",
 *   label = @Translation("AGB Zustimmung"),
 *   display_label = @Translation("AGB Zustimmung"),
 *   default_step = "_review",
 *   wrapper_element = "fieldset",
 * )
 */

class CheckoutTermsAccept extends CheckoutPaneBase {

  /**
   * {@inheritdoc}
   */
    public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
      $pane_form['accept_terms'] = [
        '#type' => 'checkbox',
        '#title' => 'Ich stimme den allgemeinen Geschäftsbedingungen zu',
        '#default_value' => 0,
        '#required' => TRUE
      ];
      return $pane_form;
    }
    
}

This works perfect for custom multi-step-checkouts. The checkbox is unchecked by default, but the checkout can't be finished without checking the box.

But when I choose the Commerce Paypal module to check out, I just ignores my checkbox and does the checkout anyway.

As I am pretty new to Drupal, I would be glad if someone could give me any advise on how to go from here. Is there any possibility to hook into the Paypal module from here and deactivate it as long as the checkbox is still unchecked? Or should I just do it in Javascript on that page?

Thank you very much in advance!

2
  • 2
    You could move this checkbox to the step before review and make it mandatory to be checked in order to continue to the, last, review step. OR hiding with JS the PayPal buttons until user checks that box sounds alright to me. – No Sssweat Jan 6 at 1:02
  • Thanks for the answer. Yes, I'll think of moving the checkbox one step back. – арно нюм Jan 6 at 14:29

Your Answer

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

Browse other questions tagged or ask your own question.