Add address card toggling

This commit is contained in:
Daniel Dudzic 2024-09-13 22:30:04 +02:00
parent 96c566321a
commit f77aae6b90
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
4 changed files with 93 additions and 5 deletions

View file

@ -1,3 +1,5 @@
import { dispatch } from '@wordpress/data';
export const snapshotFields = ( shippingAddress, billingAddress ) => {
console.log( 'Attempting to snapshot fields' );
if ( ! shippingAddress || ! billingAddress ) {
@ -74,11 +76,16 @@ export const populateWooFields = (
setWooShippingAddress,
setWooBillingAddress
) => {
const CHECKOUT_STORE_KEY = 'wc/store/checkout';
console.log(
'Populating WooCommerce fields with profile data:',
profileData
);
// Disable the 'Use same address for billing' checkbox
dispatch( CHECKOUT_STORE_KEY ).__internalSetUseShippingAsBilling( false );
// Save shipping address
const { address, name, phoneNumber } = profileData.shippingAddress;
@ -113,4 +120,7 @@ export const populateWooFields = (
console.log( 'Setting WooCommerce billing address:', billingAddress );
setWooBillingAddress( billingAddress );
dispatch( CHECKOUT_STORE_KEY ).setEditingShippingAddress( false );
dispatch( CHECKOUT_STORE_KEY ).setEditingBillingAddress( false );
};