WC 市场销售报告 [英] WC Marketplace Sales Report
问题描述
我有一个页面,其中包含以下代码,此代码是从仪表板复制的.这意味着这个特定的小部件现在显示在两个地方.在帮助下,我设法将此报告显示的天数增加到 60 天,但我只希望仪表板版本显示 60 天,而我希望此版本显示 365 天.
数组('标签' => __('产品','dc-woocommerce-multi-vendor')),//'收入' =>数组('标签' => __('收入','dc-woocommerce-multi-vendor')),'unique_purchase'=>array('label' => __( 'Unique Purchases', 'dc-woocommerce-multi-vendor' )),), get_current_user_id());?><p>此页面显示了您在过去一年中售出的所有设计.</p><table id="widget_product_sales_report" class="table table-striped product_sold_last_week table-bordered wcmp-widget-dt" width="100%"><头><tr><?php如果($product_sales_report_table_headers):foreach ($product_sales_report_table_headers as $key => $header) { ?><th class="<?php if(isset($header['class'])) echo $header['class']; ?>"><?php if(isset($header['label'])) echo $header['label'];?></th><?php }万一;?><!--th><?php _e('Product', 'dc-woocommerce-multi-vendor');?></th><th><?php _e('Revenue', 'dc-woocommerce-multi-vendor');?></th><th><?php _e('Unique Purchases', 'dc-woocommerce-multi-vendor');?></th--></tr></thead></tbody><脚本>jQuery(document).ready(function($) {var product_sales_report_wgt;var 列 = [];<?php if($product_sales_report_table_headers) {foreach ($product_sales_report_table_headers as $key => $header) { ?>对象 = {};obj['data'] = '<?php echo esc_js($key);?>';obj['className'] = '<?php if(isset($header['class'])) echo esc_js($header['class']);?>';列推(对象);<?php }?>product_sales_report_wgt = $('#widget_product_sales_report').DataTable({订购:真实,分页:真的,信息:真实,搜索 : 真的,处理:假,服务器端:真,响应:真实,语: {"emptyTable": "<?php echo trim(__('数据不足.','dc-woocommerce-multi-vendor')); ?>","zeroRecords": "<?php echo trim(__('数据不足.','dc-woocommerce-multi-vendor')); ?>",},阿贾克斯:{url : '<?php echo add_query_arg('action', 'wcmp_widget_vendor_product_sales_report', $WCMp->ajax_url());?>',类型:帖子",错误:函数(xhr,状态,错误){$("#widget_product_sales_report tbody").append('<tr class="odd"><td valign="top" colspan="<?php if(is_array($product_sales_report_table_headers)) count($product_sales_report_table_headers); ?>" class="dataTables_empty" style="text-align:center;">'+error+' - <a href="javascript:window.location.reload();"><?php_e('重新加载', 'dc-woocommerce-multi-vendor'); ?></a></td></tr>');$("#widget_product_sales_report").css("display","none");}},列:列});新 $.fn.dataTable.FixedHeader( product_sales_report_wgt );});使用此代码
//将 `$days_range` 的默认值从 7 天改为 60 天函数 lh_wcmp_vendor_custom_sales_report( $days_range ) {$days_range = 60;//您可以根据需要在此处调整天数返回 $days_range;}add_filter('wcmp_widget_vendor_product_sales_report_days_range', 'lh_wcmp_vendor_custom_sales_report', 10 );
我能够将默认的 7 天更改为 60 天.但是因为我使用了相同的小部件代码,所以仪表板和报告显示的天数相同.
所以,总结一下 - 我希望在仪表板上显示 60 天(使用上面的代码),然后在报告页面上显示 365 天.
有人可以帮忙吗?
解决方案需要更新\basel-child\dc-product-vendor\vendor-dashboard\vendor-orders.php中的代码
和 \basel-child\functions.php
文件.
我们将添加一个新的查询字符串,同时从 vendor-orders
端点向 wcmp_widget_vendor_product_sales_report
函数发出 AJAX 请求.它将允许我们检测请求是来自仪表板还是供应商订单端点.
以下代码将添加到 vendor-orders.php
文件中(见第 67-79 行):
'wcmp_widget_vendor_product_sales_report','lh-端点' =>'lh-供应商订单',);?>url : '<?php echo add_query_arg( $args, $WCMp->ajax_url() );?>',
然后我们将旧的lh_wcmp_vendor_custom_sales_report()
functions.php
文件中的函数修改为:
//从 URL 中获取 'lh-endpoint' 的值$lh_orders_endpoint = isset( $_GET['lh-endpoint'] ) &&!empty( $_GET['lh-endpoint'] ) ?$_GET['lh-endpoint'] : '';//检查 'lh-endpoint' 值是否为 'lh-vendor-orders'如果('lh-vendor-orders'!== $lh_orders_endpoint){$days_range = 60;//如果 'lh-endpoint' 不是 'lh-vendor-orders',则显示最近 2 个月的订单} 别的 {$days_range = 365;//如果 'lh-endpoint' 是 'lh-vendor-orders',则显示 1 年的订单}
<小时>
这是两个文件的完整代码:
- 从
vendor-orders.php
文件中删除现有代码并放入以下代码:
数组('标签' => __('产品','dc-woocommerce-multi-vendor')),//'收入' =>数组('标签' => __('收入','dc-woocommerce-multi-vendor')),'unique_purchase'=>array('label' => __( 'Unique Purchases', 'dc-woocommerce-multi-vendor' )),), get_current_user_id());?><p>此页面显示了您在过去一年中售出的所有设计.</p><table id="widget_product_sales_report" class="table table-striped product_sold_last_week table-bordered wcmp-widget-dt" width="100%"><头><tr><?php如果($product_sales_report_table_headers):foreach ($product_sales_report_table_headers as $key => $header) { ?><th class="<?php if(isset($header['class'])) echo $header['class']; ?>"><?php if(isset($header['label'])) echo $header['label'];?></th><?php }万一;?><!--th><?php _e('Product', 'dc-woocommerce-multi-vendor');?></th><th><?php _e('Revenue', 'dc-woocommerce-multi-vendor');?></th><th><?php _e('Unique Purchases', 'dc-woocommerce-multi-vendor');?></th--></tr></thead></tbody><脚本>jQuery(document).ready(function($) {var product_sales_report_wgt;var 列 = [];<?php if($product_sales_report_table_headers) {foreach ($product_sales_report_table_headers as $key => $header) { ?>对象 = {};obj['data'] = '<?php echo esc_js($key);?>';obj['className'] = '<?php if(isset($header['class'])) echo esc_js($header['class']);?>';列推(对象);<?php }?>product_sales_report_wgt = $('#widget_product_sales_report').DataTable({订购:真实,分页:真的,信息:真实,搜索 : 真的,处理:真实,服务器端:真,响应:真实,语: {"emptyTable": "<?php echo trim(__('数据不足.','dc-woocommerce-multi-vendor')); ?>","zeroRecords": "<?php echo trim(__('数据不足.','dc-woocommerce-multi-vendor')); ?>",},阿贾克斯:{<?php/* 添加'lh-端点' =>'lh-vendor-orders' 到 AJAX URL,以便我们稍后使用* 有条件地更改 '$days_range' 值.它将更改 ajax url*/wp-admin/admin-ajax.php?action=wcmp_widget_vendor_product_sales_report*/wp-admin/admin-ajax.php?action=wcmp_widget_vendor_product_sales_report&lh-endpoint=vendor-orders*/$args = 数组('动作' =>'wcmp_widget_vendor_product_sales_report','lh-端点' =>'lh-供应商订单',);?>//url : '<?php//echo add_query_arg( 'action', 'wcmp_widget_vendor_product_sales_report', $WCMp->ajax_url() );?>',url : '<?php echo add_query_arg( $args, $WCMp->ajax_url() );?>',类型:帖子",错误:函数(xhr,状态,错误){$("#widget_product_sales_report tbody").append('<tr class="odd"><td valign="top" colspan="<?php if(is_array($product_sales_report_table_headers)) count($product_sales_report_table_headers); ?>" class="dataTables_empty" style="text-align:center;">'+error+' - <a href="javascript:window.location.reload();"><?php_e('重新加载', 'dc-woocommerce-multi-vendor'); ?></a></td></tr>');$("#widget_product_sales_report").css("display","none");}},列:列});新 $.fn.dataTable.FixedHeader( product_sales_report_wgt );});- 在您的
functions.php
文件中,替换旧的 wcmp_widget_vendor_product_sales_report
从供应商订单标签调用
经过测试并致力于:
- WordPress 5.0.3
- 十二十九 1.2
- WooCommerce 3.5.4
- WC 市场 3.3.1
- 本地主机(适用于 Windows 5.6.15 的 XAMPP)
I have a page with the following code in it, this code is duplicated from the dashboard. This means this particular widget now shows in two places. With help I managed to increase the number of days this report shows to 60 however I only want the dashboard version to show 60 days and I would like this version to show 365 days.
<?php
/*
* The template for displaying vendor pending shipping table dashboard widget
* Override this template by copying it to yourtheme/dc-product-vendor/vendor-dashboard/dashboard-widgets/wcmp_vendor_product_sales_report.php
*
* @author WC Marketplace
* @package WCMp/Templates
* @version 3.0.0
*/
if (!defined('ABSPATH')) {
// Exit if accessed directly
exit;
}
global $WCMp;
$product_sales_report_table_headers = apply_filters('wcmp_datatable_widget_product_sales_report_table_headers', array(
'product' => array('label' => __( 'Product', 'dc-woocommerce-multi-vendor' )),
// 'revenue' => array('label' => __( 'Revenue', 'dc-woocommerce-multi-vendor' )),
'unique_purchase'=> array('label' => __( 'Unique Purchases', 'dc-woocommerce-multi-vendor' )),
), get_current_user_id());
?>
<p>This page shows all your designs that have sold over the past year.</p>
<table id="widget_product_sales_report" class="table table-striped product_sold_last_week table-bordered wcmp-widget-dt" width="100%">
<thead>
<tr>
<?php
if($product_sales_report_table_headers) :
foreach ($product_sales_report_table_headers as $key => $header) { ?>
<th class="<?php if(isset($header['class'])) echo $header['class']; ?>"><?php if(isset($header['label'])) echo $header['label']; ?></th>
<?php }
endif;
?>
<!--th><?php _e('Product', 'dc-woocommerce-multi-vendor'); ?></th>
<th><?php _e('Revenue', 'dc-woocommerce-multi-vendor'); ?></th>
<th><?php _e('Unique Purchases', 'dc-woocommerce-multi-vendor'); ?></th-->
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
jQuery(document).ready(function($) {
var product_sales_report_wgt;
var columns = [];
<?php if($product_sales_report_table_headers) {
foreach ($product_sales_report_table_headers as $key => $header) { ?>
obj = {};
obj['data'] = '<?php echo esc_js($key); ?>';
obj['className'] = '<?php if(isset($header['class'])) echo esc_js($header['class']); ?>';
columns.push(obj);
<?php }
} ?>
product_sales_report_wgt = $('#widget_product_sales_report').DataTable({
ordering : true,
paging: true,
info: true,
searching : true,
processing: false,
serverSide: true,
responsive: true,
language: {
"emptyTable": "<?php echo trim(__('Not enough data.','dc-woocommerce-multi-vendor')); ?>",
"zeroRecords": "<?php echo trim(__('Not enough data.','dc-woocommerce-multi-vendor')); ?>",
},
ajax:{
url : '<?php echo add_query_arg( 'action', 'wcmp_widget_vendor_product_sales_report', $WCMp->ajax_url() ); ?>',
type: "post",
error: function(xhr, status, error) {
$("#widget_product_sales_report tbody").append('<tr class="odd"><td valign="top" colspan="<?php if(is_array($product_sales_report_table_headers)) count($product_sales_report_table_headers); ?>" class="dataTables_empty" style="text-align:center;">'+error+' - <a href="javascript:window.location.reload();"><?php _e('Reload', 'dc-woocommerce-multi-vendor'); ?></a></td></tr>');
$("#widget_product_sales_report").css("display","none");
}
},
columns: columns
});
new $.fn.dataTable.FixedHeader( product_sales_report_wgt );
});
</script>
Using this code
// To change the default value of `$days_range` from 7 days to 60 days
function lh_wcmp_vendor_custom_sales_report( $days_range ) {
$days_range = 60; // you can adjust days here as you needed
return $days_range;
}
add_filter( 'wcmp_widget_vendor_product_sales_report_days_range', 'lh_wcmp_vendor_custom_sales_report', 10 );
I was able to change the default 7 days to 60. But because I am using the same widget code both the dashboard and the report show the same amount of days.
So, to summerise - what I would like is to show 60 days on the dashboard (using the code above) and then show 365 days on the report page.
Can anyone help?
解决方案 You need to update the code in \basel-child\dc-product-vendor\vendor-dashboard\vendor-orders.php
and \basel-child\functions.php
files.
We are going to add a new query string while making the AJAX request to wcmp_widget_vendor_product_sales_report
function from vendor-orders
endpoint. It will allow us to detect whether the request is coming from Dashboard or Vendor Orders endpoint.
Following code will be added in the vendor-orders.php
file (see line 67-79):
<?php
/* Add 'lh-endpoint' => 'lh-vendor-orders' to the AJAX URL, so we can use it later
* to change the '$days_range' value conditionally. It will change the ajax url from
* /wp-admin/admin-ajax.php?action=wcmp_widget_vendor_product_sales_report to
* /wp-admin/admin-ajax.php?action=wcmp_widget_vendor_product_sales_report&lh-endpoint=lh-vendor-orders
*/
$args = array(
'action' => 'wcmp_widget_vendor_product_sales_report',
'lh-endpoint' => 'lh-vendor-orders',
);
?>
url : '<?php echo add_query_arg( $args, $WCMp->ajax_url() ); ?>',
Then we will modify our old lh_wcmp_vendor_custom_sales_report()
function in functions.php
file as:
// get the value of 'lh-endpoint' from URL
$lh_orders_endpoint = isset( $_GET['lh-endpoint'] ) && !empty( $_GET['lh-endpoint'] ) ? $_GET['lh-endpoint'] : '';
// check if 'lh-endpoint' value is 'lh-vendor-orders' or not
if ( 'lh-vendor-orders' !== $lh_orders_endpoint ) {
$days_range = 60; // if 'lh-endpoint' is not 'lh-vendor-orders', then show last 2 months orders
} else {
$days_range = 365; // if 'lh-endpoint' is 'lh-vendor-orders', then show orders from 1 year
}
Here is the complete code for both files:
- Remove the existing code from
vendor-orders.php
file and put this code:
<?php
/*
* The template for displaying vendor orders
* Override this template by copying it to yourtheme/dc-product-vendor/vendor-dashboard/vendor-orders.php
*
* @author WC Marketplace
* @package WCMp/Templates
* @version 3.0.0
*/
if (!defined('ABSPATH')) {
// Exit if accessed directly
exit;
}
global $WCMp;
$product_sales_report_table_headers = apply_filters('wcmp_datatable_widget_product_sales_report_table_headers', array(
'product' => array('label' => __( 'Product', 'dc-woocommerce-multi-vendor' )),
// 'revenue' => array('label' => __( 'Revenue', 'dc-woocommerce-multi-vendor' )),
'unique_purchase'=> array('label' => __( 'Unique Purchases', 'dc-woocommerce-multi-vendor' )),
), get_current_user_id());
?>
<p>This page shows all your designs that have sold over the past year.</p>
<table id="widget_product_sales_report" class="table table-striped product_sold_last_week table-bordered wcmp-widget-dt" width="100%">
<thead>
<tr>
<?php
if($product_sales_report_table_headers) :
foreach ($product_sales_report_table_headers as $key => $header) { ?>
<th class="<?php if(isset($header['class'])) echo $header['class']; ?>"><?php if(isset($header['label'])) echo $header['label']; ?></th>
<?php }
endif;
?>
<!--th><?php _e('Product', 'dc-woocommerce-multi-vendor'); ?></th>
<th><?php _e('Revenue', 'dc-woocommerce-multi-vendor'); ?></th>
<th><?php _e('Unique Purchases', 'dc-woocommerce-multi-vendor'); ?></th-->
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
jQuery(document).ready(function($) {
var product_sales_report_wgt;
var columns = [];
<?php if($product_sales_report_table_headers) {
foreach ($product_sales_report_table_headers as $key => $header) { ?>
obj = {};
obj['data'] = '<?php echo esc_js($key); ?>';
obj['className'] = '<?php if(isset($header['class'])) echo esc_js($header['class']); ?>';
columns.push(obj);
<?php }
} ?>
product_sales_report_wgt = $('#widget_product_sales_report').DataTable({
ordering : true,
paging: true,
info: true,
searching : true,
processing: true,
serverSide: true,
responsive: true,
language: {
"emptyTable": "<?php echo trim(__('Not enough data.','dc-woocommerce-multi-vendor')); ?>",
"zeroRecords": "<?php echo trim(__('Not enough data.','dc-woocommerce-multi-vendor')); ?>",
},
ajax:{
<?php
/* Add 'lh-endpoint' => 'lh-vendor-orders' to the AJAX URL, so we can use it later
* to change the '$days_range' value conditionally. It will change the ajax url from
* /wp-admin/admin-ajax.php?action=wcmp_widget_vendor_product_sales_report to
* /wp-admin/admin-ajax.php?action=wcmp_widget_vendor_product_sales_report&lh-endpoint=vendor-orders
*/
$args = array(
'action' => 'wcmp_widget_vendor_product_sales_report',
'lh-endpoint' => 'lh-vendor-orders',
);
?>
//url : '<?php //echo add_query_arg( 'action', 'wcmp_widget_vendor_product_sales_report', $WCMp->ajax_url() ); ?>',
url : '<?php echo add_query_arg( $args, $WCMp->ajax_url() ); ?>',
type: "post",
error: function(xhr, status, error) {
$("#widget_product_sales_report tbody").append('<tr class="odd"><td valign="top" colspan="<?php if(is_array($product_sales_report_table_headers)) count($product_sales_report_table_headers); ?>" class="dataTables_empty" style="text-align:center;">'+error+' - <a href="javascript:window.location.reload();"><?php _e('Reload', 'dc-woocommerce-multi-vendor'); ?></a></td></tr>');
$("#widget_product_sales_report").css("display","none");
}
},
columns: columns
});
new $.fn.dataTable.FixedHeader( product_sales_report_wgt );
});
</script>
- In your
functions.php
file, replace the old lh_wcmp_vendor_custom_sales_report()
function with the new one:
// Conditionally change the default value of `$days_range` from 7 days to 60 or 365 days
function lh_wcmp_vendor_custom_sales_report( $days_range ) {
// get the value of 'lh-endpoint' from URL
$lh_orders_endpoint = isset( $_GET['lh-endpoint'] ) && !empty( $_GET['lh-endpoint'] ) ? $_GET['lh-endpoint'] : '';
// check if 'lh-endpoint' value is 'lh-vendor-orders' or not
if ( 'lh-vendor-orders' !== $lh_orders_endpoint ) {
$days_range = 60; // if 'lh-endpoint' is not 'lh-vendor-orders', then show last 2 months orders
} else {
$days_range = 365; // if 'lh-endpoint' is 'lh-vendor-orders', then show orders from 1 year
}
return $days_range;
}
add_filter( 'wcmp_widget_vendor_product_sales_report_days_range', 'lh_wcmp_vendor_custom_sales_report' );
See the screenshots of locally hacked version of WC Marketplace plugin:
wcmp_widget_vendor_product_sales_report
call from Vendor Dashboard
wcmp_widget_vendor_product_sales_report
call from Vendor Orders Tab
Tested and working on:
- WordPress 5.0.3
- Twentyninteen 1.2
- WooCommerce 3.5.4
- WC Marketplace 3.3.1
- Localhost (XAMPP for Windows 5.6.15)
这篇关于WC 市场销售报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