Plugin Directory

Changeset 3486829


Ignore:
Timestamp:
03/19/2026 09:12:33 PM (9 days ago)
Author:
routedev
Message:

Fix order sync compatibility with HPOS and legacy storage

Location:
routeapp/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • routeapp/trunk/admin/class-routeapp-order-recover.php

    r3142452 r3486829  
    100100     */
    101101    private function getOrdersBatch($batchSize, $offset, $recoverTo, $recoverFrom) {
    102         $args = [
    103           'limit' => $batchSize,
    104           'offset' => $offset,
    105           'date_created' => '>=' . $recoverFrom,
    106           'date_created' => '<=' . $recoverTo,
    107         ];
    108 
    109         return wc_get_orders($args);
     102        $args = array(
     103            'limit'        => (int) $batchSize,
     104            'offset'       => (int) $offset,
     105            'type'         => 'shop_order',
     106            'date_created' => $recoverFrom . '...' . $recoverTo,
     107        );
     108
     109        return wc_get_orders( $args );
    110110    }
    111111
     
    143143    public function updateOrderPostMeta($orders) {
    144144        foreach ($orders as $order) {
    145             if (!get_post_meta( $order->get_id(), '_routeapp_order_id')) {
     145            $has_route_meta = method_exists( $order, 'get_meta' )
     146                ? $order->get_meta( '_routeapp_order_id' )
     147                : get_post_meta( $order->get_id(), '_routeapp_order_id', true );
     148            if ( ! $has_route_meta ) {
    146149                //check if order exists on Route side
    147150                $getOrderResponse = Routeapp_API_Client::getInstance()->get_order($order->get_id());
     
    156159    /**
    157160     * Get the count of orders based on the specified date range.
    158      *
    159      * @param string $from Starting date for the orders.
    160      * @param string $to Ending date for the orders.
     161     * Supports both High-performance order storage (HPOS) and WordPress posts storage (legacy).
     162     *
     163     * @param string $from Starting date for the orders (YYYY-MM-DD).
     164     * @param string $to Ending date for the orders (YYYY-MM-DD).
    161165     * @return int The count of orders.
    162166     */
     
    164168        global $wpdb;
    165169
    166         $query = "
    167                 SELECT COUNT(1)
     170        $from_date = $from . ' 00:00:00';
     171        $to_date   = $to . ' 23:59:59';
     172
     173        if ( $this->is_hpos_enabled() ) {
     174            // High-performance order storage: query wc_orders table
     175            $orders_table = $wpdb->prefix . 'wc_orders';
     176            $from_gmt     = get_gmt_from_date( $from_date );
     177            $to_gmt       = get_gmt_from_date( $to_date );
     178
     179            $query = $wpdb->prepare(
     180                "SELECT COUNT(1)
     181                FROM {$orders_table} AS orders
     182                WHERE orders.type = 'shop_order'
     183                AND orders.status NOT IN ( 'wc-auto-draft', 'auto-draft', 'trash' )
     184                AND orders.date_created_gmt >= %s
     185                AND orders.date_created_gmt <= %s",
     186                $from_gmt,
     187                $to_gmt
     188            );
     189        } else {
     190            // WordPress posts storage (legacy): query wp_posts
     191            $query = $wpdb->prepare(
     192                "SELECT COUNT(1)
    168193                FROM {$wpdb->posts} AS posts
    169                 WHERE posts.post_type = 'shop_order_placehold'
     194                WHERE posts.post_type = 'shop_order'
     195                AND posts.post_status NOT IN ( 'wc-auto-draft', 'auto-draft', 'trash' )
    170196                AND posts.post_date >= %s
    171                 AND posts.post_date <= %s
    172             ";
    173 
    174         $prepared_query = $wpdb->prepare($query, $from, $to);
    175         $order_count = $wpdb->get_var($prepared_query);
    176 
    177         return $order_count;
     197                AND posts.post_date <= %s",
     198                $from_date,
     199                $to_date
     200            );
     201        }
     202
     203        return (int) $wpdb->get_var( $query );
     204    }
     205
     206    /**
     207     * Check if High-performance order storage (HPOS) is enabled.
     208     *
     209     * @return bool True if HPOS is enabled, false otherwise.
     210     */
     211    private function is_hpos_enabled() {
     212        if ( ! class_exists( 'Automattic\WooCommerce\Utilities\OrderUtil' ) ) {
     213            return false;
     214        }
     215        return \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled();
    178216    }
    179217
  • routeapp/trunk/readme.txt

    r3486821 r3486829  
    66Requires at least: 4.0
    77Tested up to: 6.7.1
    8 Stable tag: 2.3.1
     8Stable tag: 2.3.2
    99Requires PHP: 5.6
    1010License: GPLv2 or later
     
    106106
    107107== Changelog ==
     108
     109= 2.3.2 =
     110* Fix order sync compatibility with HPOS and legacy storage
    108111
    109112= 2.3.1 =
  • routeapp/trunk/routeapp.php

    r3486821 r3486829  
    1010 * Plugin URI:        https://route.com/for-merchants/
    1111 * Description:       Route allows shoppers to insure their orders with one-click during checkout, adding a layer of 3rd party trust while improving the customer shopping experience.
    12  * Version:           2.3.1
     12 * Version:           2.3.2
    1313 * Author:            Route
    1414 * Author URI:        https://route.com/
     
    2626 * Currently plugin version.
    2727 */
    28 define( 'ROUTEAPP_VERSION', '2.3.1' );
     28define( 'ROUTEAPP_VERSION', '2.3.2' );
    2929
    3030/**
Note: See TracChangeset for help on using the changeset viewer.