I am making the magento ecommerce website. I want to make the zipcode text field on product page required (compulsory to proceed the next page) before users add the products in shopping cart. I want to make compulsory for every users to check the zipcode for their area before adding the products in the shopping cart.

This is my cod.phtml code:

 *** Cash On Delivery ***
 * @copyright   Copyright (c) 2015
 * @company     NetAttingo Technologies
 * @package     Netgo_Cod
 * @author      NetGo
 * @dev         netattingomails@gmail.com

$msgData = Mage::helper('netgo_cod')->getConfigData(); 
if($msgData['zip_status'] == 1){
<div class="input-box">
    <div class="z-btn">
        <label>Zip Code : </label><input type="text" placeholder="Enter your pincode" value="" name="cod" class="product-custom-option" id="cod" size="29" style='color:black; font-size:12px' required>
        <button type="button" onclick="checkCOD();" name="zip-check" title="Check" class="button" id="zip-check"><span><span>Check</span></span></button>
    <div id="cod_msg"></div>

    function checkCOD(){
        var cod = $('cod').value;
        if(cod == ''){
            $('cod_msg').update('<span class="cod-error"><?php echo $msgData['emp_msg']; ?></span>');
            $('cod_msg').update('<img src="<?php echo Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ).'media/cod/img/ajax-loader-2.gif';?>">'); 
            new Ajax.Request('<?php echo Mage::getBaseUrl().'netgo/cod/check';?>', {
                parameters: {zipcode: cod}, 
                onSuccess: function(transport) {
                    var response = transport.responseText || "no response text";
                onFailure: function() { alert('Something went wrong...'); }
<?php } ?>

Firstly, onclick of Pincode Check button, add an extra class to the form suppose: checked. Then check that form contains checked class or not onclick of Add to Cart button. Hope this script will easy to implement.

| improve this answer | |
  • Can you please suggest me in the code i provided i did not got you – Salman Dalal Oct 19 '16 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.