Payment/Subscription Shortcodes to be used with Formidable

Jaime updated Steph’s shortcode but it only displayed whether a payment was “Complete” or “Not Complete”. I tweaked it so that you can display any payment information like the original did.

add_shortcode('frm_payment_status', 'frm_payment_status');

function frm_payment_status($atts){
    extract(shortcode_atts(array('id' => false, 'field' => ''), $atts));
    if(!$id) return ''; //if no entry id is specified, then don't return anything
    global $wpdb;
    $completed = $wpdb->get_var($wpdb->prepare("SELECT $field FROM {$wpdb->prefix}frm_payments WHERE item_id=%d", (int) $id));
    if ( $field != 'status' ){
        return $completed;
    } else {
        return $completed ? 'Complete' : 'Not complete'; //change your text here
    }
}

While I was at it, I adapted it so that subscription information can also be displayed.

add_shortcode('frm_subscription_status', 'frm_subscription_status');

function frm_subscription_status($atts){
    extract(shortcode_atts(array('id' => false, 'field' => ''), $atts));
    if(!$id) return ''; //if no entry id is specified, then don't return anything
    global $wpdb;
    if ($field = 'profile_id' {
        $field = 'sub_id';
    }
    $result = $wpdb->get_var($wpdb->prepare("SELECT $field FROM {$wpdb->prefix}frm_subscriptions WHERE item_id=%d", (int) $id));
    return $result;
}

Leave a Reply

Your email address will not be published. Required fields are marked *