Jump to content

[Tutorial] [PS 1.7+] Removing account creation options on checkout


Recommended Posts

Version: Prestashop 1.7+
Tutorial last update: 29/05/2019

We have noticed that more and more the question is raised in prestashop forum how you can remove account creation in the checkout page.
We will describe below how and where you can disable / remove these components.
We strongly recommend that you always make a backup of the files that you change.
We also always recommend that you disable code blocks and not remove them. This allows you to later, if desired, to turn everything back

Step 1: Removing the option to create an account on the order page.
File location: YOURSTORE/classes/form/CustomerFormatter.php

1.thumb.png.3bd63ee60df5945e19dd717203bfa6bb.png

Find and disable / remove the code below, to disable use the code tags: /* THE CODE LINES */

        if ($this->ask_for_password) {
            $format['password'] = (new FormField())
                ->setName('password')
                ->setType('password')
                ->setLabel(
                    $this->translator->trans(
                        'Password', [], 'Shop.Forms.Labels'
                    )
                )
                ->setRequired($this->password_is_required)
            ;
        }

In the same file (CustomerFormatter.php) you can find and disable following fields:
Social field ($genders), firstname, lastname, email, birthday, optin

Step 2: Removing the tab's "Order as a guest" and / or "Sign in".
File location: YOURSTORE/themes/YOURTHEME/templates/checkout/_partials/steps/ personal-information.tpl”

2.thumb.png.3a7ebe11228b2893525053655c3f8bc9.png

Find and disable / remove the code below, to disable use the code tags: {* THE CODE LINES *}

    <ul class="nav nav-inline my-2" role="tablist">
      <li class="nav-item">
        <a
          class="nav-link {if !$show_login_form}active{/if}"
          data-toggle="tab"
          href="#checkout-guest-form"
          role="tab"
          aria-controls="checkout-guest-form"
          {if !$show_login_form} aria-selected="true"{/if}
          >
          {if $guest_allowed}
            {l s='Order as a guest' d='Shop.Theme.Checkout'}
          {else}
            {l s='Create an account' d='Shop.Theme.Customeraccount'}
          {/if}
        </a>
      </li>

      <li class="nav-item">
        <span href="nav-separator"> | </span>
      </li>

      <li class="nav-item">
        <a
          class="nav-link {if $show_login_form}active{/if}"
          data-link-action="show-login-form"
          data-toggle="tab"
          href="#checkout-login-form"
          role="tab"
          aria-controls="checkout-login-form"
          {if $show_login_form} aria-selected="true"{/if}
        >
          {l s='Sign in' d='Shop.Theme.Actions'}
        </a>
      </li>
    </ul>

Step 3: Removing the block "Save time on your next order, sign up now".
File location: YOURSTORE/themes/YOURTHEME/templates/templates/checkout/order-confirmation.tpl”

3.thumb.png.2288308b96eb6ab58e1d13802cccdf3b.png

Find and disable / remove the code below, to disable use the code tags: {* THE CODE LINES *}

  {block name='customer_registration_form'}
    {if $customer.is_guest}
      <div id="registration-form" class="card">
        <div class="card-block">
          <h4 class="h4">{l s='Save time on your next order, sign up now' d='Shop.Theme.Checkout'}</h4>
          {render file='customer/_partials/customer-form.tpl' ui=$register_form}
        </div>
      </div>
    {/if}
  {/block}

Another field within "checkout" which you want to delete?
post your question below so we can add it to our tutorial.

WARNING: Please make sure to clear your store cache (Advanced parameter >> Performance >> Clear Cache) and your browser cookies to see the changes!

---------------- PS: a like and a thank you for my work is appreciated ----------------

Edited by Crezzur (see edit history)
  • Like 3
  • Thanks 2
Link to comment
Share on other sites

  • 8 months later...

Thank you very much for this tutorial, it is very helpful. You explain like a real pro 👍

I have a few question, i try to do myself but i stuck :)

1.  how to make telephone number field required?

2. How to make payment radio button selected by default, so i can remove payment step like i remove shipping step?

3. Can all steps be combined into one, so customer fill all information and click pay. No need for pressing 3 time button (Name, Address and Pay)

Thank you

1.png
2.png
3.png

Link to comment
Share on other sites

@zox First of all glad to hear that this tutorial helped you out!

Lets follow the steps below to make the changes you asked

1. Telephone number required
File location: YOURSTORE/classes/form/CustomerAddressFormatter.php

