PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / trunk
WCPOS – Point of Sale (POS) plugin for WooCommerce vtrunk
1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 1.9.12 1.9.11 1.9.10 All 159 releases
woocommerce-pos / includes / Sync / Order_Modified_Date.php

Order_Modified_Date.php in WCPOS – Point of Sale (POS) plugin for WooCommerce trunk, at includes/Sync/Order_Modified_Date.php

48 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Order post-date touch for meta-only CPT saves.
4 *
5 * @package WCPOS\WooCommercePOS\Sync
6 */
7
8 namespace WCPOS\WooCommercePOS\Sync;
9
10 use Automattic\WooCommerce\Utilities\OrderUtil;
11
12 /**
13 * Advance stale CPT order post dates after meta-only saves.
14 * HPOS already advances its own date_updated_gmt on persistence.
15 */
16 class Order_Modified_Date {
17 /**
18 * Advance an order's post_modified(_gmt) beyond its previous value.
19 *
20 * @param int $order_id The order post ID.
21 */
22 public static function touch( int $order_id ): void {
23 if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) {
24 return;
25 }
26 global $wpdb;
27
28 $previous_gmt = (string) get_post_field( 'post_modified_gmt', $order_id );
29 $modified_gmt = gmdate(
30 'Y-m-d H:i:s',
31 max( time(), strtotime( $previous_gmt . ' UTC' ) + 1 )
32 );
33
34 $wpdb->update(
35 $wpdb->posts,
36 array(
37 'post_modified' => get_date_from_gmt( $modified_gmt ),
38 'post_modified_gmt' => $modified_gmt,
39 ),
40 array( 'ID' => $order_id ),
41 array( '%s', '%s' ),
42 array( '%d' )
43 );
44
45 clean_post_cache( $order_id );
46 }
47 }
48