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,18 +338,43 @@ class WooCommerce {
} }
$subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName(); $subscribersTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
$metaKeys = [ if ($this->woocommerceHelper->isWooCommerceCustomOrdersTableEnabled()) {
'_billing_first_name', $addressesTableName = $this->woocommerceHelper->getAddressesTableName();
'_billing_last_name', $metaData = [];
]; $results = $this->connection->executeQuery("
$metaData = $this->connection->executeQuery(" SELECT order_id, first_name, last_name
SELECT post_id, meta_key, meta_value FROM {$addressesTableName}
FROM {$wpdb->postmeta} WHERE order_id IN (:orderIds) and address_type = 'billing'",
WHERE meta_key IN (:metaKeys) AND post_id IN (:postIds) ['orderIds' => array_values($orders)],
", ['orderIds' => Connection::PARAM_INT_ARRAY]
['metaKeys' => $metaKeys, 'postIds' => array_values($orders)], )->fetchAllAssociative();
['metaKeys' => Connection::PARAM_STR_ARRAY, 'postIds' => 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 = [
'_billing_first_name',
'_billing_last_name',
];
$metaData = $this->connection->executeQuery("
SELECT post_id, meta_key, meta_value
FROM {$wpdb->postmeta}
WHERE meta_key IN ('_billing_first_name', '_billing_last_name') AND post_id IN (:postIds)
",
['metaKeys' => $metaKeys, 'postIds' => array_values($orders)],
['metaKeys' => Connection::PARAM_STR_ARRAY, 'postIds' => Connection::PARAM_INT_ARRAY]
)->fetchAllAssociative();
}
$subscribersData = []; $subscribersData = [];
foreach ($orders as $email => $postId) { foreach ($orders as $email => $postId) {