Add billing+shipping indices to old orders

This commit is contained in:
claudiulodro 2017-06-28 12:03:18 -07:00
parent b999864fa1
commit 2d48099f20
2 changed files with 36 additions and 0 deletions

View File

@ -84,6 +84,10 @@ class WC_Install {
'wc_update_310_old_comments',
'wc_update_310_db_version',
),
'3.1.1' => array(
'wc_update_311_order_indices',
'wc_update_311_db_version',
),
'3.2.0' => array(
'wc_update_320_mexican_states',
'wc_update_320_db_version',

View File

@ -1128,6 +1128,38 @@ function wc_update_310_db_version() {
WC_Install::update_db_version( '3.1.0' );
}
/**
* Add the billing and shipping index meta for old orders that may not have it.
*/
function wc_update_311_order_indices() {
$args = array(
'post_status' => 'any',
'post_type' => 'shop_order',
'posts_per_page' => -1,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => '_billing_address_index',
'compare' => 'NOT EXISTS'
),
),
);
$ids = get_posts( $args );
foreach ( $ids as $id ) {
$order = new WC_Order( $id );
update_post_meta( $id, '_billing_address_index', implode( ' ', $order->get_address( 'billing' ) ) );
update_post_meta( $id, '_shipping_address_index', implode( ' ', $order->get_address( 'shipping' ) ) );
}
}
/**
* Update DB Version.
*/
function wc_update_311_db_version() {
WC_Install::update_db_version( '3.1.1' );
}
/**
* Update state codes for Mexico.
*/