• Resolved Cezar Ayran

    (@ayrancd)


    If you add any product to the cart and then on the cart page https://96472d1798.nxcli.io/cart/ you select you want insurance and then you click NO, it won’t update the cart unless you refresh the page… any idea of how to fix that? I’ve tried multiple JS codes but nothing seems to make it works if it was loaded previously. Thanks a lot!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @ayrancd

    Thanks for reaching out!

    I checked your site, and, I was able to replicate the scenario here as seen below:

    Firstly, can you please share how did you add the Shipping Insurance to your site as this is not part of the core functionalities of WooCommerce?

    If this was added thru a third-party plugin or a custom code, it would be best to reach out to the developers for further assistance here.

    Thanks!

    Thread Starter Cezar Ayran

    (@ayrancd)

    @xue28 that’s a custom code that came with the website, I’ll paste the code here so the issue is JavaScript related when the cart is updated, jQuery can’t get the field value anymore… this is what I am trying to figure out.

    <script type="text/javascript">
    		jQuery( document ).ready(function( $ ) 
    		{
    			var checkbox    = myAjax.insurance_opt=='optional' ? '<input type="checkbox" id="optional_s" name="optional_s">':'';
    			var button_text = myAjax.Policy_text!='' ? myAjax.Policy_text : 'view policy';
    			var button_color= myAjax.Policy_color!='' ? myAjax.Policy_color : 'red';
    			var policy_text_visible = 'no';
    			jQuery('input#shipping_insurance_box').click(function()
    			{				
    									if(jQuery(this).is(":checked") == 'true'){
    						var shipping_insurance_box = '1';
    					}
    					else if(jQuery(this).is(":not(:checked)")){
    						var shipping_insurance_box = '0';
    					}	
    					
    					if(jQuery('.insurance_fee_change').val() == 'forced'){
    						var shipping_insurance_box = '1';
    					}
    					var fee_change  = jQuery('select.insurance_fee_change option:selected').val();					
    					jQuery.post('https://96472d1798.nxcli.io/wp-admin/admin-ajax.php',{'action':'add_custom_cart_shipping','shipping_insurance_box':shipping_insurance_box,'fee_change':fee_change},function(response){
    						jQuery('body').trigger('wc_update_cart');
    						jQuery('body').trigger('update_checkout');
    					});
    									setTimeout(function(){					
    					if(policy_text_visible == "yes"){					
    						jQuery("tr.fee th").append('<span style="color:'+button_color+'" class="Show_Policy" id="insurance_policy">('+button_text+')</span>');
    					}
    				}, 1000);
    			});
    			
    			jQuery(document).on('change','select.insurance_fee_change',function(){
    				var fee_change  = jQuery('select.insurance_fee_change option:selected').val();
    				if(fee_change == 'yes'){
    					jQuery('input#shipping_insurance_box').prop('checked', true).trigger('click');
    				}
    				else{
    					jQuery('input#shipping_insurance_box').prop('checked', false).trigger('click');
    				}
    				
    			})
    		});
    		</script>

    Hi @ayrancd

    Thanks for your confirmation that the Shipping Insurance was added via a custom code.

    Since this is a custom solution that we don’t provide support for (please see our Support Policy), it would be best to reach out to the developers for further assistance here.

    Additionally, for questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    All the best and hopefully, the issue will be fixed soon.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shipping insurance doesn’t work if it was preloaded’ is closed to new replies.