简体   繁体   中英

hooking drupal commerce coupon pane

I try to make a small change to Drupal Commerce Coupon pane (add a div to it). I tried to hook this function:

    function commerce_coupon_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
              // Allow to replace pane content with ajax calls.
              $pane_form = array(
                '#prefix' => '<div id="commerce-checkout-coupon-ajax-wrapper">',
                '#suffix' => '</div>',
              );
        (..)
}

To do this I created a function in my module:

function <mymodule>_form_commerce_coupon_pane_alter(&$form, &$form_state, $form_id) {
        $form['#prefix'] = '<div id="collapsable-panel"><p>You have coupon? Add it here.</p>' + $form['#prefix'];
        $form['#suffix'] = $form['#suffix'] + '</div>';
    }

but it do not work. I think that there should be other way to hook checkout pane but I cannot figure out how to do this.

Your intent is correct, however the ID of the form is incorrect. It should be like this function <mymodule>_form_commerce_coupon_pane_checkout_alter .

If it still doesn't work, here's an alternative to try:

function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == "YOU NEED TO DISCOVER THE FORM ID") {
        // Do whatever you want here
    }
}

Don't forget to clear all caches!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM