/**
 * Get taxation rate
 *
 * @since 1.3.3
 * @param bool $country
 * @param bool $state
 * @return mixed|void
 */
function edd_get_tax_rate($country = false, $state = false)
{
    $rate = (double) edd_get_option('tax_rate', 0);
    $user_address = edd_get_customer_address();
    if (empty($country)) {
        if (!empty($_POST['billing_country'])) {
            $country = $_POST['billing_country'];
        } elseif (is_user_logged_in() && !empty($user_address)) {
            $country = $user_address['country'];
        }
        $country = !empty($country) ? $country : edd_get_shop_country();
    }
    if (empty($state)) {
        if (!empty($_POST['state'])) {
            $state = $_POST['state'];
        } elseif (!empty($_POST['card_state'])) {
            $state = $_POST['card_state'];
        } elseif (is_user_logged_in() && !empty($user_address)) {
            $state = $user_address['state'];
        }
        $state = !empty($state) ? $state : edd_get_shop_state();
    }
    if (!empty($country)) {
        $tax_rates = edd_get_tax_rates();
        if (!empty($tax_rates)) {
            // Locate the tax rate for this country / state, if it exists
            foreach ($tax_rates as $key => $tax_rate) {
                if ($country != $tax_rate['country']) {
                    continue;
                }
                if (!empty($tax_rate['global'])) {
                    if (!empty($tax_rate['rate'])) {
                        $rate = number_format($tax_rate['rate'], 4);
                    }
                } else {
                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) {
                        continue;
                    }
                    $state_rate = $tax_rate['rate'];
                    if (0 !== $state_rate || !empty($state_rate)) {
                        $rate = number_format($state_rate, 4);
                    }
                }
            }
        }
    }
    if ($rate > 1) {
        // Convert to a number we can use
        $rate = $rate / 100;
    }
    return apply_filters('edd_tax_rate', $rate, $country, $state);
}
Ejemplo n.º 2
0
/**
 * View a customer
 *
 * @since  2.3
 * @param  $customer The Customer object being displayed
 * @return void
 */
