我有一个包含以下代码的页面,该代码是从仪表板复制的。这意味着此特定小部件现在显示在两个位置。在帮助下,我设法将此报告显示的天数增加到60天,但是我只希望仪表板版本显示60天,而我希望此版本显示365天。
<?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>
使用此代码
// 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 );
我能够将默认的7天更改为60天。但是,因为我使用的是相同的小部件代码,因此仪表板和报告显示的天数相同。
因此,总结一下-我想要在仪表板上显示60天(使用上面的代码),然后在报告页面上显示365天。
有人可以帮忙吗?
答案 0 :(得分:0)
您需要更新\basel-child\dc-product-vendor\vendor-dashboard\vendor-orders.php
和\basel-child\functions.php
文件中的代码。
我们将在从wcmp_widget_vendor_product_sales_report
端点向vendor-orders
函数发出AJAX请求的同时添加新的查询字符串。它将使我们能够检测到该请求是来自仪表板端点还是供应商订单端点。
以下代码将添加到vendor-orders.php
文件中(请参见第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() ); ?>',
然后,我们将旧的lh_wcmp_vendor_custom_sales_report()
function in functions.php
文件修改为:
// 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
}
这是两个文件的完整代码:
vendor-orders.php
文件中删除现有代码,并放置以下代码:<?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>
functions.php
文件中,将旧的lh_wcmp_vendor_custom_sales_report()
函数替换为新的函数:// 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' );
查看WC Marketplace插件在本地被黑客入侵的版本的屏幕截图:
来自供应商信息中心的 wcmp_widget_vendor_product_sales_report
通话
wcmp_widget_vendor_product_sales_report
来自“供应商订单”标签的呼叫
经过测试并正在研究: