Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
81 stars 29 forks source link

With HPOS enabled + syncing, `wcs_get_subscription_orders()` returns an empty list when querying for parent orders #448

Closed mattallan closed 8 months ago

mattallan commented 1 year ago

Describe the bug

Our wcs_get_subscription_orders() function still contains the following code that is incompatible with stores with HPOS enabled and not syncing to WP Posts table:

if ( $any_order_type || in_array( 'parent', $order_type ) ) {
    $order_ids = array_merge( $order_ids, $wpdb->get_col(
        "SELECT DISTINCT post_parent FROM {$wpdb->posts}
            WHERE post_type = 'shop_subscription'
            AND post_parent <> 0"
    ) );
}

Note that this function is still querying the {$wpdb->posts} table for post parents 🙈

To Reproduce

  1. Go to WooCommerce > Settings > Advanced and enable High-Performance order storage (COT)
  2. Go to the Custom data stores tab under Advanced settings and switch your store to Order Tables.
  3. Disable the "Keep the posts table and the orders tables synchronized" option
  4. Purchase a new subscription
  5. Run the following snippet wcs_get_subscription_orders( 'ids' ); and notice the new parent order is not returned.

Expected behavior

Actual behavior

Product impact

mattallan commented 8 months ago

Closed by #474