I would like to be able to hold payment requests for offline processing when they meet a couple of requirements. Either the cart total exceeds $1000 or the order is from a non-US address. I think editing the Purchase Order option could make this happen, only I am not sure how to go about it. Thanks for any help. I am using v2.0.
You might want to consider using this snippet: https://wiki.foxycart.com/snippets/checkout/hiding_po_payment_option. With a few modifications (adding cart total > $1000 and customer country evaluation) this should work for your requirement.
This could start you off with your cart total condition: This could start you off with your non-US parameter evaluation:
Ah yes - sorry, that wouldn't work with 2.0.
We can work up something else you could use though - could you quickly clarify what other payment method you support for US based orders under $1000?
Sorry, I should have also asked to confirm - are you wanting to only allow purchase orders for transactions over $1000 or non-US customers, as in they won't see any other options for payment apart from the purchase order option?
That's exactly right. The following should cover what you're after: Paste that code into the "Add custom header and footer code" of your store's configuration section in the admin, to the footer textarea.
The code will then be inserted into the checkout for you, and will automatically update the payments section on page load, and whenever the address or cart total is altered to ensure it's always up to date with the current cart.
That appears to do what we need. Thanks for the help!
How can I cause the purchase order radio button to be pre-selected when the purchase order option becomes available?
Could you whisper me your store domain please so I can take a quick look at your checkout? I'd like to check something before I reply.
Thanks for whispering that information. Update the
poRefresh()
function to look like this:If we were looking for something similar, but only allowing PO Payments if a custom field "enterprise" were passed in with the cart (shockingly, to indicate an Enterprise customer was checking out), what would that look like? Is there some form of protection so a clever person didn't figure out the flag and tried to sneak in an order?
Good question. I'm assuming you're meaning that if someone looked at the source code they would see the flag that was necessary to trigger it? If so - you could instead use Twig logic rather than straight javascript which would obscure it a bit more. The twig template is still included within the javascript to allow client-side rendering, but it would be embedded within the template so would be a bit harder for the clever users to find it.
If you wanted to completely obscure it, you could send a request off to a secure endpoint on your side to decide, but that might be overkill for what you're needing.
What would the twig template tweaks look like as that is definitely preferred over easier to see JS-trickery?
The secure endpoint would simply be a script you set up on your side, and then you'd set up an ajax call on the checkout that sends over the necessary information to your endpoint - which in turn responds if the user is enterprise or not. It'd be something you'd configure purely on the checkout.
For the Twig template changes - you'd basically approach what I detailed above but just within Twig logic instead. You'd overwrite the payments block and alter the needed variables. Something like this: You'd paste that inside the
{% embed 'checkout.inc.twig' %}{% endembed %}
tags in the checkout template. What it does - once you've added in the custom Twig logic to check if it's an enterprise user, is displays the purchase order option if it's the only one present, otherwise it displays the normal payment options - but removes purchase orders from being displayed. You'd still need to have some value or condition that the Twig can check against - but the logic to show that it's using that is slightly more obscured from view.