简体   繁体   中英

How do I make comments in OpenCart Checkout Required?

I would like to make the comments section on the opencart checkout process required.

Everything that I tried either breaks the checkout or the mod doesn't work. I'm running OpenCart version 1.5.6.4.

Since the comment field shows up in both the payment method and the shipping method section, you need to validate it in both. As there are already validate() methods in both controllers all you need to do is check that the field is not empty and return a warning if it is.

The two files are:

catalog/controller/checkout/shipping_method.php
catalog/controller/checkout/payment_method.php

Look toward the end of both files and find the very last occurence of if (!$json) { which is basically the green light to move forward. Immediately before it you can add you validation code. I'd use something like this:

if (!trim($this->request->post['comment'])) {
    $json['error']['warning'] = 'Comment is required';
}

You may also want to consider modifying the respective tpl files ( catalog/view/theme/default/template/checkout/shipping_method.tpl and catalog/view/theme/default/template/checkout/payment_method.tpl ) to indicate to your customer that the field is required. You could change:

<b><?php echo $text_comments; ?></b>

into...

<b><span class="required">*</span> <?php echo $text_comments; ?></b>

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