function edd_customers_view($customer)
{
    $customer_edit_role = apply_filters('edd_edit_customers_role', 'edit_shop_payments');
    ?>

	<?php 
    do_action('edd_customer_card_top', $customer);
    ?>

	<div class="info-wrapper customer-section">

		<form id="edit-customer-info" method="post" action="<?php 
    echo admin_url('edit.php?post_type=download&page=edd-customers&view=overview&id=' . $customer->id);
    ?>
">

			<div class="customer-info">

				<div class="avatar-wrap left" id="customer-avatar">
					<?php 
    echo get_avatar($customer->email);
    ?>
<br />
					<?php 
    if (current_user_can($customer_edit_role)) {
        ?>
						<span class="info-item editable customer-edit-link"><a title="<?php 
        _e('Edit Customer', 'edd');
        ?>
" href="#" id="edit-customer"><?php 
        _e('Edit Customer', 'edd');
        ?>
</a></span>
					<?php 
    }
    ?>
				</div>

				<div class="customer-id right">
					#<?php 
    echo $customer->id;
    ?>
				</div>

				<div class="customer-address-wrapper right">
				<?php 
    if (isset($customer->user_id) && $customer->user_id > 0) {
        ?>

					<?php 
        $address = get_user_meta($customer->user_id, '_edd_user_address', true);
        $defaults = array('line1' => '', 'line2' => '', 'city' => '', 'state' => '', 'country' => '', 'zip' => '');
        $address = wp_parse_args($address, $defaults);
        ?>

					<?php 
        if (!empty($address)) {
            ?>
					<strong><?php 
            _e('Customer Address', 'edd');
            ?>
</strong>
					<span class="customer-address info-item editable">
						<span class="info-item" data-key="line1"><?php 
            echo $address['line1'];
            ?>
</span>
						<span class="info-item" data-key="line2"><?php 
            echo $address['line2'];
            ?>
</span>
						<span class="info-item" data-key="city"><?php 
            echo $address['city'];
            ?>
</span>
						<span class="info-item" data-key="state"><?php 
            echo $address['state'];
            ?>
</span>
						<span class="info-item" data-key="country"><?php 
            echo $address['country'];
            ?>
</span>
						<span class="info-item" data-key="zip"><?php 
            echo $address['zip'];
            ?>
</span>
					</span>
					<?php 
        }
        ?>
					<span class="customer-address info-item edit-item">
						<input class="info-item" type="text" data-key="line1" name="customerinfo[line1]" placeholder="<?php 
        _e('Address 1', 'edd');
        ?>
" value="<?php 
        echo $address['line1'];
        ?>
" />
						<input class="info-item" type="text" data-key="line2" name="customerinfo[line2]" placeholder="<?php 
        _e('Address 2', 'edd');
        ?>
" value="<?php 
        echo $address['line2'];
        ?>
" />
						<input class="info-item" type="text" data-key="city" name="customerinfo[city]" placeholder="<?php 
        _e('City', 'edd');
        ?>
" value="<?php 
        echo $address['city'];
        ?>
" />
						<select data-key="country" name="customerinfo[country]" id="billing_country" class="billing_country edd-select edit-item">
							<?php 
        $selected_country = $address['country'];
        $countries = edd_get_country_list();
        foreach ($countries as $country_code => $country) {
            echo '<option value="' . esc_attr($country_code) . '"' . selected($country_code, $selected_country, false) . '>' . $country . '</option>';
        }
        ?>
						</select>
						<?php 
        $selected_state = edd_get_shop_state();
        $states = edd_get_shop_states($selected_country);
        $selected_state = isset($address['state']) ? $address['state'] : $selected_state;
        if (!empty($states)) {
            ?>
						<select data-key="state" name="customerinfo[state]" id="card_state" class="card_state edd-select info-item">
							<?php 
            foreach ($states as $state_code => $state) {
                echo '<option value="' . $state_code . '"' . selected($state_code, $selected_state, false) . '>' . $state . '</option>';
            }
            ?>
						</select>
						<?php 
        } else {
            ?>
						<input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state edd-input info-item" placeholder="<?php 
            _e('State / Province', 'edd');
            ?>
"/>
						<?php 
        }
        ?>
						<input class="info-item" type="text" data-key="zip" name="customerinfo[zip]" placeholder="<?php 
        _e('Postal', 'edd');
        ?>
" value="<?php 
        echo $address['zip'];
        ?>
" />
					</span>
				<?php 
    }
    ?>
				</div>

				<div class="customer-main-wrapper left">

					<span class="customer-name info-item edit-item"><input size="15" data-key="name" name="customerinfo[name]" type="text" value="<?php 
    echo esc_attr($customer->name);
    ?>
" placeholder="<?php 
    _e('Customer Name', 'edd');
    ?>
" /></span>
					<span class="customer-name info-item editable"><span data-key="name"><?php 
    echo $customer->name;
    ?>
</span></span>
					<span class="customer-name info-item edit-item"><input size="20" data-key="email" name="customerinfo[email]" type="text" value="<?php 
    echo $customer->email;
    ?>
" placeholder="<?php 
    _e('Customer Email', 'edd');
    ?>
" /></span>
					<span class="customer-email info-item editable" data-key="email"><?php 
    echo $customer->email;
    ?>
</span>
					<span class="customer-since info-item">
						<?php 
    _e('Customer since', 'edd');
    ?>
						<?php 
    echo date_i18n(get_option('date_format'), strtotime($customer->date_created));
    ?>
					</span>
					<span class="customer-user-id info-item edit-item">
						<?php 
    $user_id = $customer->user_id > 0 ? $customer->user_id : '';
    $data_atts = array('key' => 'user_login', 'exclude' => $user_id);
    $user_args = array('name' => 'customerinfo[user_login]', 'class' => 'edd-user-dropdown', 'data' => $data_atts);
    if (!empty($user_id)) {
        $userdata = get_userdata($user_id);
        $user_args['value'] = $userdata->user_login;
    }
    echo EDD()->html->ajax_user_search($user_args);
    ?>
						<input type="hidden" name="customerinfo[user_id]" data-key="user_id" value="<?php 
    echo $customer->user_id;
    ?>
" />
					</span>

					<span class="customer-user-id info-item editable">
						<?php 
    _e('User ID', 'edd');
    ?>
:&nbsp;
						<?php 
    if (intval($customer->user_id) > 0) {
        ?>
							<span data-key="user_id"><?php 
        echo $customer->user_id;
        ?>
</span>
						<?php 
    } else {
        ?>
							<span data-key="user_id"><?php 
        _e('none', 'edd');
        ?>
</span>
						<?php 
    }
    ?>
						<?php 
    if (current_user_can($customer_edit_role) && intval($customer->user_id) > 0) {
        ?>
							<span class="disconnect-user"> - <a id="disconnect-customer" href="#disconnect" title="<?php 
        _e('Disconnects the current user ID from this customer record', 'edd');
        ?>
"><?php 
        _e('Disconnect User', 'edd');
        ?>
</a></span>
						<?php 
    }
    ?>
					</span>

				</div>

			</div>

			<span id="customer-edit-actions" class="edit-item">
				<input type="hidden" data-key="id" name="customerinfo[id]" value="<?php 
    echo $customer->id;
    ?>
" />
				<?php 
    wp_nonce_field('edit-customer', '_wpnonce', false, true);
    ?>
				<input type="hidden" name="edd_action" value="edit-customer" />
				<input type="submit" id="edd-edit-customer-save" class="button-secondary" value="<?php 
    _e('Update Customer', 'edd');
    ?>
" />
				<a id="edd-edit-customer-cancel" href="" class="delete"><?php 
    _e('Cancel', 'edd');
    ?>
</a>
			</span>

		</form>
	</div>

	<?php 
    do_action('edd_customer_before_stats', $customer);
    ?>

	<div id="customer-stats-wrapper" class="customer-section">
		<ul>
			<li>
				<a title="<?php 
    _e('View All Purchases', 'edd');
    ?>
" href="<?php 
    echo admin_url('edit.php?post_type=download&page=edd-payment-history&user='******'%d Completed Sale', '%d Completed Sales', $customer->purchase_count, 'edd'), $customer->purchase_count);
    ?>
				</a>
			</li>
			<li>
				<span class="dashicons dashicons-chart-area"></span>
				<?php 
    echo edd_currency_filter(edd_format_amount($customer->purchase_value));
    ?>
 <?php 
    _e('Lifetime Value', 'edd');
    ?>
			</li>
			<?php 
    do_action('edd_customer_stats_list', $customer);
    ?>
		</ul>
	</div>

	<?php 
    do_action('edd_customer_before_tables_wrapper', $customer);
    ?>

	<div id="customer-tables-wrapper" class="customer-section">

		<?php 
    do_action('edd_customer_before_tables', $customer);
    ?>

		<h3><?php 
    _e('Recent Payments', 'edd');
    ?>
