本文整理汇总了PHP中edd_format_discount_rate函数的典型用法代码示例。如果您正苦于以下问题:PHP edd_format_discount_rate函数的具体用法?PHP edd_format_discount_rate怎么用?PHP edd_format_discount_rate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了edd_format_discount_rate函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edd_discounts_shortcode
/**
* Discounts short code
*
* Displays a list of all the active discounts. The active discounts can be configured
* from the Discount Codes admin screen.
*
* @since 1.0.8.2
* @param array $atts Shortcode attributes
* @param string $content
* @uses edd_get_discounts()
* @return string $discounts_lists List of all the active discount codes
*/
function edd_discounts_shortcode($atts, $content = null)
{
$discounts = edd_get_discounts();
$discounts_list = '<ul id="edd_discounts_list">';
if (!empty($discounts) && edd_has_active_discounts()) {
foreach ($discounts as $discount) {
if (edd_is_discount_active($discount->ID)) {
$discounts_list .= '<li class="edd_discount">';
$discounts_list .= '<span class="edd_discount_name">' . edd_get_discount_code($discount->ID) . '</span>';
$discounts_list .= '<span class="edd_discount_separator"> - </span>';
$discounts_list .= '<span class="edd_discount_amount">' . edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID)) . '</span>';
$discounts_list .= '</li>';
}
}
} else {
$discounts_list .= '<li class="edd_discount">' . __('No discounts found', 'easy-digital-downloads') . '</li>';
}
$discounts_list .= '</ul>';
return $discounts_list;
}
示例2: edd_discounts_shortcode
/**
* Discounts short code
*
* Displays a list of all the active discounts. The active discounts can be configured
* from the Discount Codes admin screen.
*
* @since 1.0.8.2
* @param array $atts Shortcode attributes
* @param string $content
* @uses edd_get_discounts()
* @return string $discounts_lists List of all the active discount codes
*/
function edd_discounts_shortcode($atts, $content = null)
{
$discounts = edd_get_discounts();
if (!$discounts && edd_has_active_discounts()) {
return;
}
$discounts_list = '<ul id="edd_discounts_list">';
foreach ($discounts as $discount) {
if (edd_is_discount_active($discount->ID)) {
$discounts_list .= '<li class="edd_discount">';
$discounts_list .= '<span class="edd_discount_name">' . edd_get_discount_code($discount->ID) . '</span>';
$discounts_list .= '<span class="edd_discount_separator"> - </span>';
$discounts_list .= '<span class="edd_discount_amount">' . edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID)) . '</span>';
$discounts_list .= '</li>';
}
}
$discounts_list .= '</ul>';
return $discounts_list;
}
示例3: edd_ajax_apply_discount
/**
* Validates the supplied discount sent via AJAX.
*
* @since 1.0
* @return void
*/
function edd_ajax_apply_discount()
{
if (isset($_POST['code'])) {
$discount_code = sanitize_text_field($_POST['code']);
$return = array('msg' => '', 'code' => $discount_code);
$user = '';
if (is_user_logged_in()) {
$user = get_current_user_id();
} else {
parse_str($_POST['form'], $form);
if (!empty($form['edd_email'])) {
$user = urldecode($form['edd_email']);
}
}
if (edd_is_discount_valid($discount_code, $user)) {
$discount = edd_get_discount_by_code($discount_code);
$amount = edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID));
$discounts = edd_set_cart_discount($discount_code);
$total = edd_get_cart_total($discounts);
$return = array('msg' => 'valid', 'amount' => $amount, 'total_plain' => $total, 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $discount_code, 'html' => edd_get_cart_discounts_html($discounts));
} else {
$errors = edd_get_errors();
$return['msg'] = $errors['edd-discount-error'];
edd_unset_error('edd-discount-error');
}
// Allow for custom discount code handling
$return = apply_filters('edd_ajax_discount_response', $return);
echo json_encode($return);
}
edd_die();
}
示例4: edd_display_cart_discount
/**
* Show the fully formatted cart discount
*
* @since 1.4.1
* @param bool $formatted
* @param bool $echo Echo?
* @return string $amount Fully formatted cart discount
*/
function edd_display_cart_discount($formatted = false, $echo = false)
{
$discounts = edd_get_cart_discounts();
if (empty($discounts)) {
return false;
}
$discount_id = edd_get_discount_id_by_code($discounts[0]);
$amount = edd_format_discount_rate(edd_get_discount_type($discount_id), edd_get_discount_amount($discount_id));
if ($echo) {
echo $amount;
}
return $amount;
}
示例5: discount_codes_data
/**
* Retrieve all the data for all the discount codes
*
* @access public
* @since 1.4
* @return array $discount_codes_data Array of all the data for the discount codes
*/
public function discount_codes_data()
{
$discount_codes_data = array();
$per_page = $this->per_page;
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'ID';
$order = isset($_GET['order']) ? $_GET['order'] : 'DESC';
$status = isset($_GET['status']) ? $_GET['status'] : array('active', 'inactive');
$meta_key = isset($_GET['meta_key']) ? $_GET['meta_key'] : null;
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : null;
$discounts = edd_get_discounts(array('posts_per_page' => $per_page, 'paged' => isset($_GET['paged']) ? $_GET['paged'] : 1, 'orderby' => $orderby, 'order' => $order, 'post_status' => $status, 'meta_key' => $meta_key, 's' => $search));
if ($discounts) {
foreach ($discounts as $discount) {
if (edd_get_discount_max_uses($discount->ID)) {
$uses = edd_get_discount_uses($discount->ID) . '/' . edd_get_discount_max_uses($discount->ID);
} else {
$uses = edd_get_discount_uses($discount->ID);
}
if (edd_get_discount_max_uses($discount->ID)) {
$max_uses = edd_get_discount_max_uses($discount->ID) ? edd_get_discount_max_uses($discount->ID) : __('unlimited', 'edd');
} else {
$max_uses = __('Unlimited', 'edd');
}
$start_date = edd_get_discount_start_date($discount->ID);
if (!empty($start_date)) {
$discount_start_date = date_i18n(get_option('date_format'), strtotime($start_date));
} else {
$discount_start_date = __('No start date', 'edd');
}
if (edd_get_discount_expiration($discount->ID)) {
$expiration = date_i18n(get_option('date_format'), strtotime(edd_get_discount_expiration($discount->ID)));
} else {
$expiration = __('No expiration', 'edd');
}
$discount_codes_data[] = array('ID' => $discount->ID, 'name' => get_the_title($discount->ID), 'code' => edd_get_discount_code($discount->ID), 'amount' => edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID)), 'uses' => $uses, 'max_uses' => $max_uses, 'start_date' => $discount_start_date, 'expiration' => $expiration, 'status' => edd_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status);
}
}
return $discount_codes_data;
}
示例6: edd_ajax_apply_discount
/**
* Validates the supplied discount sent via AJAX.
*
* @since 1.0
* @return void
*/
function edd_ajax_apply_discount()
{
if (isset($_POST['code']) && check_ajax_referer('edd_checkout_nonce', 'nonce')) {
$user = isset($_POST['user']) ? $_POST['user'] : $_POST['email'];
$return = array('msg' => '', 'code' => $_POST['code']);
if (edd_is_discount_used($_POST['code'], $user)) {
// Called twice if discount is not used (again by edd_is_discount_valid) but allows for beter usr msg and less execution if discount is used.
$return['msg'] = __('This discount code has been used already', 'edd');
} else {
if (edd_is_discount_valid($_POST['code'], $user)) {
$discount = edd_get_discount_by_code($_POST['code']);
$amount = edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID));
$discounts = edd_set_cart_discount($_POST['code']);
$total = edd_get_cart_total($discounts);
$return = array('msg' => 'valid', 'amount' => $amount, 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $_POST['code'], 'html' => edd_get_cart_discounts_html($discounts));
} else {
$return['msg'] = __('The discount you entered is invalid', 'edd');
}
}
echo json_encode($return);
}
edd_die();
}
示例7: pp_edd_get_cart_discounts_html
/**
* Discount remove icon
*/
function pp_edd_get_cart_discounts_html($html, $discounts, $rate, $remove_url)
{
if (!$discounts) {
$discounts = edd_get_cart_discounts();
}
if (!$discounts) {
return;
}
$html = '';
foreach ($discounts as $discount) {
$discount_id = edd_get_discount_id_by_code($discount);
$rate = edd_format_discount_rate(edd_get_discount_type($discount_id), edd_get_discount_amount($discount_id));
$remove_url = add_query_arg(array('edd_action' => 'remove_cart_discount', 'discount_id' => $discount_id, 'discount_code' => $discount), edd_get_checkout_uri());
$svg = '<svg width="16" height="16" viewBox="0 0 16 16"><use xlink:href="' . get_stylesheet_directory_uri() . "/images/svg-defs.svg#icon-remove" . '"></use></svg>';
$html .= "<span class=\"edd_discount\">\n";
$html .= "<span class=\"edd_discount_rate\">{$discount} – {$rate}</span>\n";
$html .= "<a href=\"{$remove_url}\" data-code=\"{$discount}\" class=\"edd_discount_remove\">{$svg}</a>\n";
$html .= "</span>\n";
}
return $html;
}
示例8: edd_ajax_apply_discount
/**
* Validates the supplied discount sent via AJAX.
*
* @since 1.0
* @return void
*/
function edd_ajax_apply_discount()
{
if (isset($_POST['code'])) {
$discount_code = $_POST['code'];
$return = array('msg' => '', 'code' => $discount_code);
if (edd_is_discount_valid($discount_code)) {
$discount = edd_get_discount_by_code($discount_code);
$amount = edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID));
$discounts = edd_set_cart_discount($discount_code);
$total = edd_get_cart_total($discounts);
$return = array('msg' => 'valid', 'amount' => $amount, 'total_plain' => $total, 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $_POST['code'], 'html' => edd_get_cart_discounts_html($discounts));
} else {
$errors = edd_get_errors();
$return['msg'] = $errors['edd-discount-error'];
edd_unset_error('edd-discount-error');
}
// Allow for custom discount code handling
$return = apply_filters('edd_ajax_discount_response', $return);
echo json_encode($return);
}
edd_die();
}
示例9: edd_discounts_page
//.........这里部分代码省略.........
</th>
<th><?php
_e('Status', 'edd');
?>
</th>
<th><?php
_e('Actions', 'edd');
?>
</th>
</tr>
</tfoot>
<tbody>
<?php
if ($discounts) {
?>
<?php
foreach ($discounts as $discount_key => $discount) {
?>
<tr>
<td><?php
if (isset($discount['name'])) {
echo $discount['name'];
}
?>
</td>
<td><?php
if (isset($discount['code'])) {
echo $discount['code'];
}
?>
</td>
<td><?php
if (isset($discount['amount'])) {
echo edd_format_discount_rate($discount['type'], $discount['amount']);
}
?>
</td>
<td>
<?php
if (isset($discount['uses']) && isset($discount['max']) && $discount['uses'] != '' && $discount['max'] != '') {
echo $discount['uses'] == '' ? 0 : $discount['uses'] . '/' . $discount['max'];
} else {
echo isset($discount['uses']) ? $discount['uses'] : 0;
}
?>
</td>
<td>
<?php
if (isset($discount['max'])) {
echo $discount['max'] == '' ? __('unlimited', 'edd') : $discount['max'];
} else {
_e('unlimited', 'edd');
}
?>
</td>
<td>
<?php
if (isset($discount['start']) && $discount['start'] != '') {
echo date(get_option('date_format'), strtotime($discount['start']));
} else {
_e('No start date', 'edd');
}
?>
</td>
<td>
<?php