Running code right before cart-shipping-options-update and/or best place to put address validation

summersabsummersab Member
I've got a custom shipping rate endpoint as well as an address validation endpoint (both powered by the gabrielbull UPS PHP API wrapper). Right now, the validation call runs after any field in the shipping address is updated, and that's just gross. I'm trying to streamline my footer code to decrease the number of times my functions run, and this is a prime example. Here are the ideas I'm musing:
  • I could use the customer-address-update event. However, from what I can tell, this would also run after any field is changed in the address (I could be using it wrong). Also, I'm still quite the novice, and I'm not sure how to use "params" to specify that I only want the event to trigger on the shipping address.
  • Is there an event that triggers right before cart-shipping-options-update? If I could shoe-horn my address validation in there, it would fix any errors in the address prior to sending the address to my shipping endpoint to get rates. That would work, but I'm not sure there's an event that would let me do that.
  • Similar to the previous idea, perhaps I could join my shipping endpoint and address validation endpoint. Basically, my shipping endpoint would call the address validation endpoint when rates are requested from my cart. However . . . how would I return the validated address from my shipping endpoint? The ShippingResponse object used for custom endpoints doesn't include address elements, so I'm not sure how I could use my shipping endpoint to return the validated address.
  • I'm betting you'll mention using the pre-payment webhook, but I'd prefer to have the address validation run after the customer adds their address so that the fields update while they're looking at it. That gives them the chance to fix their address if my validation actually jacked up the address as opposed to actually helping. It would be more annoying to click submit, get a message that the address is wrong, and then not understand why the provided address mysteriously changed.
Any other suggestions? Were you able to follow this? Feel free to email me for clarification, but I thought this would be something that would be beneficial post on the forums should some other user have similar questions.
Sign In or Register to comment.