Forum

Thread tagged as: Shop

Autimatically get member address at checkout

OK, so I am going from the cart straight to checkout / PayPal. The member is already logged in and their address and phone number is already on record. I do not want them editing the address at the checkout so just need to grab the address that we have for them. In the master member template, I have:

<perch:members type="text" id="first_name" label="First name" listing="true" order="1" />
<perch:members type="text" id="last_name" label="Last name" listing="true" order="2" />
<perch:members type="text" id="phone" label="Phone" order="4" />
<perch:members type="text" id="address" label="Address" order="5" />
<perch:members type="text" id="city" label="City" order="6" />
<perch:members type="text" id="county" label="County" order="7" />
<perch:members type="text" id="post_code" label="Post Code" listing="true" order="8" />

When I place an oder (obviously not going via the address form) I get just first name, last name, city and county. So it has picked up some bits, but not the address line, post code and phone number. How can I make sure those bits are included? Do I add them as hidden fields on the cart template or something?

Lisa Morena

Lisa Morena 1 points

  • 4 years ago

OK, so I know the member and the customer address are technically separate but I don't get how it has so far managed to pull the city and county?

I really need to get the member and customer addresses linked so that the member address always takes precedence over the customer address. So I first need to check if a customer address exists. If not, I need to populate it with the data from the member address and then set it as the order billing and shipping address.

If an address does exist, I need to compare it with the member address and if they don't match I need to update the customer address and if they do match, I need to set it as the order billing and shipping address.

I need to enter the address details at the time of member creation and I don't want people having to update their address in two places. I also don't really want them ordering with an address that differs from that in the member's area, so you can see my issue here.

I have looked at perch_shop_customer_address(), perch_shop_edit_address_form() and perch_shop_order_address_form() and quite frankly I am getting proper confused!

Ok so I am going to admit defeat with the whole syncing addresses thing. What I need to do is check to see if an address exists for the customer with a title of 'default'. If it does, I want to show the edit address form for that address, if not, I want to prepopulate the fields with the member address and create a new address for the customer.

So how do I test if an address exists for a customer?

BTW if I add a new field to the address edit form, it get added to addressDynamicFields - how do I filter for that particular field within addressDynamicFields?