Created
March 9, 2021 21:30
-
-
Save LordPachelbel/8b36a06764088bce82c46c296958c4d4 to your computer and use it in GitHub Desktop.
BigCommerce checkout tweak to accommodate purchase orders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// this code tweaks BigCommerce's checkout page a little bit to make up for their ridiculous shortcomings | |
document.addEventListener('DOMContentLoaded', function(event) { | |
// add note about purchase order numbers to the checkout form | |
var checkoutAppDiv = document.getElementById('checkout-app'); | |
var checkoutObserver = new MutationObserver(function(mutationsList, observer) { | |
var orderCommentsField = document.querySelector('.form-input[name="orderComment"]'); | |
if(orderCommentsField !== null) { | |
var purchaseOrderNumberHelpText = document.createElement('p'); | |
purchaseOrderNumberHelpText.setAttribute('class', 'purchase-order-help-text'); | |
purchaseOrderNumberHelpText.innerHTML = '<strong>If you have a purchase order #</strong>, please enter it here.'; | |
orderCommentsField.before(purchaseOrderNumberHelpText); | |
checkoutObserver.disconnect(); | |
} | |
}); | |
checkoutObserver.observe(checkoutAppDiv, {childList: true, subtree: true}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check
toInvoice Me
. It will still be called "Check" in the admin interface, but "Invoice Me" will appear for the customer in the checkout.There are two downsides to this workaround. First, this field is part of the Shipping step, not the Billing step, which means the message and Order Comments field are in a weird place. Second and more importantly subsequent checkouts from the same customer account might not display the Order Comments field because the checkout system usually skips past the Shipping and Billing parts of the checkout when the customer already has this information saved in their account. The code I wrote doesn't move the entire field to a later step because I was playing it safe, and moving fields to different steps might break something in BigCommerce's checkout processing code.
To add the script, go to
Storefront
->Script Manager
and create a script with these values:checkout tweaks
(or whatever you want to call it)making up for BigCommerce's ridiculous shortcomings
Footer
Checkout
Essential
Script