我查看了 Booster 插件代码。它使用woocommerce_order_number过滤钩子替换WC编辑订单页面和订单中的订单ID。在/woocommerce-jetpack/includes/class-wcj-order-numbers.php:
add_filter( 'woocommerce_order_number', array( $this, 'display_order_number' ), PHP_INT_MAX, 2 );
由于它没有在任何动作挂钩中传递WCJ_Order_Numbers 和WC_Jetpack 类的$instance,为了删除此文本并使用自定义文本,我们不能使用remove_filter 函数。因此,要覆盖 Booster 插件,我们必须将另一个函数挂钩到 woocommerce_order_number。
将 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]');
}
}
此代码将转到您主题的 functions.php 文件。
经过测试和文字王:
注意事项:
1. Booster 代码中的过滤器挂钩,使用PHP_INT_MAX 优先级,所以为了覆盖它,我们不能使用更大的整数优先级。因此,在其他插件完成工作后,我使用admin_init 操作将我的函数挂钩到woocommerce_order_number。它可能会按您的预期运行,而不使用 init 挂钩,但不能保证。您也可以使用init 钩子而不是admin_init 在您网站的前端添加WC order_id(例如“我的帐户”页面)。阅读代码中的 cmets。
2. 要删除管理页面上由Booster插件生成的订单ID,您可以更改此行:
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
到:
return do_shortcode('[wcj_order_id]');