</h3>
		<?php 
    $payment_ids = explode(',', $customer->payment_ids);
    $payments = edd_get_payments(array('post__in' => $payment_ids));
    $payments = array_slice($payments, 0, 10);
    ?>
		<table class="wp-list-table widefat striped payments">
			<thead>
				<tr>
					<th><?php 
    _e('ID', 'edd');
    ?>
</th>
					<th><?php 
    _e('Amount', 'edd');
    ?>
</th>
					<th><?php 
    _e('Date', 'edd');
    ?>
</th>
					<th><?php 
    _e('Status', 'edd');
    ?>
</th>
					<th><?php 
    _e('Actions', 'edd');
    ?>
</th>
				</tr>
			</thead>
			<tbody>
				<?php 
    if (!empty($payments)) {
        ?>
					<?php 
        foreach ($payments as $payment) {
            ?>
						<tr>
							<td><?php 
            echo $payment->ID;
            ?>
</td>
							<td><?php 
            echo edd_payment_amount($payment->ID);
            ?>
</td>
							<td><?php 
            echo date_i18n(get_option('date_format'), strtotime($payment->post_date));
            ?>
</td>
							<td><?php 
            echo edd_get_payment_status($payment, true);
            ?>
</td>
							<td>
								<a title="<?php 
            _e('View Details for Payment', 'edd');
            echo ' ' . $payment->ID;
            ?>
" href="<?php 
            echo admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $payment->ID);
            ?>
">
									<?php 
            _e('View Details', 'edd');
            ?>
								</a>
								<?php 
            do_action('edd_customer_recent_purcahses_actions', $customer, $payment);
            ?>
							</td>
						</tr>
					<?php 
        }
        ?>
				<?php 
    } else {
        ?>
					<tr><td colspan="5"><?php 
        _e('No Payments Found', 'edd');
        ?>
</td></tr>
				<?php 
    }
    ?>
			</tbody>
		</table>

		<h3><?php 
    printf(__('Purchased %s', 'edd'), edd_get_label_plural());
    ?>
