【发布时间】:2023-03-16 20:08:01
【问题描述】:
我已经注册了以下 woocommerce 钩子:
add_action('woocommerce_update_order', 'some_func', 300, 2);
function some_func($order_id, $order){
// ...
}
但是,我有几个问题:
这会在更新订单时多次触发,而不是仅在最后触发。它使用旧命令触发两次,一次触发一次。
我还尝试了以下方法:
add_action('woocommerce_update_order', 'some_func', 300, 2);
function some_func($order_id, $order){
remove_action('woocommerce_update_order', 'some_func');
// ...
}
这也不会改变它。
另外,我尝试修改 remove_action 以包含优先级和参数计数,例如:
add_action('woocommerce_update_order', 'some_func', 300, 2);
function some_func($order_id, $order){
remove_action('woocommerce_update_order', 'some_func', 300, 2);
// ...
}
现在,它确实只触发一次,但它给了我旧的命令而不是新更新的命令。
我正在使用 WooCommerce 3.7.0。
关于如何在更新后仅准确触发钩子一次获得最新版本的订单有什么建议?
谢谢!
【问题讨论】:
标签: wordpress woocommerce hook-woocommerce