With the following shortcode I am trying to get user total spent amount, but it is slowing page load (6 seconds).
Is it possible to optimize this code to shorten the loading time?
add_shortcode('woo-total-completed', 'get_user_total_completed');
function get_user_total_completed() {
$total_amount = 0; // Init
$total_completed_orders = wc_get_orders( array(
'limit' => -1,
'status' => 'wc-completed',
) );
foreach( $total_completed_orders as $order) {
$total_amount += $order;
}
return $total_amount;
}