</h3>
		<?php 
    $downloads = edd_get_users_purchased_products($customer->email);
    ?>
		<table class="wp-list-table widefat striped downloads">
			<thead>
				<tr>
					<th><?php 
    echo edd_get_label_singular();
    ?>
</th>
					<th width="120px"><?php 
    _e('Actions', 'edd');
    ?>
</th>
				</tr>
			</thead>
			<tbody>
				<?php 
    if (!empty($downloads)) {
        ?>
					<?php 
        foreach ($downloads as $download) {
            ?>
						<tr>
							<td><?php 
            echo $download->post_title;
            ?>
</td>
							<td>
								<a title="<?php 
            echo esc_attr(sprintf(__('View %s', 'edd'), $download->post_title));
            ?>
" href="<?php 
            echo esc_url(admin_url('post.php?action=edit&post=' . $download->ID));
            ?>
">
									<?php 
            printf(__('View %s', 'edd'), edd_get_label_singular());
            ?>
								</a>
							</td>
						</tr>
					<?php 
        }
        ?>
				<?php 
    } else {
        ?>
					<tr><td colspan="2"><?php 
        printf(__('No %s Found', 'edd'), edd_get_label_plural());
        ?>
</td></tr>
				<?php 
    }
    ?>
			</tbody>
		</table>

		<?php 
    do_action('edd_customer_after_tables', $customer);
    ?>

	</div>

	<?php 
    do_action('edd_customer_card_bottom', $customer);
    ?>

	<?php 
}
Ejemplo n.º 3
0
/**
 * Outputs the default credit card address fields
 *
 * @since 1.0
 * @return void
 */
