Exemplo n.º 1
0
/**
 * AccessPress Template Tags for displaying front-end content
 *
 * @package AccessPress
 */
function accesspress_checkout_form($args = array())
{
    $args = isset($_POST['accesspress-checkout']) ? $_POST['accesspress-checkout'] : $args;
    $form_submitted = isset($_POST['accesspress-checkout']) || isset($_REQUEST['action']);
    /** If form submitted */
    if ($form_submitted) {
        $checkout_complete = accesspress_checkout($args);
        /** If there was an error in the submission show the error to the user */
        if (is_wp_error($checkout_complete)) {
            printf('<div class="acp-error">%s</div>', $checkout_complete->get_error_message());
        } else {
            /** Show the comlpete message when the transaction is complete */
            if ($checkout_complete) {
                _e('Congratulations! Please check your email for account details.', 'premise');
            }
            /** don't show the checkout form */
            return;
        }
    }
    /** don't show the checkout form unless there is a product or checkout is in progress */
    $product_id = isset($_GET['product_id']) ? $_GET['product_id'] : '';
    if (!$form_submitted && !memberaccess_is_valid_product($product_id)) {
        return;
    }
    echo '<div class="premise-checkout-wrap"><form method="post" action="">';
    printf('<input type="hidden" name="accesspress-checkout[product_id]" value="%s" />', $product_id);
    if (isset($_GET['renew']) && 'true' == $_GET['renew']) {
        echo '<input type="hidden" name="accesspress-checkout[renew]" value="true" />';
    }
    accesspress_checkout_form_account($args);
    accesspress_checkout_form_choose_payment($args);
    accesspress_checkout_form_payment_cc($args);
    printf('<input type="submit" value="%s" class="input-submit" />', is_user_logged_in() ? __('Submit Order', 'premise') : __('Submit Order and Create My Account', 'premise'));
    echo '</form></div>';
}
Exemplo n.º 2
0
/**
 * AccessPress Template Tags for displaying front-end content
 *
 * @package AccessPress
 */
function accesspress_checkout_form($args = array())
{
    global $product_member;
    $checkout_args = isset($_POST['accesspress-checkout']) ? $_POST['accesspress-checkout'] : $args;
    $checkout_args = apply_filters('premise_checkout_args', $checkout_args);
    $form_submitted = apply_filters('premise_checkout_form_submitted', isset($_POST['accesspress-checkout']) || isset($_REQUEST['action']), $args);
    /** If form submitted */
    if ($form_submitted) {
        $checkout_complete = accesspress_checkout($checkout_args);
        /** If there was an error in the submission show the error to the user */
        if (is_wp_error($checkout_complete)) {
            printf('<div class="acp-error">%s</div>', $checkout_complete->get_error_message());
        } else {
            /** Show the comlpete message when the transaction is complete */
            if ($checkout_complete) {
                do_action('premise_checkout_complete_before', $checkout_args, $checkout_args['product_id'], $args);
                if (!empty($checkout_complete['member_id'])) {
                    $product_member = new WP_User($checkout_complete['member_id']);
                }
                $receipt_body = get_post_meta($checkout_args['product_id'], '_acp_product_email_receipt_intro', true);
                if (!empty($receipt_body)) {
                    echo do_shortcode(str_replace("\n", '<br />', $receipt_body));
                }
                do_action('premise_checkout_complete_after', $checkout_args, $checkout_args['product_id'], $args);
            }
            /** don't show the checkout form */
            return;
        }
    }
    /** don't show the checkout form unless there is a product or checkout is in progress */
    $product_id = isset($_GET['product_id']) ? $_GET['product_id'] : '';
    if (!$form_submitted && !memberaccess_is_valid_product($product_id)) {
        return;
    }
    $checkout_button = '<input type="submit" value="%s" class="input-submit" />';
    if (is_user_logged_in()) {
        $products = memberaccess_get_member_products(get_current_user_id(), true);
        if (in_array($product_id, $products)) {
            echo '<h3>' . __('You have already purchased this product', 'premise') . '</h3>';
            $checkout_button = '';
        }
    }
    do_action('premise_checkout_form_before', $checkout_args, $product_id, $args);
    echo '<div class="premise-checkout-wrap"><form method="post" action="">';
    printf('<input type="hidden" name="accesspress-checkout[product_id]" id="accesspress-checkout-product-id" value="%s" />', $product_id);
    if (isset($_GET['renew']) && 'true' == $_GET['renew']) {
        echo '<input type="hidden" name="accesspress-checkout[renew]" value="true" />';
    }
    do_action('premise_checkout_form', $checkout_args, $product_id, $args);
    $checkout_text = trim(is_user_logged_in() ? $args['member_text'] : $args['nonmember_text']);
    if (empty($checkout_text)) {
        $checkout_text = apply_filters('premise_checkout_button_text', is_user_logged_in() ? __('Submit Order', 'premise') : __('Submit Order and Create My Account', 'premise'), is_user_logged_in());
    }
    printf($checkout_button, $checkout_text);
    echo '</form></div>';
    do_action('premise_checkout_form_after', $checkout_args, $product_id, $args);
}
Exemplo n.º 3
0
function accesspress_product_info_content($atts, $field)
{
    global $product_post;
    $atts = shortcode_atts(array('productid' => 0, 'format' => '', 'title' => '', 'target' => ''), $atts);
    if (!$atts['productid'] && isset($_REQUEST['product_id'])) {
        $atts['productid'] = (int) $_REQUEST['product_id'];
    }
    if (!$atts['productid'] && isset($_POST['accesspress-checkout']['product_id'])) {
        $atts['productid'] = (int) $_POST['accesspress-checkout']['product_id'];
    }
    if (!$atts['productid'] && isset($product_post->ID)) {
        $atts['productid'] = (int) $product_post->ID;
    }
    if (!memberaccess_is_valid_product($atts['productid'])) {
        return '';
    }
    if ($field == 'post_title') {
        if (!empty($product_post->post_title)) {
            return $product_post->post_title;
        }
        $product = get_post($atts['productid']);
        if (empty($product->post_title)) {
            return '';
        }
        return $product->post_title;
    }
    if ($field == 'purchase_link') {
        $url = accesspress_get_checkout_link($atts['productid']);
        if (!$url) {
            return '%s';
        }
        $target = $atts['target'] ? 'target="' . $atts['target'] . '"' : '';
        return sprintf('<a href="%s" title="%s" %s>', $url, $atts['title'], $target) . '%s</a>';
    }
    $meta = get_post_meta($atts['productid'], $field, true);
    if (empty($meta)) {
        return '';
    }
    return $atts['format'] ? sprintf($atts['format'], $meta) : $meta;
}