Ecommerce Shopify WordPress Discussion

How to Programmatically Retrieve Last Modified Time of Products in WooCommerce [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed yesterday. This post was edited and submitted for review 12 hours ago. Improve this question I'm working with WooCommerce (v8.2.0) in WordPress and need to track when updates happen to my products. Specifically, I want to programmatically access the last modified time for each product and to know whether it's been updated in last 24 hours or not. It's updated via the Import Products feature with matching SKUs. Products are updated from our POS terminal. Updates include changes in quantity. Need to set a variable $isUpdated to true if at least X products are updated. I've gone through the WooCommerce documentation but haven't found a clear method to retrieve the last modified time for each product. Does WooCommerce offer a built-in feature for this, or is there a recommended approach? To clarify the question itself: How can I programmatically determine if at least X products have been updated in a given time frame, using the last modified time as a criterion? Thank you for any guidance or code examples!
By suggestion made from ChadPhillips within the comments I was able to solve this (because this process of updating these products is using wp_update_post), I did this: function check_if_multiple_products_updated() { $args = array( 'post_type' => 'product', 'posts_per_page' => -1, // Retrieve all products 'fields' => 'ids', // Retrieve only IDs for performance ); $products = get_posts($args); $updated_count = 0; $time_check = strtotime('-24 hours'); // Check for updates within the last 24 hours foreach ($products as $product_id) { $last_modified = get_post_modified_time('U', false, $product_id, true); if ($last_modified > $time_check) { $updated_count++; } } return $updated_count >= 1; // Returns true if 1 or more products were updated in the last 24 hours } And since this code is used within my custom plugin, I am using this function as follows: // Check if at least 1 products were updated in the last 24 hours $isUpdated = check_if_multiple_products_updated(); then later on: $response[] = $product_data + array("isUpdated"=> $isUpdated);

January 20, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.