Fill form when continuation in block

This commit is contained in:
Alex P 2023-10-23 20:59:49 +03:00
parent df283218bd
commit 539e211e6b
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 19 additions and 0 deletions

View file

@ -24,6 +24,20 @@ const PayPalComponent = ({
const [paypalOrder, setPaypalOrder] = useState(null);
useEffect(() => {
// fill the form if in continuation (for product or mini-cart buttons)
if (!config.scriptData.continuation || !config.scriptData.continuation.order || window.ppcpContinuationFilled) {
return;
}
const addresses = paypalOrderToWcAddresses(config.scriptData.continuation.order);
wp.data.dispatch('wc/store/cart').setBillingAddress(addresses.billingAddress);
if (shippingData.needsShipping) {
wp.data.dispatch('wc/store/cart').setShippingAddress(addresses.shippingAddress);
}
// this useEffect should run only once, but adding this in case of some kind of full re-rendering
window.ppcpContinuationFilled = true;
}, [])
const [loaded, setLoaded] = useState(false);
useEffect(() => {
if (!loaded) {