php - Biiling 表单完成后,支付网关之前的 WooCommerce Hook
问题描述
在 Woocommerce 中,我需要在客户端完成计费表单之后、支付网关之前调用一个函数。此功能需要使用计费表单信息...是否有一个 Hook ?
我试图这样做:
add_action( 'woocommerce_order_status_changed', 'create_contact_and_deal', 10, 1 );
function create_contact_and_deal($order_id=0, $status_transition_from="", $status_transition_to="", $instance=NULL) { ...
但是当我完成计费表格时没有调用该函数..
解决方案
设置 add_action 时缺少参数。
add_action( 'woocommerce_order_status_changed', 'create_contact_and_deal', 10, 1 );
function create_contact_and_deal($order_id=0, $status_transition_from="", $status_transition_to="", $instance=NULL) {
}
应该:
function action_woocommerce_order_status_changed( $this_get_id, $this_status_transition_from, $this_status_transition_to, $instance ) {
// make action magic happen here...
if($this_status_transition_from == "pending" && $this_status_transition_to == "processing")
//Perform stuff when condition is met.
{
}
// add the action
add_action( 'woocommerce_order_status_changed', 'action_woocommerce_order_status_changed', 10, 4 );
最重要的部分是add_action
函数的第四个参数。,1
在您的示例中,仅传递第一个参数 ID。 ,4
每次更改时都会为您提供状态。最后一个值表示将传递给回调函数的参数数量。
推荐阅读
- google-chrome - 不再有插入/插入光标输入类型 = 文本
- windows - Nsight Systems:将 Windows 主机上的 CUDA 应用程序远程分析到 Linux 目标时出现问题
- javascript - 在盖茨比主题中更改徽标
- swift - Swift - CoreData 在删除后持续存在直到重新编译
- react-native - 如何检查应用程序是否安装在手机上?因此 Expo 可以为设备生成 ExpoPushtoken 以启用推送通知
- entity-framework - 清洁架构 EF Core DbContext 项目
- php - PHP 无法读取、写入或创建 XML 文件 - 仅在托管时
- python - Python Socket 立即关闭
- json - 如何从不带引号的字符串构建 json 对象
- python - Python/FFMpeg:我如何在 python 中让 ffmpeg 从视频中提取图像,编辑图像,然后使用来自源视频的同步音频创建新视频?