如何获得用户的全部捐款--重力表单?

时间:2017-04-01 作者:Artus

我使用此代码显示使用重力表单在站点上进行的总捐赠。但如何限制只显示登录用户的捐赠?是的,用户已经进行了多次捐赠。

add_shortcode(\'donations\', \'total_donations\');
function total_donations($atts) {

     $form_id = $atts[\'form\'];
    // function to pull all the entries for one form
    $donations = RGFormsModel::get_leads($form_id);
    // start the total at zero
    $total = 0;
    // initialize a counter for the number of donations made
    $i = 0;
    // loop through all the returned results
    foreach ($donations as $amount) {
            // add each donation amount to the total
            // change [49] here to the field ID which holds the donation amount
            // the preg_replace will strip anything that is not a number or decimal

            $numeric_amount =  preg_replace(\'/[^0-9\\.]/Uis\', \'\',$amount[49]);
            $total += $numeric_amount;
            // increment the counter so we know how many donations there are as well
            $i++;
    }

    // do some formatting and return the html output from the shortcode
    $output = "We have raised $" . $total /* . " from $i donors."*/;
    // just the string above will be returned.  You can style it here or where you are using the shortcode
    return $output;
}
add_filter(\'widget_text\', \'do_shortcode\');

1 个回复
最合适的回答,由SO网友:Artus 整理而成

答案来自一个插件。重力WP计数。

相关推荐