PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
← All changes | core/integrations/woocommerce/status-mapper.php +26 -2 1.0.62 → 1.0.64 View file →
@@ -117,24 +117,48 @@
117 117
118 118 /**
119 119 * Get the booking ID from WooCommerce order meta
120 120 *
121 + * Reads through the order object so it works with HPOS ( orders stored in their
122 + * own tables ), falling back to post meta for orders written before that.
123 + *
121 124 * @param int $order_id The WooCommerce order ID
122 125 * @return int|false The booking ID or false if not found
123 126 */
124 127 public static function get_booking_id_from_order( $order_id ) {
125 - return get_post_meta( $order_id, '_tt_booking_id', true );
128 + $order = function_exists( 'wc_get_order' ) ? wc_get_order( $order_id ) : false;
129 +
130 + if ( ! $order ) {
131 + return get_post_meta( $order_id, '_tt_booking_id', true );
132 + }
133 +
134 + $booking_id = $order->get_meta( '_tt_booking_id' );
135 +
136 + return $booking_id ? $booking_id : get_post_meta( $order_id, '_tt_booking_id', true );
126 137 }
127 138
128 139 /**
129 140 * Store the booking ID in WooCommerce order meta
130 141 *
142 + * Writes through the order object. With HPOS enabled and post syncing off,
143 + * update_post_meta() would leave the value in a wp_postmeta row that WooCommerce
144 + * itself cannot see.
145 + *
131 146 * @param int $order_id The WooCommerce order ID
132 147 * @param int $booking_id The booking ID
133 148 * @return bool Whether the meta was updated
134 149 */
135 150 public static function set_booking_id_for_order( $order_id, $booking_id ) {
136 - return update_post_meta( $order_id, '_tt_booking_id', $booking_id );
151 + $order = function_exists( 'wc_get_order' ) ? wc_get_order( $order_id ) : false;
152 +
153 + if ( ! $order ) {
154 + return update_post_meta( $order_id, '_tt_booking_id', $booking_id );
155 + }
156 +
157 + $order->update_meta_data( '_tt_booking_id', $booking_id );
158 + $order->save();
159 +
160 + return true;
137 161 }
138 162
139 163 /**
140 164 * Check if a booking-order pair is currently being synced