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 fromvendor-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):Then we will modify our old
lh_wcmp_vendor_custom_sales_report()
function in functions.php
file as:Here is the complete code for both files:
vendor-orders.php
file and put this code:functions.php
file, replace the oldlh_wcmp_vendor_custom_sales_report()
function with the new one:See the screenshots of locally hacked version of WC Marketplace plugin:
wcmp_widget_vendor_product_sales_report
call from Vendor Dashboardwcmp_widget_vendor_product_sales_report
call from Vendor Orders TabTested and working on: