[英]Add order_id beneath custom Woocommerce Order Number on Edit Order page
We use the Booster plugin which creates a unique WooCommerce order number such as WC-456544646.我们使用 Booster 插件创建一个唯一的 WooCommerce 订单号,例如 WC-456544646。 I now need to add the original order_id which still works in the background and with the WooCommerce API.
我现在需要添加在后台和 WooCommerce API 中仍然有效的原始 order_id。
Booster provides a shortcode for the original order ID [wcj_order_id]
Booster 为原始订单 ID
[wcj_order_id]
提供了一个简码
Here is the HTML for the custom Woo order number on the Edit Order page.这是“编辑订单”页面上自定义 Woo 订单号的 HTML。
<h2 class="woocommerce-order-data__heading">
Order #WC-63872414 details</h2>
How can I insert a shortcode onto the 'Edit Order' page?如何在“编辑订单”页面上插入短代码?
(Woocommerce/Orders/[Select Order/Order Details] eg /post.php?post=638&action=edit
(Woocommerce/Orders/[选择订单/订单详情] 例如
/post.php?post=638&action=edit
I looked into Booster plugin code.我查看了 Booster 插件代码。 It uses
woocommerce_order_number
filter hook to replace the order ID in WC edit order page and orders.它使用
woocommerce_order_number
过滤器钩子来替换 WC 编辑订单页面和订单中的订单 ID。 In /woocommerce-jetpack/includes/class-wcj-order-numbers.php
:在
/woocommerce-jetpack/includes/class-wcj-order-numbers.php
:
add_filter( 'woocommerce_order_number', array( $this, 'display_order_number' ), PHP_INT_MAX, 2 );
Since it's not passing the $instance of neither WCJ_Order_Numbers
nor WC_Jetpack
classes in any action hook, in order to remove this text and use a custom one, we can not use remove_filter
function.由于它没有在任何动作挂钩中传递
WCJ_Order_Numbers
和WC_Jetpack
类的 $instance,为了删除此文本并使用自定义文本,我们不能使用remove_filter
函数。 So to override Booster plugin, we have to hook another function to woocommerce_order_number
.因此,要覆盖 Booster 插件,我们必须将另一个函数挂接到
woocommerce_order_number
。
To add WC order_id to admin order pages:将 WC order_id 添加到管理订单页面:
add_action( 'admin_init', 'append_wc_order_id');
function append_wc_order_id()
{
add_filter('woocommerce_order_number', 'filter_wc_order_id', PHP_INT_MAX);
function filter_wc_order_id($order_id)
{
/* If you are using 'init' action hook, uncomment bellow line to apply this code only to your admin pages: */
//if (!is_admin()) return $order_id;
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
}
}
This code goes to your functions.php
file of your theme.此代码转到您的主题的
functions.php
文件。
Tested & Wordking :测试 & Wordking :
Notes:笔记:
1. The filter hook in the Booster code, uses PHP_INT_MAX
priority so in order to override this, we can not use bigger integer priority. 1. Booster 代码中的过滤器钩子,使用
PHP_INT_MAX
优先级,所以为了覆盖它,我们不能使用更大的整数优先级。 Therefore I used admin_init
action to hook my function to woocommerce_order_number
, after other plugins done their job.因此,在其他插件完成工作后,我使用
admin_init
操作将我的函数挂接到woocommerce_order_number
。 It may function as you expected, without using init hooks, but it's not guaranteed.它可能会按您的预期运行,无需使用 init 钩子,但不能保证。 You can use
init
hook instead of admin_init
to add the WC order_id on the front-end side of your site too (eg 'My Account' page).您也可以使用
init
hook 而不是admin_init
在站点的前端添加 WC order_id(例如“我的帐户”页面)。 Read the comments inside the code.阅读代码中的注释。
2. To remove the order ID generated by Booster plugin on admin pages, you may change this line: 2. 要删除管理页面上 Booster 插件生成的订单 ID,您可以更改此行:
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
to:到:
return do_shortcode('[wcj_order_id]');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.