Last active
February 10, 2019 00:32
-
-
Save logichub/c1bfa144f4503d4515b6a01de49c8ce3 to your computer and use it in GitHub Desktop.
Conditionally change the default value of `$days_range` from 7 days to 60 or 365 days on the Vendor Dashboard in WC Marketplace plugin - Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* See this link: https://gist.github.com/logichub/047b0e785bedbc076a8374f95d60b044 | |
* after creating this file in your child theme as mentioned below: | |
*/ | |
/* | |
* 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See part 2 here.