reporting plugin에 대한 플러그인 확장을 생성하고 있습니다. 현재 플러그인은 제품별로 상위 판매 제품에 대한 보고서를 포함한 다양한 보고서를 생성합니다.WooCommerce : SQL 쿼리에서 제품 변형의 총수입을 구하십시오.
변형을 기반으로 최고의 제품을 표시하려면이 설정을 다시 만들어야합니다. 필요한 필드는 상품 이름, SKU, 판매 수량, 총 금액입니다.
제품 변형에 대한 데이터를 얻는 방법은 무엇입니까?
아래에 현재 코드를 입력했습니다.
는 SQL 쿼리 및 데이터 처리 :
$phoen_product_query = "
SELECT
posts.post_title AS product_name,
meta.meta_key as mkey,
meta.meta_value as product_value,
posts.ID AS ID
FROM {$wpdb->posts} AS posts
LEFT JOIN {$wpdb->postmeta} AS meta
ON posts.ID = meta.post_id
WHERE
posts.post_status IN ('publish','private')
AND posts.post_type IN ('product')
AND meta.meta_key IN ('total_sales' ,'_price' ,'post_views_count', '_sku')
ORDER BY
posts.ID ASC,
meta.meta_key ASC
";
$phoen_product_data = $wpdb->get_results( $phoen_product_query,ARRAY_A);
foreach($phoen_product_data as $key1 => $valuee){
if(!isset($phoen_top_products[$valuee['ID']])){
$phoen_top_products[$valuee['ID']] = Array();
$phoen_top_products[$valuee['ID']] = Array(
"produc_total" => 0,
"product_price" => 0,
"product_count" => 0,
"product_views" => 0
);
}
switch ($valuee['mkey']) {
case "_sku":
$phoen_top_products[$valuee['ID']]["product_sku"] = $valuee['product_value'];
break;
case "_price":
$phoen_top_products[$valuee['ID']]["product_price"] = $valuee['product_value'];
break;
case "post_views_count":
$phoen_top_products[$valuee['ID']]["product_views"] = $valuee['product_value'];
break;
case "total_sales":
$phoen_top_products[$valuee['ID']]["product_count"] = $valuee['product_value'];
$phoen_top_products[$valuee['ID']]["produc_total"] = $valuee['product_value'] * $phoen_top_products[$valuee['ID']]["product_price"];
$phoen_top_products[$valuee['ID']]["product_name"] = $valuee['product_name'];
$phoen_top_products[$valuee['ID']]["ID"] = $valuee['ID'];
break;
default:
break;
}
}
관리 모듈 : 데이터베이스 쿼리에서
<table class="table table-striped table-bordered" id="phoen_top_product_table">
<thead>
<tr>
<th><?php _e('Product Name', 'advanced-reporting-for-woocommerce'); ?></th>
<th><?php _e('SKU', 'advanced-reporting-for-woocommerce'); ?></th>
<th><?php _e('Qty', 'advanced-reporting-for-woocommerce'); ?></th>
<th><?php _e('Amount', 'advanced-reporting-for-woocommerce'); ?></th>
</tr>
</thead>
<tbody>
<?php
$phoen_repot_product=array();
$phoen_product_count=0;
for($i=0; $i<count($phoen_top_products); $i++)
{
if($phoen_get_product_val!='View All')
{
if($phoen_product_count<$phoen_get_product_val)
{
?>
<tr class="phoen_top_product_tr">
<td>
<?php $phoen_product_title=isset($phoen_top_products[$i]['product_name'])?$phoen_top_products[$i]['product_name']:'';
echo $phoen_product_title; ?>
</td>
<td>
<?php $phoen_product_sku=isset($phoen_top_products[$i]['product_sku'])?$phoen_top_products[$i]['product_sku']:'';
echo $phoen_product_sku; ?>
</td>
<td>
<?php
$phoen_product_quentity=isset($phoen_top_products[$i]['product_count'])?$phoen_top_products[$i]['product_count']:'';
echo $phoen_product_quentity;
?>
</td>
<td>
<?php
$phoen_total_product_price=isset($phoen_top_products[$i]['produc_total'])?$phoen_top_products[$i]['produc_total']:'';
echo get_woocommerce_currency_symbol().($phoen_total_product_price);
?>
</td>
</tr>
<?php
$phoen_repot_product[$i]= array(
'name'=>$phoen_product_title,
'sku'=>$phoen_product_sku,
'product_count'=>$phoen_product_quentity,
'amount'=>$phoen_total_product_price
);
}
$phoen_product_count++;
}else{
?>
<tr class="phoen_top_product_tr">
<td>
<?php $phoen_product_title=isset($phoen_top_products[$i]['product_name'])?$phoen_top_products[$i]['product_name']:'';
echo $phoen_product_title; ?>
</td>
<td>
<?php $phoen_product_sku=isset($phoen_top_products[$i]['product_sku'])?$phoen_top_products[$i]['product_sku']:'';
echo $phoen_product_sku; ?>
</td>
<td>
<?php
$phoen_product_quentity=isset($phoen_top_products[$i]['product_count'])?$phoen_top_products[$i]['product_count']:'';
echo $phoen_product_quentity;
?>
</td>
<td>
<?php
$phoen_total_product_price=isset($phoen_top_products[$i]['produc_total'])?$phoen_top_products[$i]['produc_total']:'';
echo get_woocommerce_currency_symbol().($phoen_total_product_price);
?>
</td>
</tr>
<?php
$phoen_repot_product[$i]= array(
'name'=>$phoen_product_title,
'sku'=>$phoen_product_sku,
'product_count'=>$phoen_product_quentity,
'amount'=>$phoen_total_product_price
);
}
}
$phoen_product_file = fopen('phoen-repot-product.csv', 'w');
fputcsv($phoen_product_file, array('Product Name', 'SKU', 'Qty', 'Amount'));
foreach ($phoen_repot_product as $phoen_product_row)
{
fputcsv($phoen_product_file, $phoen_product_row);
}
fclose($phoen_product_file);
?>
</tbody>
지연으로 인해 불편을 끼쳐 드려 죄송합니다. 나는 당신의 대답을 이미 선택했다고 생각했습니다. – Christy