Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Last active April 14, 2022 20:59
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bryceadams/050d886159265d6f5e6dbce649552704 to your computer and use it in GitHub Desktop.
Disable WooCommerce total spent / order count meta calculations
<?php
add_filter( 'get_user_metadata', 'mtkdocs_filter_user_metadata', 10, 4 );
function mtkdocs_filter_user_metadata( $value, $object_id, $meta_key, $single ) {
// Check if it's one of the keys we want to filter
if ( in_array( $meta_key, array( '_money_spent', '_order_count' ) ) ) {
// Return 0 so WC doesn't try calculate it
return 0;
}
// Default
return $value;
}
@JVDL-1
Copy link

JVDL-1 commented Feb 1, 2021

@bryceadams Thank you so much for this snippet. So much speed improvement for retrieving orders by our shipping partner. It would calculate total spend and order count for each order. Went from 100 orders in 5 minutes to about 30 sec!

Got a question, does the WooCommerce Analytics dashboard still works for total order count and total spent?
https://docs.woocommerce.com/document/woocommerce-analytics/#customers-report

Random picked some customers to check if the numbers still matched, which they seem to do. So that would indicate that WooCommerce Analytics dashboard does its own calculations. Is this right? Or did the snippet only disable the function partially?

@bryceadams
Copy link
Author

@JVDL-1 great to hear! :) No idea how the WC Analytics dashboard works / calculates numbers so I'd recommend testing thoroughly on your end to be sure. If needed, you could probably adjust the code to only run when your shipping partner gets the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment