Hide payment method for non-48 US states

sccr410sccr410 Member
in Help edited October 2014
I cannot get the JS to work to hide PayPal and only allow the PO payment option if a user is outside the non-contiguous 48 US states. Also the amount for shipping should say something like "Will be provided in custom invoice".

Client needs to custom quote shipping for all these international orders and will be sending custom PayPal invoices
Comments
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    That's definitely possible - could you let us know the store you're working this into? Feel free to whisper if it's private.
  • donaldmccullough
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    Give this a try, placing this in your checkout template:
    <script type="text/javascript">
    function togglePayments() {
    	var state = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_state").val() : $("#customer_state").val());
    	var country = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    
    	if ((country == "US" && (state == "HI" || state == "AK")) || country != "US") {
    		// Not contiguous US
    		jQuery("#fc_payment_method_purchase_order").attr("checked", "checked");
    		jQuery("#fc_payment_method_paypal_container").hide();
      		jQuery("input#purchase_order").val("Invoice me");
    		jQuery("#fc_payment_method_purchase_order_container, #fc_payment_method_purchase_order_container fieldset,  #fc_payment_method_purchase_order_container li").show();
    	} else {
    		jQuery("#fc_payment_method_paypal").attr("checked", "checked");
    		jQuery("#fc_payment_method_paypal_container, #fc_payment_method_paypal_container fieldset").show();
    		jQuery("#fc_payment_method_purchase_order_container").hide();
    	}
    }
    
    FC.checkout.overload("updateTaxes", togglePayments, null);
    FC.checkout.overload("updatePaymentDisplay", null, togglePayments);
    jQuery(document).ready(function () { togglePayments(); });
    </script>
    
  • Awesome, thanks for this! It is very close but missing a couple things:

    * US customers still need to be able to choose the invoice option
    * Non 48 customers should have shipping cost visually shown "Included in invoice"
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    For your first point there, simply remove this line:
    jQuery("#fc_payment_method_purchase_order_container").hide();
    

    For the shipping cost, something like this would cover that:
    jQuery("#shipping_cost_formatted").html("Included in invoice");
    
  • Almost, here is actually what I had do to for the shipping:
    jQuery("#shipping_cost,").val("Will be provided in invoice").css('width',200);
    jQuery("#fc_cart_foot_shipping .fc_col2").html("Will be provided in invoice");
    jQuery("#order_total").val('TBD based on shipping').css('width',200);
    jQuery("#fc_cart_foot_total .fc_col2").html("TBD based on shipping");
    

    Purchase order part worked though
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    Glad you got it all sorted!
  • Hey, I'd like to do something like this, but am using the 2.0 version of the cart. Is this meant for a previous version, because plugging it in as instructed above doesn't appear to do anything?
  • fc_adamfc_adam FoxyCart Team
    @tjaskolka,

    This script is for stores 1.1 and older. For 2.0 you would set this up as part of the Twig template. If you could detail what sort of customisation you're wanting to apply to the payments, we can help you set that up.
  • OK. Will open new discussion describing what I want. Thanks.
Sign In or Register to comment.