Forum

Thread tagged as: Question, Shop

How to auto-populate Order Addresses using pre-saved Customer (Shop) Addresses?

When a new customer (either registering or checking out as a guest) enters their billing and shipping addresses during checkout, the addresses are correctly associated with the order in perch2_shop_orders.

The addresses are also correctly saved in perch2_shop_addresses with the correct addressTitle and addressSlug of default and shipping.

The addresses are displayed correctly on the confirmation page using perch_shop_order_addresses().

I'm having a problem however, when a registered customer logs in, adds items to their cart and checks out. They're already logged in so the page to enter addresses is skipped and there are no addresses associated with the order. perch_shop_order_addresses() returns nothing.

I'd like to auto populate the addresses for the order (i.e. perch_shop_order_addresses()) with the saved addresses that are returned by perch_shop_customer_addresses().

I know it can be done manually with the user selecting a billing and a shipping address from their saved addresses (as discussed here: https://forum.grabaperch.com/forum/05-20-2016-shop-address-selection. Ideally I'd like to do this automatically though.

Martin Jewiss

Martin Jewiss 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

They're already logged in so the page to enter addresses is skipped

Where is that implemented? It sounds like that logic is incorrect.

Hi Drew, Thanks for getting back to us. Martin has asked me to have a look at this.

We're currently using the perch shop add-on.

When a customer clicks proceed to checkout they are taken to the [checkout.php] page which does two checks: 1) if (perch_member_logged_in() && perch_post('#PaymentGatewayToken')) - which evaluates as true when we have a logged in customer (either with or without a password) (* #PaymentGatewayToken is just a replacement I put on here we're using the right one in the actual code) 2)

if (!perch_member_logged_in()) {
        PerchSystem::redirect('/shop/addresses');
    }

Now, ('/shop/addresses') - [addresses.php] has the following redirect:

if (perch_member_logged_in()) {
        PerchSystem::redirect('/shop/checkout');
    }

this means that a customer that is logged in will completely skip the address page and be taken straight to the payment page without any address information being added. We're wondering if there's a page we're missing or if there's a way for us to simply ask the customer to confirm the shipping and billing address we have on file.

This may help depending on the workflow you are aiming at:

// if the addresses are not set then get them
if (! perch_shop_addresses_set()) {
    // ... goto to the confirm/ select addresses page ...
}