示例#1
0
function pw_edd_recurring_limit_one_subscription($valid_data, $post_data)
{
    if (!class_exists('EDD_Recurring_Customer')) {
        return;
    }
    if (!is_user_logged_in()) {
        return;
    }
    $purchase_data = array('downloads' => edd_get_cart_contents());
    if (EDD_Recurring_Customer::is_customer_active() && EDD_Recurring()->is_purchase_recurring($purchase_data)) {
        edd_set_error('edd-one-subscription', __('You already have an active subscription so may not purchase a second one.', 'edd'));
    }
}
function ck_edd_user_download_button_recurring($purchase_form, $args)
{
    if (!class_exists('EDD_Recurring_Customer')) {
        return $purchase_form;
    }
    if (!EDD_Recurring_Customer::is_customer_active(get_current_user_id())) {
        return $purchase_form;
    }
    if (!is_user_logged_in()) {
        return $purchase_form;
    }
    $download_id = (string) $args['download_id'];
    $current_user_id = get_current_user_id();
    // If the user has purchased this item, itterate through their purchases to get the specific
    // purchase data and pull out the key and email associated with it. This is necessary for the
    // generation of the download link
    if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) {
        $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete');
        foreach ($user_purchases as $purchase) {
            $cart_items = edd_get_payment_meta_cart_details($purchase->ID);
            $item_ids = wp_list_pluck($cart_items, 'id');
            if (in_array($download_id, $item_ids)) {
                $email = edd_get_payment_user_email($purchase->ID);
                $payment_key = edd_get_payment_key($purchase->ID);
            }
        }
        // Attempt to get the file data associated with this download
        $download_data = edd_get_download_files($download_id, null);
        if ($download_data) {
            // Setup the style and colors associated with the settings
            global $edd_options;
            $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button';
            $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
            $new_purchase_form = '';
            foreach ($download_data as $filekey => $file) {
                // Generate the file URL and then make a link to it
                $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $download_id, null);
                $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a>&nbsp;';
            }
        }
        // As long as we ended up with links to show, use them.
        if (!empty($new_purchase_form)) {
            $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form;
        }
    }
    return $purchase_form;
}
示例#3
0
 /**
  * Displays a payment update form
  *
  * @since  x.x
  * @return string
  */
 public function update_payment_form()
 {
     global $user_ID;
     if (!is_user_logged_in()) {
         return;
     }
     if (!EDD_Recurring_Customer::is_customer_active($user_ID)) {
         return;
     }
     if ('cancelled' === EDD_Recurring_Customer::get_customer_status($user_ID)) {
         return;
     }
     // Gateways can choose to show the form or not by using this filter
     $show_cc_form = apply_filters('edd_recurring_customer_can_update_card', false, $user_ID);
     if (!$show_cc_form) {
         $form_fields = array();
         $form_fields['cc_number'] = array('type' => 'text', 'options' => array('name' => 'edd-recurring-card-number', 'label' => __('Credit Card Number', 'edd-recurring'), 'placeholder' => __('Credit Card Number', 'edd-recurring'), 'autocomplete' => false));
         $form_fields['cc_name'] = array('type' => 'text', 'options' => array('name' => 'edd-recurring-card-name', 'label' => __('Name on Card', 'edd-recurring'), 'placeholder' => __('Name on Card', 'edd-recurring'), 'autocomplete' => true));
         $form_fields['cvc_number'] = array('type' => 'text', 'options' => array('name' => 'edd-recurring-cvc-number', 'class' => 'small-text', 'label' => __('CVC Number', 'edd-recurring'), 'placeholder' => __('###', 'edd-recurring'), 'autocomplete' => false));
         $form_fields['exp_head'] = array('type' => 'legend', 'options' => array('text' => __('Card Expiration', 'edd-recurring')));
         $form_fields['exp_month'] = array('type' => 'month_dropdown');
         $form_fields['exp_year'] = array('type' => 'year_dropdown', 'number_of_years' => 10);
         $elements = apply_filters('edd_recurring_update_form_elements', $form_fields, $user_ID);
     }
     $form_output = '';
     if (isset($_GET['updated']) && $_GET['updated'] == true && !edd_get_errors()) {
         $form_output = '<p class="edd_success"><strong>' . __('Success', 'edd') . ':</strong> ' . __('Your profile has been edited successfully.', 'edd') . '</p>';
     }
     $form_output .= '<div id="edd-recurring-update-wrapper">';
     $form_output .= '<form action="' . remove_query_arg('updated', edd_get_current_page_url()) . '" id="edd-recurring-form" method="POST">';
     $form_input_html = '';
     if (!$show_cc_form) {
         // Iterate through all the form elements, and add them to the HTML
         foreach ($elements as $element) {
             switch ($element['type']) {
                 case 'month_dropdown':
                     $form_input_html .= EDD()->html->{$element}['type']();
                     break;
                 case 'year_dropdown':
                     $form_input_html .= EDD()->html->{$element}['type']('edd-recurring-exp-year', null, 0, $element['number_of_years']);
                     break;
                 case 'legend':
                     $form_input_html .= '<legend>' . $element['options']['text'] . '</legend>';
                     break;
                 default:
                     $form_input_html .= EDD()->html->{$element}['type']($element['options']);
                     $form_input_html .= '<br />';
                     break;
             }
         }
     }
     ob_start();
     edd_print_errors();
     $form_output .= ob_get_clean();
     $form_output .= apply_filters('edd_recurring_update_form_html', $form_input_html, $user_ID);
     $recurring_gateway = apply_filters('edd_recurring_update_gateway', '', $user_ID);
     $form_output .= '<input name="edd-recurring-update-gateway" type="hidden" value="' . $recurring_gateway . '" />';
     $form_output .= wp_nonce_field('update-payment', 'edd_recurring_update_nonce', true, false);
     $form_output .= '<input type="hidden" name="edd_action" value="recurring_update_payment" />';
     $form_output .= '<input type="submit" name="edd-recurring-update-submit" id="edd-recurring-update-submit" value="' . esc_attr(__('Update Payment', 'edd-recurring')) . '" />';
     $form_output .= '</form>';
     $form_output .= '</div>';
     return '<div id="edd_checkout_form_wrap">' . $form_output . '</div>';
 }
 /**
  * Check if user has access to content
  *
  * @since  2.2.7
  * @return bool
  */
 public function can_access_content($has_access, $user_id, $restricted_to)
 {
     if ($has_access && is_array($restricted_to)) {
         foreach ($restricted_to as $item) {
             if (get_post_meta(get_the_ID(), '_edd_cr_active_only', true)) {
                 if (!EDD_Recurring_Customer::is_customer_active($user_id)) {
                     $has_access = false;
                     break;
                 }
             }
         }
     }
     return $has_access;
 }