Automattic\WooCommerce\Admin\API\Reports\Variations
DataStore::fill_deleted_product_name
Fill missing extended_info.name for the deleted products.
Метод класса: DataStore{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->fill_deleted_product_name( $products );
- $products(массив) (обязательный)
- Product data.
Код DataStore::fill_deleted_product_name() DataStore::fill deleted product name WC 11.1.0
protected function fill_deleted_product_name( array &$products ) {
global $wpdb;
$product_variation_ids = array();
// Find products with missing extended_info.name.
foreach ( $products as $key => $product ) {
if ( ! isset( $product['extended_info']['name'] ) ) {
$product_variation_ids[ $key ] = array(
'product_id' => $product['product_id'],
'variation_id' => $product['variation_id'],
);
}
}
if ( ! count( $product_variation_ids ) ) {
return;
}
$where_clauses = implode(
' or ',
array_map(
function ( $ids ) {
return "(
product_lookup.product_id = {$ids['product_id']}
and
product_lookup.variation_id = {$ids['variation_id']}
)";
},
$product_variation_ids
)
);
$query = "
select
product_lookup.product_id,
product_lookup.variation_id,
order_items.order_item_name
from
{$wpdb->prefix}wc_order_product_lookup as product_lookup
left join {$wpdb->prefix}woocommerce_order_items as order_items
on product_lookup.order_item_id = order_items.order_item_id
where
{$where_clauses}
group by
product_lookup.product_id,
product_lookup.variation_id,
order_items.order_item_name
";
// phpcs:ignore
$results = $wpdb->get_results( $query );
$index = array();
foreach ( $results as $result ) {
$index[ $result->product_id . '_' . $result->variation_id ] = $result->order_item_name;
}
foreach ( $product_variation_ids as $product_key => $ids ) {
$product = $products[ $product_key ];
$index_key = $product['product_id'] . '_' . $product['variation_id'];
if ( isset( $index[ $index_key ] ) ) {
$products[ $product_key ]['extended_info']['name'] = $index[ $index_key ];
}
}
}