WooCommerce: Making sure updated data gets synced to Metorik

You can read about how Metorik syncs data in the help doc here. When it comes to updated data, eg. an order or customer's information being updated, there are two ways it will try to sync the data to Metorik:

1. Webhooks: WooCommerce will try to send Metorik a message saying "this order or this customer was updated".

For WooCommerce to execute the webhook you would add the code 

do_action('woocommerce_update_order', $order->get_id(), $order);

2. Background syncing: Metorik checks to see if its version of the order/customer/etc is 'out of date' compared to WooCommerce's version, and if it, it will update it.

Both of the above may fail due to a number of reasons. Mainly, when you've got some custom code updating data but not triggering a webhook / changing the 'last modified' date.

To ensure that Metorik is aware of updates, you should update the order/customer/etc. 'last modified' date.

For orders, subscriptions, and products:

This is usually done by setting the post_modified and post_modified_gmt dates:

$post = array(
    'ID' => 123,
    'post_modified' => current_time( 'Y:m:d H:i:s' ),
    'post_modified_gmt' => current_time( 'Y:m:d H:i:s', 1 ),
);
wp_update_post( $post );

For customers:

There are two options here. The easiest would be using WooCommerce's built-in function for this:

$customer_id = 123;
wc_set_user_last_update_time( $customer_id );

Alternatively, you can update the user custom meta with a timestamp:

$customer_id = 123;
update_user_meta( $customer_id, 'last_update', time() );

Be sure to dynamically get the Post IDs above (they are set to 123 in the example code) and test the code thoroughly.

If you need help with this, just let us know through the app's support.

Still need help? Contact Us Contact Us