1

I need to programmatically uncheck the "My billing and shipping address are the same" checkbox in Magento 2.2.6 checkout when a button is pressed.

Background:

I have built a button and some js into my template for simple "in-store pickup" option. It automatically adds the store address to the shipping address and selects the "In Store Pickup" shipping method.

I am using this jquery code in the extensions onepage.phtml file and it works fine, but I just can't figure out the last step to uncheck that button.

        $(document).on('click', '#in-store-pickup', function() {    
            // Set Shipping Address     
            $('.shipping-address-box').find("input[name='firstname']").val( "In-Store" ).change();
            $('.shipping-address-box').find("input[name='lastname']").val( "Pickup" ).change();
            $('.shipping-address-box').find("input[name='city']").val( "<?php echo $city; ?>" ).change();
            $('.shipping-address-box').find("input[name='region_id']").val( "<?php echo $regionId; ?>" ).change();  
            $('.shipping-address-box').find("input[name='postcode']").val( "<?php echo $postcode; ?>" ).change();   
            $('.shipping-address-box').find("input[name='telephone']").val( "<?php echo $phone; ?>" ).change(); 
            $('.shipping-address-box').find("input[name='company']").val( "<?php echo $name; ?>" ).change();
            $('.shipping-address-box').find("input[name='street\\[0\\]']").val( "<?php echo $street1; ?>" ).change();
            $('.shipping-address-box').find("input[name='street\\[1\\]']").val( "<?php echo $street2; ?>" ).change();

            // Set payment method
            $('#s_method_amstrates_amstrates8').trigger('click');

            // Need to uncheck the "My billing and shipping address are the same"


        });

(For the record, I am sure there is a cleaner way of doing above as well)

I have tried several things including triggering a change on the checkbox, but I believe the knockout bindings interfere with it. Thanks

Your Answer

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

Browse other questions tagged or ask your own question.