Magento newsletter auto checked on registration Page

半城伤御伤魂 提交于 2019-12-04 19:18:48
Vim Bonsu

Here is what worked for me. If you want the newsletter opt in on the customer account registration page checked by default, get this file: /app/design/frontend/your_theme/default/template/customer/form/regist‌​er.phtml

Find this line:

<?php if ($this->isNewsletterEnabled()): ?>

Right below it, add this:

<?php
$checked = true;
if($this->getFormData()->getEmail()) {
if(!$this->getFormData()->getIsSubscribed()) {
    $checked = true;
    }
}   
 ?>

Then Find this div

<div class="input-box">

Replace the code in the div with this code:

<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed" checked="checked" class="checkbox" />

That's it! Save and upload the file.

Please find the following code in register.phtml file:

<?php if ($this->isNewsletterEnabled()): ?>
        <li class="control">
            <div class="input-box">
                 <li>
             <input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed" <?php if($this->getFormData()->getIsSubscribed()){ ?> checked="checked"<?php }elseif($this->getFormData()->getIsSubscribed == NULL){ ?> checked="checked"<?php }?> />
            <label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
        </li>
    </div>
    <label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
    <?php /* Extensions placeholder */ ?>
    <?php echo $this->getChildHtml('customer.form.register.newsletter')?>
</li>
<?php endif ?>

And Replace with the following code :

<?php if ($this->isNewsletterEnabled()): ?>
<?php
$checked = true;
if($this->getFormData()->getEmail()) {
    if(!$this->getFormData()->getIsSubscribed()) {
        $checked = false;
    }
}   
 ?>
<li class="control">
<div class="input-box">
    <input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($checked): ?> checked="checked"<?php endif; ?> class="checkbox" />
</div>
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.register.newsletter')?>
</li>
<?php endif ?>

I have used php for this because. by this we can get user preference after user submit form and error occur

Hope this Help !!

Navaratna Yadav

Please Add the following code in register.phtml file:

Add chaked End of line Input type

<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" checked />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!