WC 3.0 Orders Search
-
Hi. With WC 3.0 the _billing_address_index and _shipping_address_index postmeta was introduced. This is a great solution to efficiently search orders
The issue is that old orders won’t have these postmeta fields
As suggested in the class-wc-order-data-store-cpt line 501* Searches on meta data can be slow – this lets you choose what fields to search.
* 3.0.0 added _billing_address and _shipping_address meta which contains all address data to make this faster.
* This however won’t work on older orders unless updated, so search a few others (expand this using the filter if needed).On the same class-wc-order-data-store-cpt.php file there is a function to update the postmeta when there is a address change: protected function update_post_meta( &$order ).
This function created this postmeta fields when there is an update
in billing or shipping address:// If address changed, store concatenated version to make searches faster.
if ( in_array( ‘billing’, $updated_props ) || ! metadata_exists( ‘post’, $id, ‘_billing_address_index’ ) ) {
update_post_meta( $id, ‘_billing_address_index’, implode( ‘ ‘, $order->get_address( ‘billing’ ) ) );
}
if ( in_array( ‘shipping’, $updated_props ) || ! metadata_exists( ‘post’, $id, ‘_shipping_address_index’ ) ) {
update_post_meta( $id, ‘_shipping_address_index’, implode( ‘ ‘, $order->get_address( ‘shipping’ ) ) );
}
Is there any way to run this function to force all orders prior WC 3.0 to contain this two posmeta fields? We have over 94000 orders which at least 90000 are orders prior WC 3.0. This should be run automatically when the 3.0 update is done so old orders contain these postmeta fields.
- The topic ‘WC 3.0 Orders Search’ is closed to new replies.