我正在创建一个帖子gform_after_submission
操作,在成功创建帖子时设置帖子ID变量。
https://docs.gravityforms.com/gform_after_submission/
add_action(\'gform_after_submission_1\', [ $this, \'create_order\' ], 10, 2 );
public function create_order( $entry, $form ) {
// get the current cart data array
$data = self::data();
// user id
$user_id = get_current_user_id();
// create an order array
$order = [
\'post_author\' => $user_id,
\'post_content\' => json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),
\'post_type\' => \'purchase-order\',
\'post_status\' => \'publish\'
];
// create order post using an array and return the post id
$result = wp_insert_post($order);
// if post id and is not a wp error then
if($result && !is_wp_error($result)) {
// get the id
$post_id = $result;
// my order custom field updates go here...
}
}
因为我的表单是通过ajax提交的,所以我无法调用上面的头php重定向,因为重定向只会发生在ajax请求中。
我需要通过我的$post_id
到重力窗体gform_confirmation
滤器但我真的很难看到如何做到这一点。
https://docs.gravityforms.com/gform_confirmation/
add_filter(\'gform_confirmation_1\', [ $this, \'order_confirmation\' ], 10, 4 );
public function order_confirmation( $confirmation, $form, $entry, $ajax ) {
// update redirect to order
$confirmation = array( \'redirect\' => get_permalink($post_id) );
// return confirmation
return $confirmation;
}
如果有人有任何想法,那就太好了,谢谢。