wordpress - WooCommerce 钩子 – woocommerce_update_order 问题
问题描述
我已经注册了以下 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。
关于如何在更新后仅触发一次钩子而获得最新版本的订单的任何建议?
谢谢!
解决方案
add_action( 'save_post', 'my_save_post_function', 10, 3 );
function my_save_post_function( $post_ID, $post, $update ) {
if("shop_order" == $post->post_type){
$msg = 'An order updte fireda';
wp_die( $msg );
}
}
在后置条件内执行您的操作
推荐阅读
- javascript - 使用 PointerLockControl 的三个 js 中的对象未跟随相机第一人称视图
- python - 如何向 docker-compose 项目 (DJANGO) 的 Pipfile 添加额外的 python 包?
- c# - 如何让 RestSharp 请求像浏览器请求一样?
- ios - 在 React Native 模块中将 Swift 类导入 Obj-C
- javascript - 如何在 mocha 测试中使用“do while”
- java - 多线程读取文件csv并使用spring批处理更新/更新mongodb
- python - 获取变量的延迟输出
- html - 如何将表格中的文本对齐到水平和垂直居中
- c# - C# .NET 从另一个(大)流的一部分制作 GZipStream
- javascript - 如何放一个