function edd_default_cc_address_fields()
{
    $logged_in = is_user_logged_in();
    $customer = EDD()->session->get('customer');
    $customer = wp_parse_args($customer, array('address' => array('line1' => '', 'line2' => '', 'city' => '', 'zip' => '', 'state' => '', 'country' => '')));
    $customer['address'] = array_map('sanitize_text_field', $customer['address']);
    if ($logged_in) {
        $user_address = get_user_meta(get_current_user_id(), '_edd_user_address', true);
        foreach ($customer['address'] as $key => $field) {
            if (empty($field) && !empty($user_address[$key])) {
                $customer['address'][$key] = $user_address[$key];
            } else {
                $customer['address'][$key] = '';
            }
        }
    }
    ob_start();
    ?>
	<fieldset id="edd_cc_address" class="cc-address">
		<span><legend><?php 
    _e('Billing Details', 'edd');
    ?>
</legend></span>
		<?php 
    do_action('edd_cc_billing_top');
    ?>
		<p id="edd-card-address-wrap">
			<label for="card_address" class="edd-label">
				<?php 
    _e('Billing Address', 'edd');
    ?>
				<?php 
    if (edd_field_is_required('card_address')) {
        ?>
					<span class="edd-required-indicator">*</span>
				<?php 
    }
    ?>
			</label>
			<span class="edd-description"><?php 
    _e('The primary billing address for your credit card.', 'edd');
    ?>
</span>
			<input type="text" id="card_address" name="card_address" class="card-address edd-input<?php 
    if (edd_field_is_required('card_address')) {
        echo ' required';
    }
    ?>
" placeholder="<?php 
    _e('Address line 1', 'edd');
    ?>
" value="<?php 
    echo $customer['address']['line1'];
    ?>
"/>
		</p>
		<p id="edd-card-address-2-wrap">
			<label for="card_address_2" class="edd-label">
				<?php 
    _e('Billing Address Line 2 (optional)', 'edd');
    ?>
				<?php 
    if (edd_field_is_required('card_address_2')) {
        ?>
					<span class="edd-required-indicator">*</span>
				<?php 
    }
    ?>
			</label>
			<span class="edd-description"><?php 
    _e('The suite, apt no, PO box, etc, associated with your billing address.', 'edd');
    ?>
</span>
			<input type="text" id="card_address_2" name="card_address_2" class="card-address-2 edd-input<?php 
    if (edd_field_is_required('card_address_2')) {
        echo ' required';
    }
    ?>
" placeholder="<?php 
    _e('Address line 2', 'edd');
    ?>
" value="<?php 
    echo $customer['address']['line2'];
    ?>
"/>
		</p>
		<p id="edd-card-city-wrap">
			<label for="card_city" class="edd-label">
				<?php 
    _e('Billing City', 'edd');
    ?>
				<?php 
    if (edd_field_is_required('card_city')) {
        ?>
					<span class="edd-required-indicator">*</span>
				<?php 
    }
    ?>
			</label>
			<span class="edd-description"><?php 
    _e('The city for your billing address.', 'edd');
    ?>
</span>
			<input type="text" id="card_city" name="card_city" class="card-city edd-input<?php 
    if (edd_field_is_required('card_city')) {
        echo ' required';
    }
    ?>
" placeholder="<?php 
    _e('City', 'edd');
    ?>
" value="<?php 
    echo $customer['address']['city'];
    ?>
"/>
		</p>
		<p id="edd-card-zip-wrap">
			<label for="card_zip" class="edd-label">
				<?php 
    _e('Billing Zip / Postal Code', 'edd');
    ?>
				<?php 
    if (edd_field_is_required('card_zip')) {
        ?>
					<span class="edd-required-indicator">*</span>
				<?php 
    }
    ?>
			</label>
			<span class="edd-description"><?php 
    _e('The zip or postal code for your billing address.', 'edd');
    ?>
</span>
			<input type="text" size="4" name="card_zip" class="card-zip edd-input<?php 
    if (edd_field_is_required('card_zip')) {
        echo ' required';
    }
    ?>
" placeholder="<?php 
    _e('Zip / Postal code', 'edd');
    ?>
" value="<?php 
    echo $customer['address']['zip'];
    ?>
"/>
		</p>
		<p id="edd-card-country-wrap">
			<label for="billing_country" class="edd-label">
				<?php 
    _e('Billing Country', 'edd');
    ?>
				<?php 
    if (edd_field_is_required('billing_country')) {
        ?>
					<span class="edd-required-indicator">*</span>
				<?php 
    }
    ?>
			</label>
			<span class="edd-description"><?php 
    _e('The country for your billing address.', 'edd');
    ?>
</span>
			<select name="billing_country" id="billing_country" class="billing_country edd-select<?php 
    if (edd_field_is_required('billing_country')) {
        echo ' required';
    }
    ?>
">
				<?php 
    $selected_country = edd_get_shop_country();
    if (!empty($customer['address']['country']) && '*' !== $customer['address']['country']) {
        $selected_country = $customer['address']['country'];
    }
    $countries = edd_get_country_list();
    foreach ($countries as $country_code => $country) {
        echo '<option value="' . esc_attr($country_code) . '"' . selected($country_code, $selected_country, false) . '>' . $country . '</option>';
    }
    ?>
			</select>
		</p>
		<p id="edd-card-state-wrap">
			<label for="card_state" class="edd-label">
				<?php 
    _e('Billing State / Province', 'edd');
    ?>
				<?php 
    if (edd_field_is_required('card_state')) {
        ?>
					<span class="edd-required-indicator">*</span>
				<?php 
    }
    ?>
			</label>
			<span class="edd-description"><?php 
    _e('The state or province for your billing address.', 'edd');
    ?>
</span>
            <?php 
    $selected_state = edd_get_shop_state();
    $states = edd_get_shop_states($selected_country);
    if (!empty($customer['address']['state'])) {
        $selected_state = $customer['address']['state'];
    }
    if (!empty($states)) {
        ?>
            <select name="card_state" id="card_state" class="card_state edd-select<?php 
        if (edd_field_is_required('card_state')) {
            echo ' required';
        }
        ?>
">
                <?php 
        foreach ($states as $state_code => $state) {
            echo '<option value="' . $state_code . '"' . selected($state_code, $selected_state, false) . '>' . $state . '</option>';
        }
        ?>
            </select>
        	<?php 
    } else {
        ?>
			<input type="text" size="6" name="card_state" id="card_state" class="card_state edd-input" placeholder="<?php 
        _e('State / Province', 'edd');
        ?>
"/>
			<?php 
    }
    ?>
		</p>
		<?php 
    do_action('edd_cc_billing_bottom');
    ?>
	</fieldset>
	<?php 
    echo ob_get_clean();
}