将自定义列添加到woocommerce报告 - csv [英] Add custom column to woocommerce report - csv
本文介绍了将自定义列添加到woocommerce报告 - csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
函数wpg_add_columns($ cols){
$ cols ['wc_settings_tab_payment_method'] = __('付款方式','mytheme');
return $ cols;
}
add_filter('wpg_order_columns','wpg_add_columns');
解决方案
这应该工作。让我知道这一点。
<?php
//步骤1:将字段添加到列
函数wpg_add_columns($ cols){
$ cols ['wc_settings_tab_authors_income'] = __('作者收入','mytheme');
return $ cols;
}
add_filter('wpg_order_columns','wpg_add_columns');
//步骤2:将相同的列添加到设置,以便它会出现在设置页面中。
函数wpg_add_fields($ settings){
$ settings ['authors_income'] = array(
'name'=> __('Authors Income','woocommerce-simply -order-export'),
'type'=>'checkbox',
'desc'=> __('Authors Income','woocommerce-simply-order-export'),
'id'=>'wc_settings_tab_authors_income'
);
返回$设置;
}
add_filter('wc_settings_tab_order_export','wpg_add_fields');
//注意:注意,在上面的步骤中,id属性与步骤1中的数组键的属性相同。(wc_settings_tab_authors_income)
//步骤3:将其添加到CSV。
函数csv_write(& $ csv,$ od,$ fields){
if(!empty($ fields ['wc_settings_tab_authors_income'])&& $ fields ['wc_settings_tab_authors_income' ] === true){
$ authors_income = get_post_meta($ od-> id,'authors_income',true);
array_push($ csv,$ authors_income);
}
}
add_action('wpg_add_values_to_csv','csv_write',10,3);
I've got a question - is it possible to add one more column (which will present data from custom field) to csv export file in woocommerce? all necessary data is stored for each order as meta_key: 'authors_income'. I have no idea how to make it. I've tried to adapt below code, but it doesnt work:
function wpg_add_columns($cols) {
$cols['wc_settings_tab_payment_method'] = __('Payment Method', 'mytheme');
return $cols;
}
add_filter('wpg_order_columns', 'wpg_add_columns');
解决方案
This should work. Let me know this goes.
<?php
//Step 1: Add field to column
function wpg_add_columns($cols) {
$cols['wc_settings_tab_authors_income'] = __('Authors Income', 'mytheme');
return $cols;
}
add_filter('wpg_order_columns', 'wpg_add_columns');
//Step 2: Add same column to settings, so that it will appear in settings page.
function wpg_add_fields($settings) {
$settings['authors_income'] = array(
'name' => __( 'Authors Income', 'woocommerce-simply-order-export' ),
'type' => 'checkbox',
'desc' => __( 'Authors Income', 'woocommerce-simply-order-export' ),
'id' => 'wc_settings_tab_authors_income'
);
return $settings;
}
add_filter('wc_settings_tab_order_export', 'wpg_add_fields');
//Note: Notice that in above step, id attribute is identical to that of array key in step 1. ( wc_settings_tab_authors_income )
//Step 3: Add it to csv.
function csv_write( &$csv, $od, $fields ) {
if( !empty( $fields['wc_settings_tab_authors_income'] ) && $fields['wc_settings_tab_authors_income'] === true ){
$authors_income = get_post_meta( $od->id, 'authors_income', true );
array_push( $csv, $authors_income );
}
}
add_action('wpg_add_values_to_csv', 'csv_write', 10, 3);
这篇关于将自定义列添加到woocommerce报告 - csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文