最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

WooCommerce HPOS Need to Get Order Item Product ID Offsite w mysql - Stack Overflow

programmeradmin2浏览0评论

The site is fully HPOS.

I'm writing a standalone code outside WP/Woo to update a custom order meta field (in wp_wc_orders_meta) for thousands of orders. It'll run once, so it's outside Woo/WP and won't use hooks, filters, or the item object.

The order ids and respective order item ids are known for the orders that need the data updated.

I need to get the order item product id and can't find it in the HPOS order tables. It's in HPOS incompatible tables, wp_woocommerce_order_itemmeta and wp_wc_order_product_lookup (Recent order items are not in those tables.).

I could get wp_woocommerce_order_items > order_item_name and look for that in wp_posts > post_title, but the name may have changed since the order was placed and would not return the correct result if at all.

Are the HPOS-compatible tables where I can trace to get the product id for the order items?

The site is fully HPOS.

I'm writing a standalone code outside WP/Woo to update a custom order meta field (in wp_wc_orders_meta) for thousands of orders. It'll run once, so it's outside Woo/WP and won't use hooks, filters, or the item object.

The order ids and respective order item ids are known for the orders that need the data updated.

I need to get the order item product id and can't find it in the HPOS order tables. It's in HPOS incompatible tables, wp_woocommerce_order_itemmeta and wp_wc_order_product_lookup (Recent order items are not in those tables.).

I could get wp_woocommerce_order_items > order_item_name and look for that in wp_posts > post_title, but the name may have changed since the order was placed and would not return the correct result if at all.

Are the HPOS-compatible tables where I can trace to get the product id for the order items?

Share Improve this question edited Jan 18 at 23:01 Shadow 34.2k10 gold badges63 silver badges74 bronze badges asked Jan 18 at 22:34 CatsyCatsy 291 silver badge6 bronze badges 7
  • Order item data is located in the following database tables wp_wc_order_product_lookup, wp_woocommerce_order_items and wp_woocommerce_order_itemmeta. – LoicTheAztec Commented Jan 19 at 12:03
  • wp_wc_order_product_lookup is not HPOS. The site is totally HPOS and the latest order there was 12/5/24 before the site was switched to totally HPOS. Thus, if these are the only HPOS order item tables, then the correct product_id for the order item for a defined order cannot be read if the product name was changed. It appears that the product_id is not stored per order item for HPOS. – Catsy Commented Jan 20 at 15:48
  • Note that order items are not really impacted by HPOS, only direct order data and metadata are concerned. HPOS uses custom WC tables, so wp_wc_order_product_lookup, wp_woocommerce_order_items and wp_woocommerce_order_itemmeta are custom WC tables that are used by HPOS. – LoicTheAztec Commented Jan 20 at 16:12
  • As far as I see it, there's no way to get the product_id for the order items, only the product_name. Do you see a way to get the product_id for the order item? Merci. – Catsy Commented Jan 21 at 20:52
  • Could you provide in your question some related code attempt? It's difficult to guess how you are managing things. Did you try using wp_wc_order_product_lookup DB table? – LoicTheAztec Commented Jan 22 at 8:44
 |  Show 2 more comments

1 Answer 1

Reset to default 0

I found it. We had the WP/Woo cron disabled and enabled the cron in our server less often (There were many server spikes since some WP/Woo cron runs with every page load.). After enabling it again to run through WP/Woo and going to the order edit page, it will then save to the table. sigh.

If the spikes return, we'll need to figure out how to get this table working with the WP/Woo crons running on our server.

发布评论

评论列表(0)

  1. 暂无评论