Search for and add the code :

    } elseif ($field === 'phone') {
        $formField->setType('tel');
        // ADD CODE BELOW TO CustomerAddressFormatter.php
        $formField->setRequired(true);

Adding "$formField->setRequired(true);" will tell the form the field "phone" is required.
You can find all fields from the Addresses block in checkout in the file CustomerAddressFormatter.php.
You can add or remove the "$formField->setRequired(true);" to change if the field is required to proceed or not.

2. Payment radio button selected
File location: YOURSTORE/themes/classic/templates/checkout/_partials/steps/payment.tpl
Search for:

{if $selected_payment_option == $option.id || $is_free} checked {/if}

Change to: ("payment-option-2" means option 2 will be selected, change to required option)

{if $option.id == 'payment-option-2'} checked {/if}

3. Combine all steps
Will look into this later on

Edited by Crezzur (see edit history)
Link to comment
Share on other sites

Hi Crezzur, Thank you for answer

The phone field is now required and it work. But the radio button do not work. I try in a classic theme but button is never selected. I try payment-option-1 and payment-option-2. (I have only one payment option).

After that i try same code change in my template, and radio button is selected automatically, but i can not press button to continue... it is grayed out. Please see image.

Screenshot-3.png

 

Link to comment
Share on other sites

  • 3 months later...
  • 4 weeks later...

This tutorial worked for me, but it introduced something else. I've already spent hours trying to solve it and I suspect there is a easy solution. Any tips welcome!

See screenshot. When I disable the modules GDPR and Newsletter, the bottom two text input fields seem to "think" they are the checkboxes that are no longer there.

Ie they format with label on top and Email field is no longer mandatory - a huge issue for us. If I switch GDPR and Newsletter back on, the fields format correctly.

How can I get rid of the "ghosts" of GDPR and Newsletter checkboxes? Have tried to unhook what I believe was carrying them, and disabled the modules. No luck!

Thanks.

image.png.682b1eab13c4617d469bcca989ad4a56.png

Link to comment
Share on other sites

  • 3 months later...

Hi friends! First of all I want to thank you for your great turotial!

I tried to remove the "firstname" and "lastname" filds, from the Checkout process, acording to your tutorial....and after I did that, it gives me this error (please see the picture attached)....I gues there are not optional filds. Here is how I disabled these fields:

/*$format['firstname'] = (new FormField())
            ->setName('firstname')
            ->setLabel(
                $this->translator->trans(
                    'First name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);*/

        /*$format['lastname'] = (new FormField())
            ->setName('lastname')
            ->setLabel(
                $this->translator->trans(
                    'Last name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);*/

Can someone tell me how do I remove those fields so I can move on to the next step of the checkout process?

Thank you!

error-after-disabeling-the-firstname-and-lastname-fields-from-checkout-process.png

removed-fields-firstname-and-lastname.png

Edited by ccristian
translate corrections (see edit history)
Link to comment
Share on other sites

@ccristian

I have just tried it my self, in the file CustomerFormatter.php disable the full block like below. I receive no errors doing this and the fields firstname and lastname are removed.

/* -- START REMOVE
        $format['firstname'] = (new FormField())
            ->setName('firstname')
            ->setLabel(
                $this->translator->trans(
                    'First name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);

        $format['lastname'] = (new FormField())
            ->setName('lastname')
            ->setLabel(
                $this->translator->trans(
                    'Last name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);
END REMOVE -- */

 

Link to comment
Share on other sites

9 hours ago, Crezzur said:

@ccristian

I have just tried it my self, in the file CustomerFormatter.php disable the full block like below. I receive no errors doing this and the fields firstname and lastname are removed.


/* -- START REMOVE
        $format['firstname'] = (new FormField())
            ->setName('firstname')
            ->setLabel(
                $this->translator->trans(
                    'First name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);

        $format['lastname'] = (new FormField())
            ->setName('lastname')
            ->setLabel(
                $this->translator->trans(
                    'Last name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);
END REMOVE -- */

 

I tried this too, and It doesn't working :(

Link to comment
Share on other sites

  • 7 months later...
  • 4 weeks later...
On 5/5/2021 at 9:49 AM, Crezzur said:

For the people still searching for removing parts from the Adresses form i have writen a small tutorial on Stack Overflow.

You can find this here: https://stackoverflow.com/a/67396914/3877838

Great guide. Is it possible to make all the steps in one page? Personal Info, Delivery, Payment, so client isnt forced to click after each step. Which is rather annoying for them.

Link to comment
Share on other sites

  • 8 months later...

If i make 1 step i get an error 500

details in attachment

 

Could you help?

PS.

It is worth adding in the tutorial so that the changed files are in the override folder, otherwise the changes will disappear after the update

asdasd.PNG

 

 

So the beter way for 1 step is this

https://stackoverflow.com/questions/67834719/prestashop-1-7-how-to-remove-optional-password-for-registration-from-guest-check

and add edited file to override/classes/form

clear cache

 

edit2://

 

if you change like attachment in link then you remove password form all form and you can not make new account....

so still dont have any idea how fix it 

@Crezzur.com

Edited by kolmen (see edit history)
Link to comment
Share on other sites

  • 8 months later...
On 2/6/2022 at 6:07 PM, kolmen said:

If i make 1 step i get an error 500

details in attachment

 

Could you help?

PS.

It is worth adding in the tutorial so that the changed files are in the override folder, otherwise the changes will disappear after the update

asdasd.PNG

 

 

So the beter way for 1 step is this

https://stackoverflow.com/questions/67834719/prestashop-1-7-how-to-remove-optional-password-for-registration-from-guest-check

and add edited file to override/classes/form

clear cache

 

edit2://

 

if you change like attachment in link then you remove password form all form and you can not make new account....

so still dont have any idea how fix it 

@Crezzur.com

Hi, Here is my solution to the issue you're having, i had this issue before and after searching files here's what i found out you need to remove.

navigate: classes/form/customerform.tpl

comment out this 

$passwordField = $this->getField('password');
if ((!empty($passwordField->getValue()) || $this->passwordRequired)
&& Validate::isPasswd($passwordField->getValue()) === false) {
$passwordField->addError($this->translator->trans(
'Password must be between 5 and 72 characters long',
[],
'Shop.Notifications.Error'
));
}


Hope this helps!

Edited by MorpheusUno (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi to all!

Does anybody knows how to hide the "Country" field from Checkout process? Since I have only 1 country activated for shipping I don't need this field to be shown in the checkout process. I tried to hide it from front office by adding the "display: none" property, but I didn't found the right code...I tried to remove it from Back Office > International > Countries > Address format and it's telling me that this field it's mandatory.... please help!

My configuration is: PrestaShop version 1.7.8.7, 

Warehouse theme latest version (4.5.5), here is the link of the Warehouse style I am using:

https://iqit-commerce.com/ps17/demo1/en/

 

Thank you!

 

remove-country-field.jpg

Link to comment
Share on other sites

  • 1 month later...
On 11/26/2022 at 8:28 AM, ccristian said:

Hi to all!

Does anybody knows how to hide the "Country" field from Checkout process? Since I have only 1 country activated for shipping I don't need this field to be shown in the checkout process. I tried to hide it from front office by adding the "display: none" property, but I didn't found the right code...I tried to remove it from Back Office > International > Countries > Address format and it's telling me that this field it's mandatory.... please help!

My configuration is: PrestaShop version 1.7.8.7, 

Warehouse theme latest version (4.5.5), here is the link of the Warehouse style I am using:

https://iqit-commerce.com/ps17/demo1/en/

 

Thank you!

 

remove-country-field.jpg

Solved my problem with this line of code: 

.form-group:has(#field-id_country) {
    display:none;
}

Link to comment
Share on other sites

  • 1 year later...

Hello, I followed some of the instructions here and also used chatGPT to delete thefields that I didn't wanted from checkout, but it didn't worked, nothing happend. I delete cache on the backoffice and browser too. Chatgpt also mentioned that there could be more related archives that will still show the fields.

I don't know about PHP so I just doing copy paste.

This is the actuall code on my CustomerFormatter.php

Quote

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */
use Symfony\Component\Translation\TranslatorInterface;

class CustomerFormatterCore implements FormFormatterInterface
{
    private $translator;
    private $language;

    private $ask_for_birthdate = true;
    private $ask_for_partner_optin = true;
    private $partner_optin_is_required = true;
    private $ask_for_password = true;
    private $password_is_required = true;
    private $ask_for_new_password = false;

    public function __construct(
        TranslatorInterface $translator,
        Language $language
    ) {
        $this->translator = $translator;
        $this->language = $language;
    }

    public function setAskForBirthdate($ask_for_birthdate)
    {
        $this->ask_for_birthdate = $ask_for_birthdate;

        return $this;
    }

    public function setAskForPartnerOptin($ask_for_partner_optin)
    {
        $this->ask_for_partner_optin = $ask_for_partner_optin;

        return $this;
    }

    public function setPartnerOptinRequired($partner_optin_is_required)
    {
        $this->partner_optin_is_required = $partner_optin_is_required;

        return $this;
    }

    public function setAskForPassword($ask_for_password)
    {
        $this->ask_for_password = $ask_for_password;

        return $this;
    }

    public function setAskForNewPassword($ask_for_new_password)
    {
        $this->ask_for_new_password = $ask_for_new_password;

        return $this;
    }

    public function setPasswordRequired($password_is_required)
    {
        $this->password_is_required = $password_is_required;

        return $this;
    }

    public function getFormat()
    {
        $format = [];

        $genders = Gender::getGenders($this->language->id);
        if ($genders->count() > 0) {
            $genderField = (new FormField())
                ->setName('id_gender')
                ->setType('radio-buttons')
                ->setLabel(
                    $this->translator->trans(
                        'Social title',
                        [],
                        'Shop.Forms.Labels'
                    )
                );
            foreach ($genders as $gender) {
                $genderField->addAvailableValue($gender->id, $gender->name);
            }
            $format[$genderField->getName()] = $genderField;
        }

        $format['firstname'] = (new FormField())
            ->setName('firstname')
            ->setLabel(
                $this->translator->trans(
                    'First name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true)
            ->addAvailableValue(
                'comment',
                $this->translator->trans('Only letters and the dot (.) character, followed by a space, are allowed.', [], 'Shop.Forms.Help')
            );

        $format['lastname'] = (new FormField())
            ->setName('lastname')
            ->setLabel(
                $this->translator->trans(
                    'Last name',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true)
            ->addAvailableValue(
                'comment',
                $this->translator->trans('Only letters and the dot (.) character, followed by a space, are allowed.', [], 'Shop.Forms.Help')
            );

        if (Configuration::get('PS_B2B_ENABLE')) {
            $format['company'] = (new FormField())
                ->setName('company')
                ->setType('text')
                ->setLabel($this->translator->trans(
                    'Company',
                    [],
                    'Shop.Forms.Labels'
                ));
            $format['siret'] = (new FormField())
                ->setName('siret')
                ->setType('text')
                ->setLabel($this->translator->trans(
                    // Please localize this string with the applicable registration number type in your country. For example : "SIRET" in France and "Código fiscal" in Spain.
                    'Identification number',
                    [],
                    'Shop.Forms.Labels'
                ));
        }

        $format['email'] = (new FormField())
            ->setName('email')
            ->setType('email')
            ->setLabel(
                $this->translator->trans(
                    'Email',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->setRequired(true);

        if ($this->ask_for_password) {
            $format['password'] = (new FormField())
                ->setName('password')
                ->setType('password')
                ->setLabel(
                    $this->translator->trans(
                        'Password',
                        [],
                        'Shop.Forms.Labels'
                    )
                )
                ->setRequired($this->password_is_required);
        }

        if ($this->ask_for_new_password) {
            $format['new_password'] = (new FormField())
                ->setName('new_password')
                ->setType('password')
                ->setLabel(
                    $this->translator->trans(
                        'New password',
                        [],
                        'Shop.Forms.Labels'
                    )
                );
        }

        if ($this->ask_for_birthdate) {
            $format['birthday'] = (new FormField())
                ->setName('birthday')
                ->setType('text')
                ->setLabel(
                    $this->translator->trans(
                        'Birthdate',
                        [],
                        'Shop.Forms.Labels'
                    )
                )
                ->addAvailableValue('placeholder', Tools::getDateFormat())
                ->addAvailableValue(
                    'comment',
                    $this->translator->trans('(E.g.: %date_format%)', ['%date_format%' => Tools::formatDateStr('31 May 1970')], 'Shop.Forms.Help')
                );
        }

        if ($this->ask_for_partner_optin) {
            $format['optin'] = (new FormField())
                ->setName('optin')
                ->setType('checkbox')
                ->setLabel(
                    $this->translator->trans(
                        'Receive offers from our partners',
                        [],
                        'Shop.Theme.Customeraccount'
                    )
                )
                ->setRequired($this->partner_optin_is_required);
        }

        // ToDo, replace the hook exec with HookFinder when the associated PR will be merged
        $additionalCustomerFormFields = Hook::exec('additionalCustomerFormFields', ['fields' => &$format], null, true);

        if (is_array($additionalCustomerFormFields)) {
            foreach ($additionalCustomerFormFields as $moduleName => $additionnalFormFields) {
                if (!is_array($additionnalFormFields)) {
                    continue;
                }

                foreach ($additionnalFormFields as $formField) {
                    $formField->moduleName = $moduleName;
                    $format[$moduleName . '_' . $formField->getName()] = $formField;
                }
            }
        }

        // TODO: TVA etc.?

        return $this->addConstraints($format);
    }

    private function addConstraints(array $format)
    {
        $constraints = Customer::$definition['fields'];

        foreach ($format as $field) {
            if (!empty($constraints[$field->getName()]['validate'])) {
                $field->addConstraint(
                    $constraints[$field->getName()]['validate']
                );
            }
        }

        return $format;
    }
}
 

And these are the files on the same folder of the file CustomerFormatter.php (public_htm>classes>form)

 

image.thumb.png.5f42277c9a99cabc7072e037aeee188e.png

 

Edited by boba56
edit/ige repeated (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...