You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:为Contact Form 7创建hook,实现付款后开启skip_mail发送表单邮件

How to Send Contact Form 7 Email Only After Successful Payment (Toggle skip_mail)

Got it! You’re totally on the right track using skip_mail = on to block immediate form emails, and we can absolutely use a custom hook to flip that setting and send the form data only after a successful payment goes through. Here’s a step-by-step solution tailored to your setup:

1. Use the Add-on’s Payment Success Hook

The PayPal & Stripe Add-on for Contact Form 7 fires specific action hooks when a payment completes successfully. The most reliable one (works for both gateways) is wpcf7_payment_completed—we’ll use this to trigger our email logic.

2. Add the Custom Code

You’ll need to drop this snippet into your WordPress theme’s functions.php file, or better yet, a custom plugin (to avoid losing code when you update your theme):

// Trigger CF7 email after successful payment
add_action( 'wpcf7_payment_completed', 'send_cf7_email_post_payment', 10, 2 );

function send_cf7_email_post_payment( $payment_details, $cf7_submission ) {
    // Grab the CF7 form object from the submission data
    $cf7_form = $cf7_submission->get_contact_form();

    // Temporarily turn off skip_mail so the email can send
    $cf7_form->set_properties( array( 'skip_mail' => false ) );

    // Fetch the form's email settings and send the mail
    $email_settings = $cf7_form->prop( 'mail' );
    $cf7_form->send_mail( $cf7_submission, $email_settings );

    // Optional: Flip skip_mail back to on if you want future submissions to still skip by default
    $cf7_form->set_properties( array( 'skip_mail' => true ) );
}

3. Key Notes & Troubleshooting

  • Double-check the hook name: If you’re using an older version of the add-on, confirm the hook in its documentation—some versions use gateway-specific hooks like wpcf7_stripe_payment_completed or wpcf7_paypal_payment_completed if you need to target one payment method only.
  • Test with sandbox payments: Always run a test payment (using PayPal Sandbox or Stripe Test Mode) to make sure the email sends exactly when you expect it to.
  • Adjust priority if needed: If you have other CF7-related hooks running, tweak the 10 in add_action to a higher number (like 20) if this code isn’t firing correctly—this ensures it runs after other conflicting logic.
  • Customize the email: If you want the post-payment email to look different from your default CF7 email, you can use the wpcf7_mail_components filter inside this function to modify the subject, body, or recipients.

内容的提问来源于stack exchange,提问作者nubitol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:08:35