Jump to content

Custom customer fields do not work when ordering


krypton-media

Recommended Posts

Hello,
until the update to the current version 8.1.3, the query of the user-defined customer fields also worked for me in the order overview. Although these are marked as mandatory, they are now no longer queried. Only the terms and conditions are always queried by default Is this error known and how can it be solved?

Best regards

Christian

2021-03-06 23_25_44-Window.png

2021-03-06 23_25_02-Window.png

Link to comment
Share on other sites

I have now tried to create a hook to extend the query, e.g. when registering a customer. However, I do not know how to act on the missing entries.
Currently I just write something in $errors but that doesn't work so that it queries the fields additionally.

clientregister.tpl

						<div class="row">
							<div class="col-sm-1" style="text-align:right">
								<input type="checkbox" name="accepttos" id="accepttos" />
							</div>
							<div class="col-sm-11" style="text-align:left">
								{$LANG.ordertosagreement}
								&nbsp;
								<strong><a href="{$tosurl}" target="_blank">{$LANG.ordertos}</a></strong>
							</div>
						</div>
						<div class="row">
							<div class="col-sm-1" style="text-align:right">
								<input type="checkbox" name="widerruf" id="widerruf" />
							</div>
							<div class="col-sm-11" style="text-align:left">
								{$LANG.ordercancellationpolicyagreement}
								&nbsp;
								<strong><a href="{$WEB_ROOT}cancellationpolicy.php" target="_blank">{$LANG.ordercancellationpolicy}</a></strong>
							</div>
						</div>
						<div class="row">
							<div class="col-sm-1" style="text-align:right">
								<input type="checkbox" name="datenschutz" id="datenschutz" />
							</div>
							<div class="col-sm-11" style="text-align:left">
								{$LANG.orderprivacypolicyagreement}
								&nbsp;
								<strong><a href="{$WEB_ROOT}privacypolicy.php" target="_blank">{$LANG.orderprivacypolicy}</a></strong>
							</div>
						</div>

ClientRegister.php ( includes/hooks/)

<?php
add_hook('ClientAreaRegister', 1, function($vars) {
    global $_LANG;
	
	$errors = array();

	 if ( $_REQUEST['widerruf'] != true ) {
	 $errors[] = $_LANG['ordercancellationpolicy'];


	 }
	 if ( $_REQUEST['datenschutz'] != true ) {
	 $errors[] = $_LANG['orderprivacypolicy'];


	 }

	return $errors;
});

 

Link to comment
Share on other sites

On 06/03/2021 at 22:31, krypton-media said:

Is this error known and how can it be solved?

I can't recall anyone else mentioning it.

one thing that I am confused about is whether you are using Client Custom Fields for this as the second screenshot implies ? if so, required fields are needing to be completed when I test this locally...

the point being that if these were customfields, then WHMCS should take care of checking that they're required.... if that's the case, what happens when you try this on an unmodified Six template (i'm assuming you're using a custom version of Six) ?

Link to comment
Share on other sites

Quote

if so, required fields are needing to be completed when I test this locally...

this is how it should be, but it doesn't work

Quote

what happens when you try this on an unmodified Six template (i'm assuming you're using a custom version of Six) 

I will try it and yes I have a modified version.

Link to comment
Share on other sites

Hello,

I have now tried this again with the standard template six. I created two new custom fields and made them mandatory during the order process.
However, as can be seen in the error message, only the general terms and conditions are requested. It is enough if I accept them. The other two fields do not have to be clicked.

With kind regards
Christian

2021-03-11 19_59_49-WHMCS - Benutzerdefinierte Kundenfelder und 1 weitere Seite - Persönlich – Micro.png

2021-03-11 19_59_14-Mein Warenkorb - krypton-media und 2 weitere Seiten - Persönlich – Microsoft​ Ed.png

Link to comment
Share on other sites

  • 2 weeks later...

Hi Christian,

On 11/03/2021 at 19:03, krypton-media said:

I have now tried this again with the standard template six. I created two new custom fields and made them mandatory during the order process.
However, as can be seen in the error message, only the general terms and conditions are requested. It is enough if I accept them. The other two fields do not have to be clicked.

if setup and used correctly, the page requires them if a user isn't yet registered/logged in...

E1AWDnb.pngzUtV2XV.png

if the user is logged in, then I don't think any custom fields are validated or even the TOS field... I think that's intended behaviour - though I would dispute that these are really custom fields in the way you're using them at checkout... if that's the case, their values won't be saved to the database.

On 12/03/2021 at 13:43, krypton-media said:

Is there perhaps a hook with which you can include additional fields that must be clicked? This function is mandatory in Germany, otherwise you can be legally prosecuted.

assuming the above code you're using is still in the template, e.g you are hardcoding checkboxes and not using custom fields in the true sense...

<?php

# Validate Checkbox Fields @ Checkout Hook
# Written by brian!

use App;

add_hook('ShoppingCartValidateCheckout', 1, function ($vars) {

	$widerruf = App::getFromRequest('widerruf');
	$datenschutz = App::getFromRequest('datenschutz');
	if (!$widerruf && !$datenschutz) {
		return ['You must confirm you agree to the Cancellation Policy','You must confirm you agree to the Data Protection Policy'];
	}
	elseif (!$widerruf) {
		return 'You must confirm you agree to the Cancellation Policy';
	}
	elseif (!$datenschutz) {
		return 'You must confirm you agree to the Data Protection Policy';
	}
});

you probably should be returning language strings instead of the quote English/German errors, but I assume you know how to do that (once you've written the appropriate language strings for each error in all languages used)....

return Lang::trans('ordererroraccepttos');

if you were *really* using custom fields at checkout for this, then the code should still work - you would just have to adjust the getfromrequest values to the names of the fields.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated