2017-11-23 13 views
1

WooCommerceでレポートをカスタマイズする必要があるので、class-wc-report-sales-by-date.phpというコアファイルを編集する必要があります。そのようなファイルはフックを使用しません。Woocommerceレポートセクションの上書き機能

このWCのソースコード内の

チェックイン:includes/admin/reports/class-wc-report-sales-by-date.php

私は、この変数を393行を編集する必要があります。ます$ this-> report_data->私は総売上量をカスタマイズする必要が をTOTAL_SALES別の値を追加してください。

このコアファイルをWooCommerceからオーバーライドするにはどうすればよいですか?

答えて

2

コアファイルを上書きしない...他にもメイドがあります。あなたはline 411を見れば、あなたは変更を加えることがwoocommerce_admin_report_dataフィルターフックを持って、この方法(例):

add_filter('woocommerce_admin_report_data', 'custom_admin_report_data', 10, 1); 
function custom_admin_report_data($report_data){ 
    // HERE you make your calculations and changes 
    // New amout to set (example) 
    $new_calculated_amount = 100; 

    // Set the new amounts for "total_sales" key 
    $report_data->total_sales = $new_calculated_amount; 

    // Raw data output just for testing, to get the keys and the structure of the data 
    // to be removed 
    echo '<pre>'; print_r($report_data); echo '</pre>'; 

    // Return the changed data object 
    return $report_data; 
} 

コードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルに行きますかすべてのプラグインファイルでも使用できます。

テスト済みで動作します。私は


...それはちょうど "total_sales"値に機能することで、データ構造と変化のメイドを見ることだ...あなたは削除する必要があり、生のデータを出力コードの行が含まれている

stdClass Object 
(
    [order_counts] => Array 
     (
      [0] => stdClass Object 
       (
        [count] => 1 
        [post_date] => 2017-11-21 16:45:43 
       ) 
     ) 
    [coupons] => Array 
     (
     ) 
    [order_items] => Array 
     (
      [0] => stdClass Object 
       (
        [order_item_count] => 1 
        [post_date] => 2017-11-21 16:45:43 
       ) 
     ) 
    [refunded_order_items] => 0 
    [orders] => Array 
     (
      [0] => stdClass Object 
       (
        [total_sales] => 48 
        [total_shipping] => 15 
        [total_tax] => 5 
        [total_shipping_tax] => 3 
        [post_date] => 2017-11-21 16:45:43 
       ) 
     ) 
    [full_refunds] => Array 
     (
     ) 
    [partial_refunds] => Array 
     (
     ) 
    [refund_lines] => Array 
     (
     ) 
    [total_tax_refunded] => 0 
    [total_shipping_refunded] => 0 
    [total_shipping_tax_refunded] => 0 
    [total_refunds] => 0 
    [total_tax] => 5.00 
    [total_shipping] => 15.00 
    [total_shipping_tax] => 3.00 
    [total_sales] => 48.00 
    [net_sales] => 25.00 
    [average_sales] => 3.57 
    [average_total_sales] => 6.86 
    [total_coupons] => 0.00 
    [total_refunded_orders] => 0 
    [total_orders] => 1 
    [total_items] => 1 
) 

RAWデータ出力がこののようなもの(それはあなたのより良いの変更を行うためのデータ構造を与える)です

ですから、あなたもあなたも"total_sales"キー...

+1

感謝を持っているとして、「注文」オブジェクトデータに変更を加える必要が見ることができますように。それが私の必要なものです。私は本当にあなたの時間と助けに感謝:) –

関連する問題