Question

I try to hide "save" button in my prestashop checkout page. By default when guest field all fields need to click on "save" button. Strange but button do not disappear. May be something in default js is not ok but i don`t want to touch it. I want to hide this button with little jquery.

You can see it live at: test.detelinmarkov.com/quick-order And what i try to do: When information is correct and has been saved customers see message "Account information saved successfully" I try when this message show up "save" button to hide.

Notice: Before i try to get some id for successfully saved data because if customer go back to other page or refresh checkout page "Account information saved successfully" disappear and button is stay there.

And the code that i try, but don`t work...

                {literal}
            <script>
            $('input[name=opc_account_saved]')
                .click(
                     function ()
                     {
                         $(this).hide();

                         $("savebutton").hide();
                     }
                );
            </script>
            {/literal}
            <div id="savebutton">
            <p class="submit">
                <input type="submit" class="exclusive button" name="submitAccount" id="submitAccount" value="{l s='Save'}" />
            </p>
            </div>
            <p style="display: none;" id="opc_account_saved">
                {l s='Account information saved successfully'}
            </p>

By default problem with not disappearing of button may be is in this js:

$(function() {
// GUEST CHECKOUT / NEW ACCOUNT MANAGEMENT
if ((!isLogged) || (isGuest))
{
    if (guestCheckoutEnabled && !isLogged)
    {
        $('#opc_account_choice').show();
        $('#opc_account_form, #opc_invoice_address').hide();

        $('#opc_createAccount').click(function() {
            $('.is_customer_param').show();
            $('#opc_account_form').slideDown('slow');
            $('#is_new_customer').val('1');
            $('#opc_account_choice, #opc_invoice_address').hide();
            updateState();
            updateNeedIDNumber();
            updateZipCode();
        });
        $('#opc_guestCheckout').click(function() {
            $('.is_customer_param').hide();
            $('#opc_account_form').slideDown('slow');
            $('#is_new_customer').val('0');
            $('#opc_account_choice, #opc_invoice_address').hide();
            $('#new_account_title').html(txtInstantCheckout);
            $('#submitAccount').prop({id : 'submitGuestAccount', name : 'submitGuestAccount'});
            updateState();
            updateNeedIDNumber();
            updateZipCode();
        });
    }
    else if (isGuest)
    {
        $('.is_customer_param').hide();
        $('#opc_account_form').show('slow');
        $('#is_new_customer').val('0');
        $('#opc_account_choice, #opc_invoice_address').hide();
        $('#new_account_title').html(txtInstantCheckout);
        updateState();
        updateNeedIDNumber();
        updateZipCode();
    }
    else
    {
        $('#opc_account_choice').hide();
        $('#is_new_customer').val('1');
        $('.is_customer_param, #opc_account_form').show();
        $('#opc_invoice_address').hide();
        updateState();
        updateNeedIDNumber();
        updateZipCode();
    }

    // LOGIN FORM
    $('#openLoginFormBlock').click(function() {
        $('#openNewAccountBlock').show();
        $(this).hide();
        $('#login_form_content').slideDown('slow');
        $('#new_account_form_content').slideUp('slow');
        return false;
    });
    // LOGIN FORM SENDING
    $('#SubmitLogin').click(function() {
        $.ajax({
            type: 'POST',
            headers: { "cache-control": "no-cache" },
            url: authenticationUrl + '?rand=' + new Date().getTime(),
            async: false,
            cache: false,
            dataType : "json",
            data: 'SubmitLogin=true&ajax=true&email='+encodeURIComponent($('#login_email').val())+'&passwd='+encodeURIComponent($('#login_passwd').val())+'&token=' + static_token ,
            success: function(jsonData)
            {
                if (jsonData.hasError)
                {
                    var errors = '<b>'+txtThereis+' '+jsonData.errors.length+' '+txtErrors+':</b><ol>';
                    for(var error in jsonData.errors)
                        //IE6 bug fix
                        if(error !== 'indexOf')
                            errors += '<li>'+jsonData.errors[error]+'</li>';
                    errors += '</ol>';
                    $('#opc_login_errors').html(errors).slideDown('slow');
                }
                else
                {
                    // update token
                    static_token = jsonData.token;
                    updateNewAccountToAddressBlock();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus !== 'abort')
                    alert("TECHNICAL ERROR: unable to send login informations \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
            }
        });
        return false;
    });

    // INVOICE ADDRESS
    $('#invoice_address').click(function() {
        bindCheckbox();
    });

    // VALIDATION / CREATION AJAX
    $('#submitAccount').click(function() {
        $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow')

        var callingFile = '';
        var params = '';

        if (parseInt($('#opc_id_customer').val()) == 0)
        {
            callingFile = authenticationUrl;
            params = 'submitAccount=true&';
        }
        else
        {
            callingFile = orderOpcUrl;
            params = 'method=editCustomer&';
        }

        $('#opc_account_form input:visible, #opc_account_form input[type=hidden]').each(function() {
            if ($(this).is('input[type=checkbox]'))
            {
                if ($(this).is(':checked'))
                    params += encodeURIComponent($(this).attr('name'))+'=1&';
            }
            else if ($(this).is('input[type=radio]'))
            {
                if ($(this).is(':checked'))
                    params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&';
            }
            else
                params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&';
        });
        $('#opc_account_form select:visible').each(function() {
            params += encodeURIComponent($(this).attr('name'))+'='+encodeURIComponent($(this).val())+'&';
        });
        params += 'customer_lastname='+encodeURIComponent($('#customer_lastname').val())+'&';
        params += 'customer_firstname='+encodeURIComponent($('#customer_firstname').val())+'&';
        params += 'alias='+encodeURIComponent($('#alias').val())+'&';
        params += 'other='+encodeURIComponent($('#other').val())+'&';
        params += 'is_new_customer='+encodeURIComponent($('#is_new_customer').val())+'&';
        // Clean the last &
        params = params.substr(0, params.length-1);

        $.ajax({
            type: 'POST',
            headers: { "cache-control": "no-cache" },
            url: callingFile + '?rand=' + new Date().getTime(),
            async: false,
            cache: false,
            dataType : "json",
            data: 'ajax=true&'+params+'&token=' + static_token ,
            success: function(jsonData)
            {
                if (jsonData.hasError)
                {
                    var tmp = '';
                    var i = 0;
                    for(var error in jsonData.errors)
                        //IE6 bug fix
                        if(error !== 'indexOf')
                        {
                            i = i+1;
                            tmp += '<li>'+jsonData.errors[error]+'</li>';
                        }
                    tmp += '</ol>';
                    var errors = '<b>'+txtThereis+' '+i+' '+txtErrors+':</b><ol>'+tmp;
                    $('#opc_account_errors').slideUp('fast', function(){
                        $(this).html(errors).slideDown('slow', function(){
                            $.scrollTo('#opc_account_errors', 800);
                        });                         
                    }); 
                }
                else
                {
                    $('#opc_account_errors').slideUp('slow', function(){
                        $(this).html('');
                    });
                }

                isGuest = parseInt($('#is_new_customer').val()) == 1 ? 0 : 1;
                // update addresses id
                if(jsonData.id_address_delivery !== undefined && jsonData.id_address_delivery > 0)
                    $('#opc_id_address_delivery').val(jsonData.id_address_delivery);
                if(jsonData.id_address_invoice !== undefined && jsonData.id_address_invoice > 0)
                    $('#opc_id_address_invoice').val(jsonData.id_address_invoice);                  

                if (jsonData.id_customer !== undefined && jsonData.id_customer !== 0 && jsonData.isSaved)
                {
                    // update token
                    static_token = jsonData.token;

                    // It's not a new customer
                    if ($('#opc_id_customer').val() !== '0')
                        if (!saveAddress('delivery'))
                            return false;

                    // update id_customer
                    $('#opc_id_customer').val(jsonData.id_customer);

                    if ($('#invoice_address:checked').length !== 0)
                    {
                        if (!saveAddress('invoice'))
                            return false;
                    }

                    // update id_customer
                    $('#opc_id_customer').val(jsonData.id_customer);

                    // force to refresh carrier list
                    if (isGuest)
                    {
                        isLogged = 1;
                        $('#opc_account_saved').fadeIn('slow');
                        $('#submitAccount').hide();
                        updateAddressSelection();
                    }
                    else
                        updateNewAccountToAddressBlock();
                }
                $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow');
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus !== 'abort')
                    alert("TECHNICAL ERROR: unable to save account \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
                $('#opc_new_account-overlay, #opc_delivery_methods-overlay, #opc_payment_methods-overlay').fadeIn('slow')
            }
        });
        return false;
    });
}

bindCheckbox();
bindInputs();

$('#opc_account_form input,select,textarea').change(function() {
    if ($(this).is(':visible'))
    {
        $('#opc_account_saved').fadeOut('slow');
        $('#submitAccount').show();
    }
});

});

Was it helpful?

Solution

Missing # in your id selector

$("#savebutton").hide();
//-^-----
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top