我的重力表单创建了一个WooCommerce订单,但我想排除某个表单

时间:2019-06-10 作者:Tom Hutchison

当前代码

function gravity_form_submitted($entry) //, $form)
{
if(is_user_logged_in()){
    $user_id = get_current_user_id();
} else {
    //session_start();
    $user_id = $_SESSION[\'new_user_id\'];
}

$priority = rgar( $entry, 42 ); //gform field_id referring to priority
$tokens_purchased = explode(\'|\', rgar( $entry, 43)); //gform field_id 
referring to item purchased (product_id from woocommerce)
$coupon = rgar($entry, 45);

$token = new Tokens();

if($tokens_purchased[0] !== \'account\'){
    $order = new Order();
    $order_id = $order->newOrder($user_id, $tokens_purchased[0], $coupon);
    $token->addTokens($order_id);
}

$token->removeTokens($user_id, $priority);

$arg = array(
    \'ID\' => $_SESSION[\'new_post_id\'],
    \'post_author\' => $user_id,
);
wp_update_post( $arg );

//Clear session
unset($_SESSION[\'new_post_id\'], $_SESSION[\'new_user_id\']);
}
add_action(\'gform_after_submission\', \'gravity_form_submitted\', 10, 2);
我尝试使用gform\\u is\\u value\\u匹配从woocommerce订单创建中排除某个帖子,但找不到排除帖子ID的挂钩

有人知道如何从订单创建中排除post ID吗?

1 个回复
SO网友:Sonali Agrawal

Try this :

add_action( \'gform_after_submission\', \'gravity_form_submitted\', 10, 2 );

function gravity_form_submitted($entry, $form)
{
  if($form[\'id\'] != "exclude_form_id")//if multiple you can check not in array
     { 
        //your order generation code
     }
}

Form Object $form

相关推荐