mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Fill form when continuation in block
This commit is contained in:
parent
df283218bd
commit
539e211e6b
2 changed files with 19 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -167,6 +167,11 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
|||
$script_data['continuation']['cancel'] = array(
|
||||
'html' => $this->cancellation_view->render_session_cancellation( $url, $this->session_handler->funding_source() ),
|
||||
);
|
||||
|
||||
$order = $this->session_handler->order();
|
||||
if ( $order ) {
|
||||
$script_data['continuation']['order'] = $order->to_array();
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue