How do I apply this WordPress filter?

2019-08-19 08:18发布

问题:

I need help to apply this WordPress filter...

apply_filters( ‘wcmp_widget_vendor_product_sales_report_days_range’, 7, $requestData, $vendor );

This filter is what has been provided to me by the plugin makers (WC Marketplace) - all they said was "in order to display product sold over 60 days, you have to do custom code. For this use this filter apply_filters( ‘wcmp_widget_vendor_product_sales_report_days_range’, 7, $requestData, $vendor ); and change the value change 7 to 60."

I am new to WordPress coding and am not sure how to go about applying this filter. The only reference to this filter in their plugins code is in this file https://github.com/dualcube/dc-woocommerce-multi-vendor/blob/master/classes/class-wcmp-ajax.php on line 2905.

Any help would be great. I have already looked in the WordPress references but I am clueless.

回答1:

Use this code in your theme's functions.php file:

// 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 );

Though I don't have data to test it, but I am sure it will work for you.



标签: wordpress