2014-10-19 98 views
0

我一直在尋找2天如何做到這一點,並真正掙扎。我對PHP相當陌生,所以這可能很簡單,但無論我嘗試它,都不起作用。在銷售報告中顯示自定義字段'利潤' - Woocommerce

我在每個產品中都有一個名爲'Profit'的自定義字段。我想要做的就是在woocommerce銷售報告電子郵件插件的產品名稱旁邊打電話。 !

這是我需要編輯的class-wc-sre-row-top-sellers.php文件中的代碼。 但它不工作,我哪裏錯了?

更新:我現在增加了什麼建議仍然沒有運氣。你可以看到我加了「//設置利潤奧利並添加

行。 ' - £)。 $ Profit

$ value =最後的底部。

UPDATE2:我現在已經添加的代碼,因爲我是好心告訴之下,但它仍然沒有工作。利潤正在被調用,但之後沒有任何顯示。我已經進入了自定義字段的方法是在自定義字段標籤

我在做什麼錯下的產品?

<?php 
 

 
if (!defined('ABSPATH')) { 
 
\t exit; 
 
} // Exit if accessed directly 
 

 
class WC_SRE_Row_Top_Sellers extends WC_SRE_Report_Row { 
 

 
\t /** 
 
\t * The constructor 
 
\t * 
 
\t * @param $date_range 
 
\t * 
 
\t * @access public 
 
\t * @since 1.0.0 
 
\t */ 
 
\t public function __construct($date_range) { 
 
\t \t parent::__construct($date_range, 'top-sellers', __('Top Sellers', 'woocommerce-sales-report-email')); 
 
\t } 
 

 
\t /** 
 
\t * Prepare the data 
 
\t * 
 
\t * @access public 
 
\t * @since 1.0.0 
 
\t */ 
 
\t public function prepare() { 
 

 
\t \t // Create a Report Manager object 
 
\t \t $report_manager = new WC_SRE_Report_Manager($this->get_date_range()); 
 

 
\t \t // Set the default order types 
 
\t \t $order_types = array('shop_order'); 
 

 
\t \t // wc_get_order_types() is a 2.2+ function 
 
\t \t if (function_exists('wc_get_order_types')) { 
 
\t \t \t $order_types = wc_get_order_types('order-count'); 
 
\t \t } 
 

 
\t \t // Get top sellers 
 
\t \t $top_sellers = $report_manager->get_order_report_data(array(
 
\t \t \t 'data'   => array(
 
\t \t \t \t '_product_id' => array(
 
\t \t \t \t \t 'type'   => 'order_item_meta', 
 
\t \t \t \t \t 'order_item_type' => 'line_item', 
 
\t \t \t \t \t 'function'  => '', 
 
\t \t \t \t \t 'name'   => 'product_id' 
 
\t \t \t \t), 
 
\t \t \t \t '_qty'  => array(
 
\t \t \t \t \t 'type'   => 'order_item_meta', 
 
\t \t \t \t \t 'order_item_type' => 'line_item', 
 
\t \t \t \t \t 'function'  => 'SUM', 
 
\t \t \t \t \t 'name'   => 'order_item_qty' 
 
\t \t \t \t) 
 
\t \t \t), 
 
\t \t \t 'order_by'  => 'order_item_qty DESC', 
 
\t \t \t 'group_by'  => 'product_id', 
 
\t \t \t 'limit'  => 12, 
 
\t \t \t 'query_type' => 'get_results', 
 
\t \t \t 'filter_range' => true, 
 
\t \t \t 'order_types' => $order_types, 
 
\t \t)); 
 

 
\t \t $value = 'n/a'; 
 

 
\t \t 
 

 
\t \t // Fill the $value var with products 
 
\t \t if (count($top_sellers) > 0) { 
 
\t \t \t $value = ''; 
 
\t \t \t foreach ($top_sellers as $product) { 
 

 
// THIS IS WHERE THE NEW CODE IS AND $PROFIT IS CALLED AFTER ' - £' . BELOW 
 
\t \t $Profit = array_shift(woocommerce_get_product_terms($product->product_id, 'Profit', 'names')); 
 
\t \t \t \t $value .= $product->order_item_qty . 'x : ' . get_the_title($product->product_id) . ' - £' . $Profit . '<br/>'; 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->set_value($value); 
 
\t } 
 

 
}

+0

我也面臨着我要爲**總添加新行同樣的問題在銷售報告電子郵件中發送**和**淨銷售額**。請幫我在這 – Xabby 2016-11-08 16:11:07

回答

1

這裏是讓自定義的方式變量加入到吸引商業產品:

$Profit = array_shift(woocommerce_get_product_terms($product->product_id, 'Profit', 'names')); 
+0

感謝您的答覆。我已更新該帖子以顯示我正在執行此操作,但我仍然沒有任何運氣。 – OliverG 2014-10-19 16:06:52

+0

您已將它放在錯誤的地方,您應該添加$ Profit = array_shift(woocommerce_get_product_terms($ product-> product_id,'Profit','names')); foreach之後($ top_sellers爲$ product){ – 2014-10-19 20:21:11

+0

非常感謝您發送此郵件並告訴我該放哪裏。不幸的是,這仍然沒有獲得價格,它只是不抓住自定義領域。看起來「woocommerce_get_product_terms」已被棄用,但我也嘗試過它的替換「wc_get_product_terms」,但仍然沒有運氣。誰能幫忙? – OliverG 2014-10-19 22:17:58