Repeat the tax id as a PO #

Hi, i need to get the costumer tax id, and repeat the information at a custom PO order field.

I have changed the PO# field to be able to use Boleto bancário as a payments type, i need to get the tax id info and fullfill the PO# filed on my checkout.

I also need to have a text right below this filed to explain to costumer what will happen next (In this case, he will get a boleto at his email address).

Can you help on this one?

Thank you!
Comments
  • fc_adamfc_adam FoxyCart Team
    edited March 13
    @leaodonorte,

    Funnily enough - we actually helped someone with a similar request recently. If I'm understanding you correctly - you're wanting to copy whatever value is entered into the customer tax ID field into the purchase order number field, and display a custom text string under that field as well.

    If so - the following javascript should do that, and can be included in the 'footer' textarea of the "Add custom header and footer code to your templates" option on the "configuration" page in the admin.
    {% if context == "checkout" %}
    <script>
    FC.client.on("render.done", updatePO);
    $("body").on("focusout", "#billing_tax_id", updatePO);
    function updatePO() {
    if (FC.json.payment_method_type == "purchase_order") {
    $("#purchase_order").val(FC.json.billing_address.tax_id).attr("readonly", true);
    if ($(".custom-boleto").length == 0) {
    $("#fc-payment-method-purchase-order .fc-input-group-container--active").append('<div class="fc-form-group custom-boleto"><p>Custom text to display to the user about what happens next</p></div></div>');
    }
    }
    }
    </script>
    {% endif %}
    That script will force the purchase order field to match the billing tax ID, and also make the purchase order field readonly - to ensure it stays as the same. It then outputs the text below the PO field - and you can modify the string as desired within the javascript there.

    I hope that helps!
  • Many thanks! @fc_adam ! it worked perfectly!
  • Hi, @fc_adam, one more question, is possible to include the custom text above at the costumer receipt as well?
  • Also, i have notice that after using the code above, my shop stoped showing the side cart. Any fix for this?
  • fc_adamfc_adam FoxyCart Team
    @leaodonorte,

    Oh sorry, I missed a semicolon in my code - I've edited my post to add it, but this line needs to end with a semicolon:
    $("body").on("focusout", "#billing_tax_id", updatePO);
    In terms of including it on the receipt - you could use a modified version of the javascript like this:
    {% if context == "checkout" or context == "receipt" %}
    <script>
    var message = "Custom text to display to the user about what happens next";

    {% if context == "checkout" %}
    FC.client.on("render.done", updatePO);
    $("body").on("focusout", "#billing_tax_id", updatePO);
    {% else %}
    $(updatePO);
    {% endif %}

    function updatePO() {
    if (FC.json.payment_method_type == "purchase_order") {
    if (FC.json.context == "checkout") {
    $("#purchase_order").val(FC.json.billing_address.tax_id).attr("readonly", true);
    if ($(".custom-boleto").length == 0) {
    $("#fc-payment-method-purchase-order .fc-input-group-container--active").append('<div class="fc-form-group custom-boleto"><p>' + message + '</p></div></div>');
    }
    } else {
    $("#fc-messages .fc-alert--success").append("<br><br>" + message);
    }
    }
    }
    </script>
    {% endif %}
    The location of the message text is moved to the top - but that should update both checkout and receipt for you.
Sign In or Register to comment.