Skip to content

Instantly share code, notes, and snippets.

@andyg5000
Created November 11, 2015 17:15
Show Gist options
  • Save andyg5000/a0feb70f979156102734 to your computer and use it in GitHub Desktop.
Save andyg5000/a0feb70f979156102734 to your computer and use it in GitHub Desktop.
Create a simple addressbook profile from the last order for each customer
<?php
$query = db_query("SELECT MAX(order_id) as order_id, uid FROM commerce_order GROUP BY uid");
foreach ($query as $result) {
try {
$order_wrapper = entity_metadata_wrapper('commerce_order', $result->order_id);
$billing = $order_wrapper->commerce_customer_billing->value();
if (empty($billing->data['commerce_simple_addressbook']['cloned'])) {
$billing->data['commerce_simple_addressbook']['cloned'] = TRUE;
$order_wrapper->commerce_customer_billing->commerce_simple_addressbook_save->set(TRUE);
$order_wrapper->commerce_customer_billing->save();
$order_wrapper->commerce_customer_shipping->commerce_simple_addressbook_save->set(TRUE);
$order_wrapper->commerce_customer_shipping->save();
commerce_simple_addressbook_commerce_checkout_complete($order_wrapper->value());
}
} catch (Exception $ex) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment