Update updateNames() to work with Woo Custom Order Tables

[MAILPOET-4711]
This commit is contained in:
Rodrigo Primo
2022-10-10 16:50:24 -03:00
committed by Aschepikov
parent dd1fcd5100
commit 1010b64c05

View File

@ -338,6 +338,30 @@ class WooCommerce {
} }
$subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName(); $subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
if ($this->woocommerceHelper->isWooCommerceCustomOrdersTableEnabled()) {
$addressesTableName = $this->woocommerceHelper->getAddressesTableName();
$metaData = [];
$results = $this->connection->executeQuery("
SELECT order_id, first_name, last_name
FROM {$addressesTableName}
WHERE order_id IN (:orderIds) and address_type = 'billing'",
['orderIds' => array_values($orders)],
['orderIds' => Connection::PARAM_INT_ARRAY]
)->fetchAllAssociative();
// format data in the same format that is used when querying wp_postmeta (see below).
foreach ($results as $result) {
$firstNameData['post_id'] = $result['order_id'];
$firstNameData['meta_key'] = '_billing_first_name';
$firstNameData['meta_value'] = $result['first_name'];
$metaData[] = $firstNameData;
$lastNameData['post_id'] = $result['order_id'];
$lastNameData['meta_key'] = '_billing_last_name';
$lastNameData['meta_value'] = $result['last_name'];
$metaData[] = $lastNameData;
}
} else {
$metaKeys = [ $metaKeys = [
'_billing_first_name', '_billing_first_name',
'_billing_last_name', '_billing_last_name',
@ -345,11 +369,12 @@ class WooCommerce {
$metaData = $this->connection->executeQuery(" $metaData = $this->connection->executeQuery("
SELECT post_id, meta_key, meta_value SELECT post_id, meta_key, meta_value
FROM {$wpdb->postmeta} FROM {$wpdb->postmeta}
WHERE meta_key IN (:metaKeys) AND post_id IN (:postIds) WHERE meta_key IN ('_billing_first_name', '_billing_last_name') AND post_id IN (:postIds)
", ",
['metaKeys' => $metaKeys, 'postIds' => array_values($orders)], ['metaKeys' => $metaKeys, 'postIds' => array_values($orders)],
['metaKeys' => Connection::PARAM_STR_ARRAY, 'postIds' => Connection::PARAM_INT_ARRAY] ['metaKeys' => Connection::PARAM_STR_ARRAY, 'postIds' => Connection::PARAM_INT_ARRAY]
)->fetchAllAssociative(); )->fetchAllAssociative();
}
$subscribersData = []; $subscribersData = [];
foreach ($orders as $email => $postId) { foreach ($orders as $email => $postId) {