使用 HPOS 过滤 WooCommerce 中的订单列表

Sco*_*t L 4 php wordpress orders woocommerce hook-woocommerce

我正在将开源插件转换为 HPOS 兼容。其功能之一是管理中订单列表上的附加过滤器(与订单状态一致),例如: 例子

我似乎无法实际执行查询的修改。pre_get_posts以前,当不再使用 WP_Post 时,我正在挂钩显然不再相关。

然后对于过滤器字段也是如此,我将其挂接到restrict_manage_posts. 找到了等效的钩子:woocommerce_order_list_table_restrict_manage_orders

有人知道要使用哪个钩子吗?

Loi*_*tec 5

高性能订单存储文档中,有一个指向高性能订单存储升级食谱书的链接,您可以在其中找到您正在查找的相关核心文件的路径。

\n

在本文档中,您拥有:

\n
use Automattic\\WooCommerce\\Internal\\DataStores\\Orders\\CustomOrdersTableController;\n
Run Code Online (Sandbox Code Playgroud)\n

指向woocommerce/src/Internal/DataStores/Orders,其中OrdersTableQuery.phpfile是要查看的正确位置。

\n

maybe_override_query()在第 233 行的方法中:

\n
$pre_query = apply_filters( \'woocommerce_hpos_pre_query\', null, $this, $this->sql );\n
Run Code Online (Sandbox Code Playgroud)\n

build_query()在第 877 行的方法中:

\n
$clauses = (array) apply_filters_ref_array( \'woocommerce_orders_table_query_clauses\', array( $pieces, &$this, $this->args ) );\n
Run Code Online (Sandbox Code Playgroud)\n

依此类推\xe2\x80\xa6

\n

WC_Order_Query用于查询 HPOS 订单时,以下过滤器应该仍然有效:

\n
    \n
  • woocommerce_order_query_args过滤钩(替换pre_get_posts),
  • \n
  • woocommerce_order_query过滤钩(替换pre_get_posts),
  • \n
  • 并且可以尝试woocommerce_order_data_store_cpt_get_orders_query过滤钩。
  • \n
\n

对于restrict_manage_posts现在的钩子,您将使用:
\nwoocommerce_order_list_table_restrict_manage_orders

\n
其他一些用 HPOS 替换钩子:
\n
    \n
  • 要编辑现有列或将自定义列添加到管理订单列表:

    \n
      \n
    • manage_woocommerce_page_wc-orders_columns替换钩子:
      \nmanage_edit-shop_order_columns
    • \n
    • manage_woocommerce_page_wc-orders_custom_column替换钩子:
      \nmanage_shop_order_posts_custom_column
    • \n
    \n
  • \n
  • 要使自定义订单元数据可在管理订单列表中搜索,请使用:

    \n
      \n
    • woocommerce_order_table_search_query_meta_keys更换钩子:
      \nwoocommerce_shop_order_search_fields
    • \n
    \n
  • \n
  • 对于管理订单列表中的批量操作:

    \n
      \n
    • bulk_actions-woocommerce_page_wc-orders替换钩子:
      \nbulk_actions-edit-shop_order
    • \n
    • handle_bulk_actions-woocommerce_page_wc-orders有 2 个参数$column并且$orderand 替换钩子\nhandle_bulk_actions-edit-shop_order
    • \n
    \n
  • \n
\n


mor*_*ter 5

我最初评论了一个问题,但删除了它,因为我对删除线的理解不正确。我虽然你写的woocommerce_order_list_table_restrict_manage_orders是 的替代钩子pre_get_posts

对于具有类似低阅读理解能力的其他人,管理订单页面的更新挂钩是:

老的 新的
pre_get_posts woocommerce_order_query_args
restrict_manage_posts woocommerce_order_list_table_restrict_manage_orders
manage_edit-shop_order_columns manage_woocommerce_page_wc-orders_columns
manage_shop_order_posts_custom_column manage_woocommerce_page_wc-orders_custom_column
bulk_actions-edit-shop_order bulk_actions-woocommerce_page_wc-orders
handle_bulk_actions-edit-shop_order handle_bulk_actions-woocommerce_page_wc-orders

我还包括了其他一些我很难找到的内容,主要是因为get_current_screen()->id管理订单表已更改。