fbpx

Feature Requests

Got an idea for a new feature or integration? We’d love to hear it! You can find our roadmap here.

1 vote

Update WooCommerce Order Count & Total Spend Meta Fields

WooCommerce has two incredibly valuable meta data fields however they’re not actively updated by WooCommerce Core – wc_order_count and wc_money_spent. (Both work for multi-sites so the actual meta key uses a suffix depending on the website’s DB suffix; e.g. wc_order_count_wp/wc_money_spent_wp) The meta fields are super valuable as we could run loyalty campaigns based on customer’s lifetime spend/order count through the CRM – in my client’s case Klaviyo. WooCommerce Core doesn’t actually update those values (for reasons beyond me) but some plugins such as WebToffee Import/Export do through their own actions/hooks, e.g. in this case when initiating the export of a customer list. We can install a custom snippet on the site to add the wc_get_customer_total_spent and wc_get_customer_order_count actions on the thank you page but I also think it would be a great addition to your plugin to have that option somewhere in the settings. Could maybe be something that runs at intervals during the day so that the checkout isn’t slowed down, or when user meta is updated and sent to the CRM? Below is the snippet that the WooCommerce team sent to attach the action to the thank you page (haven’t tested this). add_action( ‘woocommerce_thankyou’, ‘update_mycustom_user_data’, 10, 1 ); function update_mycustom_user_data( $order_id ){ // First we get an instance of the WC_Order Object from the Order ID $order = wc_get_order( $order_id ); if( empty( $order )){ return; } // then we can get the User ID $user_id = $order->get_user_id(); $total = wc_get_customer_total_spent( $user_id ); $count = wc_get_customer_order_count( $user_id ); }

Completed Category: Plugin Integration Enhancements Robert Hemsing shared this idea Updated: November 4, 2024

2 thoughts on “Update WooCommerce Order Count & Total Spend Meta Fields”

  1. Hmm. Ok. Sure. Since Woo has core methods for calculating them, I suppose it makes sense to add them for sync.

    We’ll include wc_order_count and wc_money_spent with the next update 👍

    If they’re enabled, the values will be calculated using those functions whenever a customer is synced to the CRM.

Leave a Comment

Your email address will not be published. Required fields are marked *