【问题标题】:Wordpress Help (WPForms + PayPal Workflow)Wordpress 帮助(WPForms + PayPal 工作流程)
【发布时间】:2020-05-11 19:58:49
【问题描述】:

上下文: 我已经使用 Wordpress 中的 WPForms 插件为我的客户创建了一个自定义捐赠表格。客户希望通过 PayPal 接受捐款。

问题: WPForms 具有 PayPal 附加功能,但价格为 200 美元。

问题 为了避免为昂贵的插件支付 200 美元,我如何手动将用户输入的 WPForm 数据(姓名、电子邮件、地址、捐款金额和就业信息)直接/发布到 PayPal?

【问题讨论】:

    标签: wordpress forms paypal


    【解决方案1】:

    在您将在下面看到的示例代码中,我们首先检查表单 ID 以确保它与目标表单匹配。然后我们检查一个特定的字段(通过字段 ID)看它是否为空。

    只需记住将表单 ID 从 5 更改为与您的表单 ID 匹配,并将“4”更改为与您的字段 ID 匹配。

    function wpf_dev_process( $fields, $entry, $form_data ) {
    
        // Optional, you can limit to specific forms. Below, we restrict output to
        // form #5.
        if ( absint( $form_data['id'] ) !== 5 ) {
            return $fields;
        }
    
        // check the field ID 4 to see if it's empty and if it is, run the error    
        if(empty($fields[4]['value'])) 
            {
                // Add to global errors. This will stop form entry from being saved to the database.
                // Uncomment the line below if you need to display the error above the form.
                // wpforms()->process->errors[ $form_data['id'] ]['header'] = esc_html__( 'Some error occurred.', 'plugin-domain' );    
    
                // Check the field ID 4 and show error message at the top of form and under the specific field
                   wpforms()->process->errors[ $form_data['id'] ] [ '4' ] = esc_html__( 'Some error occurred.', 'plugin-domain' );
    
                // Add additional logic (what to do if error is not displayed)
            }
        }
    add_action( 'wpforms_process', 'wpf_dev_process', 10, 3 );
    

    【讨论】:

    • 谢谢,桑吉夫!我在哪里放置此代码?在哪个文件中?另外,“10”和“3”在你的代码中代表什么?
    • 你需要将函数放在主题的functions.php中,并在你想要获取表单值的地方调用函数。 10 或 3 是 WPForm id。
    猜你喜欢
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2016-01-06
    • 2012-05-19
    • 1970-01-01
    相关资源
    最近更新 更多