installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/**
|
||||
* Add Discount Page
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Discounts
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( 'Add New Discount', 'easy-digital-downloads' ); ?></h1>
|
||||
|
||||
<hr class="wp-header-end">
|
||||
|
||||
<form id="edd-add-discount" action="" method="post">
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_top' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_name' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-name"><?php esc_html_e( 'Name', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input name="name" required="required" id="edd-name" type="text" value="" placeholder="<?php esc_html_e( 'Summer Sale', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php esc_html_e( 'The name of this discount. Customers will see this on checkout.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_code' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-code"><?php esc_html_e( 'Code', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" required="required" id="edd-code" name="code" class="code" value="" pattern="[a-zA-Z0-9-_]+" placeholder="<?php esc_html_e( '10PERCENT', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php esc_html_e( 'The code customers will enter to apply this discount. Only alphanumeric characters are allowed.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_type' ); ?>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_amount' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-amount"><?php esc_html_e( 'Amount', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<span class="edd-amount-type-wrapper">
|
||||
<input type="text" required="required" class="edd-price-field" id="edd-amount" name="amount" value="" placeholder="<?php esc_html_e( '10.00', 'easy-digital-downloads' ); ?>"/>
|
||||
<label for="edd-amount-type" class="screen-reader-text"><?php esc_html_e( 'Amount Type', 'easy-digital-downloads' ); ?></label>
|
||||
<select name="amount_type" id="edd-amount-type">
|
||||
<option value="percent">%</option>
|
||||
<option value="flat"><?php echo esc_html( edd_currency_symbol() ); ?></option>
|
||||
</select>
|
||||
</span>
|
||||
<p class="description"><?php esc_html_e( 'The amount as a percentage or flat rate. Cannot be left blank.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_products' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd_products"><?php printf( esc_html__( '%s Requirements', 'easy-digital-downloads' ), edd_get_label_singular() ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo EDD()->html->product_dropdown( array(
|
||||
'name' => 'product_reqs[]',
|
||||
'id' => 'edd_products',
|
||||
'selected' => array(),
|
||||
'multiple' => true,
|
||||
'chosen' => true,
|
||||
'placeholder' => sprintf( esc_html__( 'Select %s', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ),
|
||||
) ); // WPCS: XSS ok. ?>
|
||||
<div id="edd-discount-product-conditions" style="display:none;">
|
||||
<p>
|
||||
<select id="edd-product-condition" name="product_condition">
|
||||
<option value="all"><?php printf( esc_html__( 'Cart must contain all selected %s', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ); ?></option>
|
||||
<option value="any"><?php printf( esc_html__( 'Cart needs one or more of the selected %s', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
<input type="radio" class="tog" name="scope" value="global" checked="checked"/>
|
||||
<?php esc_html_e( 'Apply discount to entire purchase.', 'easy-digital-downloads' ); ?>
|
||||
</label><br/>
|
||||
<label>
|
||||
<input type="radio" class="tog" name="scope" value="not_global"/>
|
||||
<?php printf( esc_html__( 'Apply discount only to selected %s.', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ); ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
<p class="description"><?php printf( esc_html__( '%s this discount can only be applied to. Leave blank for any.', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_excluded_products' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-excluded-products"><?php printf( esc_html__( 'Excluded %s', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo EDD()->html->product_dropdown( array(
|
||||
'name' => 'excluded_products[]',
|
||||
'id' => 'excluded_products',
|
||||
'selected' => array(),
|
||||
'multiple' => true,
|
||||
'chosen' => true,
|
||||
'placeholder' => sprintf( esc_html__( 'Select %s', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ),
|
||||
) ); // WPCS: XSS ok. ?>
|
||||
<p class="description"><?php printf( esc_html__( '%s this discount cannot be applied to. Leave blank for none.', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_start' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-start"><?php esc_html_e( 'Start date', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td class="edd-discount-datetime">
|
||||
<input name="start_date" id="edd-start" type="text" value="" class="edd_datepicker" data-format="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" placeholder="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" />
|
||||
|
||||
<label class="screen-reader-text" for="start-date-hour">
|
||||
<?php esc_html_e( 'Start Date Hour', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="24" step="1" name="start_date_hour" id="start-date-hour" placeholder="00" />
|
||||
:
|
||||
|
||||
<label class="screen-reader-text" for="start-date-minute">
|
||||
<?php esc_html_e( 'Start Date Minute', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="59" step="1" name="start_date_minute" id="start-date-minute" placeholder="00" />
|
||||
|
||||
<?php echo esc_html( ' (' . edd_get_timezone_abbr() . ')' ); ?>
|
||||
<p class="description"><?php esc_html_e( 'Pick the date and time this discount will start on. Leave blank for no start date.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_expiration' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-expiration"><?php esc_html_e( 'Expiration date', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td class="edd-discount-datetime">
|
||||
<input name="end_date" id="edd-expiration" type="text" class="edd_datepicker" data-format="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" placeholder="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" />
|
||||
|
||||
<label class="screen-reader-text" for="end-date-hour">
|
||||
<?php esc_html_e( 'Expiration Date Hour', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="24" step="1" name="end_date_hour" id="end-date-hour" placeholder="23" />
|
||||
:
|
||||
|
||||
<label class="screen-reader-text" for="end-date-minute">
|
||||
<?php esc_html_e( 'Expiration Date Minute', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="59" step="1" name="end_date_minute" id="end-date-minute" placeholder="59" />
|
||||
|
||||
<?php echo esc_html( ' (' . edd_get_timezone_abbr() . ')' ); ?>
|
||||
<p class="description"><?php esc_html_e( 'Pick the date and time this discount will expire on. Leave blank to never expire.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_min_cart_amount' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-min-cart-amount"><?php esc_html_e( 'Minimum Amount', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" id="edd-min-cart-amount" name="min_charge_amount" value="" placeholder="<?php esc_html_e( 'No minimum', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php esc_html_e( 'The minimum subtotal of item prices in a cart before this discount may be applied.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_max_uses' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-max-uses"><?php esc_html_e( 'Max Uses', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" id="edd-max-uses" name="max_uses" value="" placeholder="<?php esc_html_e( 'Unlimited', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php esc_html_e( 'The maximum number of times this discount can be used.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_before_use_once' ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-use-once"><?php esc_html_e( 'Use Once Per Customer', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" id="edd-use-once" name="once_per_customer" value="1"/>
|
||||
<span class="description"><?php esc_html_e( 'Prevent customers from using this discount more than once.', 'easy-digital-downloads' ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Action after "Use Once Per Customer" checkbox.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
?>
|
||||
<?php do_action( 'edd_add_discount_form_after_use_once' ); ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php do_action( 'edd_add_discount_form_bottom' ); ?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name="type" value="discount" />
|
||||
<input type="hidden" name="edd-action" value="add_discount"/>
|
||||
<input type="hidden" name="edd-redirect" value="<?php echo esc_url( edd_get_admin_url( array( 'page' => 'edd-discounts' ) ) ); ?>"/>
|
||||
<input type="hidden" name="edd-discount-nonce" value="<?php echo esc_attr( wp_create_nonce( 'edd_discount_nonce' ) ); ?>"/>
|
||||
<input type="submit" value="<?php esc_html_e( 'Add Discount Code', 'easy-digital-downloads' ); ?>" class="button-primary"/>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
@ -0,0 +1,430 @@
|
||||
<?php
|
||||
/**
|
||||
* Discount Codes Table Class
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Discounts
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.4
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use EDD\Admin\List_Table;
|
||||
|
||||
/**
|
||||
* EDD_Discount_Codes_Table Class
|
||||
*
|
||||
* Renders the Discount Codes table on the Discount Codes page
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 3.0 Updated to work with the discount code migration to custom tables.
|
||||
*/
|
||||
class EDD_Discount_Codes_Table extends List_Table {
|
||||
|
||||
/**
|
||||
* Get things started
|
||||
*
|
||||
* @since 1.4
|
||||
* @see WP_List_Table::__construct()
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct( array(
|
||||
'singular' => 'discount',
|
||||
'plural' => 'discounts',
|
||||
'ajax' => false,
|
||||
) );
|
||||
|
||||
$this->process_bulk_action();
|
||||
$this->get_counts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for the discount list table
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_base_url() {
|
||||
|
||||
// Remove some query arguments
|
||||
$base = remove_query_arg( edd_admin_removable_query_args(), edd_get_admin_base_url() );
|
||||
|
||||
// Add base query args
|
||||
return add_query_arg( array(
|
||||
'page' => 'edd-discounts',
|
||||
), $base );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the table columns
|
||||
*
|
||||
* @since 1.4
|
||||
*
|
||||
* @return array $columns Array of all the list table columns
|
||||
*/
|
||||
public function get_columns() {
|
||||
return apply_filters( 'edd_discounts_table_columns', array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'name' => __( 'Name', 'easy-digital-downloads' ),
|
||||
'code' => __( 'Code', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Amount', 'easy-digital-downloads' ),
|
||||
'use_count' => __( 'Uses', 'easy-digital-downloads' ),
|
||||
'start_date' => __( 'Start Date', 'easy-digital-downloads' ),
|
||||
'end_date' => __( 'End Date', 'easy-digital-downloads' )
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the sortable columns
|
||||
*
|
||||
* @since 1.4
|
||||
*
|
||||
* @return array Array of all the sortable columns
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
return apply_filters( 'edd_discounts_table_sortable_columns', array(
|
||||
'name' => array( 'name', false ),
|
||||
'code' => array( 'code', false ),
|
||||
'use_count' => array( 'use_count', false ),
|
||||
'start_date' => array( 'start_date', false ),
|
||||
'end_date' => array( 'end_date', false )
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the primary column.
|
||||
*
|
||||
* @since 2.5
|
||||
* @access protected
|
||||
*
|
||||
* @return string Name of the primary column.
|
||||
*/
|
||||
protected function get_primary_column_name() {
|
||||
return 'name';
|
||||
}
|
||||
|
||||
/**
|
||||
* This function renders most of the columns in the list table.
|
||||
*
|
||||
* @since 1.4
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @param string $column_name The name of the column
|
||||
*
|
||||
* @return string Column Name
|
||||
*/
|
||||
public function column_default( $discount, $column_name ) {
|
||||
$value = property_exists( $discount, $column_name ) ? $discount->$column_name : '';
|
||||
|
||||
return apply_filters( 'edd_discounts_table_column', $value, $discount, $column_name );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function renders the amount column.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param EDD_Discount $discount Data for the discount code.
|
||||
* @return string Formatted amount.
|
||||
*/
|
||||
public function column_amount( $discount ) {
|
||||
return edd_format_discount_rate( $discount->type, $discount->amount );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function renders the start column.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @return string Start date
|
||||
*/
|
||||
public function column_start_date( $discount ) {
|
||||
$start_date = $discount->start_date;
|
||||
$timezone_abbreviation = edd_get_timezone_abbr();
|
||||
|
||||
if ( $start_date ) {
|
||||
$display = edd_date_i18n( $start_date, 'M. d, Y' ) . '<br>' . edd_date_i18n( $start_date, 'H:i' ) . ' ' . $timezone_abbreviation;
|
||||
} else {
|
||||
$display = '—';
|
||||
}
|
||||
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Expiration column.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @return string Expiration date.
|
||||
*/
|
||||
public function column_end_date( $discount ) {
|
||||
$expiration = $discount->end_date;
|
||||
$timezone_abbreviation = edd_get_timezone_abbr();
|
||||
|
||||
if ( $expiration ) {
|
||||
$display = edd_date_i18n( $expiration, 'M. d, Y' ) . '<br>' . edd_date_i18n( $expiration, 'H:i' ) . ' ' . $timezone_abbreviation;
|
||||
} else {
|
||||
$display = '—';
|
||||
}
|
||||
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Name column.
|
||||
*
|
||||
* @since 1.4
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @return string Data shown in the Name column
|
||||
*/
|
||||
public function column_name( $discount ) {
|
||||
$base = $this->get_base_url();
|
||||
$state = '';
|
||||
$row_actions = array();
|
||||
$status = $this->get_status();
|
||||
|
||||
// Bail if current user cannot manage discounts
|
||||
if ( ! current_user_can( 'manage_shop_discounts' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// State
|
||||
if ( ( ! empty( $status ) && ( $status !== $discount->status ) ) || ( 'active' !== $discount->status ) ) {
|
||||
$state = ' — ' . edd_get_discount_status_label( $discount->id );
|
||||
}
|
||||
|
||||
// Edit
|
||||
$row_actions['edit'] = '<a href="' . esc_url( add_query_arg( array(
|
||||
'edd-action' => 'edit_discount',
|
||||
'discount' => absint( $discount->id ),
|
||||
), $base ) ) . '">' . __( 'Edit', 'easy-digital-downloads' ) . '</a>';
|
||||
|
||||
// Active, so add "deactivate" action
|
||||
if ( 'active' === strtolower( $discount->status ) ) {
|
||||
$row_actions['cancel'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
|
||||
'edd-action' => 'deactivate_discount',
|
||||
'discount' => absint( $discount->id ),
|
||||
), $base ), 'edd_discount_nonce' ) ) . '">' . __( 'Deactivate', 'easy-digital-downloads' ) . '</a>';
|
||||
|
||||
// Inactive, so add "activate" action
|
||||
} elseif ( 'inactive' === strtolower( $discount->status ) ) {
|
||||
$row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
|
||||
'edd-action' => 'activate_discount',
|
||||
'discount' => absint( $discount->id ),
|
||||
), $base ), 'edd_discount_nonce' ) ) . '">' . __( 'Activate', 'easy-digital-downloads' ) . '</a>';
|
||||
}
|
||||
|
||||
// Delete
|
||||
if ( 0 === (int) $discount->use_count ) {
|
||||
$row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
|
||||
'edd-action' => 'delete_discount',
|
||||
'discount' => absint( $discount->id ),
|
||||
), $base ), 'edd_discount_nonce' ) ) . '">' . __( 'Delete', 'easy-digital-downloads' ) . '</a>';
|
||||
} else {
|
||||
$row_actions['orders'] = '<a href="' . esc_url(
|
||||
edd_get_admin_url(
|
||||
array(
|
||||
'page' => 'edd-payment-history',
|
||||
'discount_id' => absint( $discount->id ),
|
||||
)
|
||||
)
|
||||
) . '">' . __( 'View Orders', 'easy-digital-downloads' ) . '</a>';
|
||||
}
|
||||
|
||||
// Filter all discount row actions
|
||||
$row_actions = apply_filters( 'edd_discount_row_actions', $row_actions, $discount );
|
||||
|
||||
// Wrap discount title in strong anchor
|
||||
$discount_title = '<strong><a class="row-title" href="' . esc_url( add_query_arg( array(
|
||||
'edd-action' => 'edit_discount',
|
||||
'discount' => absint( $discount->id ),
|
||||
), $base ) ) . '">' . stripslashes( $discount->name ) . '</a>' . esc_html( $state ) . '</strong>';
|
||||
|
||||
/**
|
||||
* Filter to allow additional content to be appended to the discount title.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @param string $base The base URL for the discount list table.
|
||||
* @param string $status The queried discount status.
|
||||
* @return string Additional data shown in the Name column
|
||||
*/
|
||||
$additional_content = apply_filters( 'edd_discount_row_after_title', '', $discount, $base, $status );
|
||||
|
||||
// Return discount title & row actions
|
||||
return $discount_title . $additional_content . $this->row_actions( $row_actions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the checkbox column.
|
||||
*
|
||||
* @since 1.4
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @return string Checkbox HTML.
|
||||
*/
|
||||
public function column_cb( $discount ) {
|
||||
return sprintf(
|
||||
'<input type="checkbox" name="%1$s[]" id="%1$s-%2$s" value="%2$s" /><label for="%1$s-%2$s" class="screen-reader-text">%3$s</label>',
|
||||
/*$1%s*/ 'discount',
|
||||
/*$2%s*/ absint( $discount->id ),
|
||||
/* translators: discount name */
|
||||
esc_html( sprintf( __( 'Select %s', 'easy-digital-downloads' ), $discount->name ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return discount code wrapped in a `<code>` tag.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param EDD_Discount $discount Discount object.
|
||||
* @return string Discount code HTML.
|
||||
*/
|
||||
public function column_code( $discount ) {
|
||||
return '<code class="edd-discount-code">' . $discount->code . '</code>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Message to be displayed when there are no items.
|
||||
*
|
||||
* @since 1.7.2
|
||||
*/
|
||||
public function no_items() {
|
||||
esc_html_e( 'No discounts found.', 'easy-digital-downloads' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the bulk actions
|
||||
*
|
||||
* @since 1.4
|
||||
* @return array $actions Array of the bulk actions
|
||||
*/
|
||||
public function get_bulk_actions() {
|
||||
return array(
|
||||
'activate' => __( 'Activate', 'easy-digital-downloads' ),
|
||||
'deactivate' => __( 'Deactivate', 'easy-digital-downloads' ),
|
||||
'delete' => __( 'Delete', 'easy-digital-downloads' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process bulk actions.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public function process_bulk_action() {
|
||||
|
||||
// Bail if a nonce was not supplied.
|
||||
if ( ! isset( $_REQUEST['_wpnonce'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-discounts' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
check_admin_referer( 'bulk-discounts' );
|
||||
|
||||
$ids = wp_parse_id_list( (array) $this->get_request_var( 'discount', false ) );
|
||||
|
||||
// Bail if no IDs
|
||||
if ( empty( $ids ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $ids as $id ) {
|
||||
switch ( $this->current_action() ) {
|
||||
case 'delete':
|
||||
edd_delete_discount( $id );
|
||||
break;
|
||||
|
||||
case 'cancel':
|
||||
edd_update_discount_status( $id, 'cancelled' );
|
||||
break;
|
||||
|
||||
case 'activate':
|
||||
edd_update_discount_status( $id, 'active' );
|
||||
break;
|
||||
|
||||
case 'deactivate':
|
||||
edd_update_discount_status( $id, 'inactive' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the discount code counts.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public function get_counts() {
|
||||
$this->counts = edd_get_discount_counts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the data for all the discount codes.
|
||||
*
|
||||
* @since 1.4
|
||||
* @deprecated 3.0 Use get_data()
|
||||
*
|
||||
* @return array Discount codes.
|
||||
*/
|
||||
public function discount_codes_data() {
|
||||
_edd_deprecated_function( __METHOD__, '3.0', 'EDD_Discount_Codes_Table::get_data()' );
|
||||
|
||||
return $this->get_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all of the table data for the discount codes.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array Discount codes table data.
|
||||
*/
|
||||
public function get_data() {
|
||||
|
||||
// Parse pagination
|
||||
$this->args = $this->parse_pagination_args( array(
|
||||
'status' => $this->get_status(),
|
||||
'search' => $this->get_search(),
|
||||
) );
|
||||
|
||||
// Return data
|
||||
return edd_get_discounts( $this->args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the final data for the table
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public function prepare_items() {
|
||||
$columns = $this->get_columns();
|
||||
$hidden = array();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
|
||||
$this->_column_headers = array( $columns, $hidden, $sortable );
|
||||
$this->items = $this->get_data();
|
||||
|
||||
$status = $this->get_status( 'total' );
|
||||
|
||||
// Setup pagination
|
||||
$this->set_pagination_args( array(
|
||||
'total_pages' => ceil( $this->counts[ $status ] / $this->per_page ),
|
||||
'total_items' => $this->counts[ $status ],
|
||||
'per_page' => $this->per_page,
|
||||
) );
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Contextual Help
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Discounts
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.2.3
|
||||
*/
|
||||
|
||||
use EDD\Admin\Pass_Manager;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Adds the Contextual Help for the Discount Codes Page
|
||||
*
|
||||
* @since 1.3
|
||||
* @return void
|
||||
*/
|
||||
function edd_discounts_contextual_help() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
$pass_manager = new Pass_Manager();
|
||||
if ( $pass_manager->isFree() ) {
|
||||
$docs_url = edd_link_helper(
|
||||
'https://easydigitaldownloads.com/docs/',
|
||||
array(
|
||||
'utm_medium' => 'discounts-contextual-help',
|
||||
'utm_content' => 'documentation',
|
||||
)
|
||||
);
|
||||
|
||||
$upgrade_url = edd_link_helper(
|
||||
'https://easydigitaldownloads.com/lite-upgrade/',
|
||||
array(
|
||||
'utm_medium' => 'discounts-contextual-help',
|
||||
'utm_content' => 'lite-upgrade',
|
||||
)
|
||||
);
|
||||
$screen->set_help_sidebar(
|
||||
'<p><strong>' . __( 'For more information:', 'easy-digital-downloads' ) . '</strong></p>' .
|
||||
'<p>' . sprintf( __( 'Visit the <a href="%s">documentation</a> on the Easy Digital Downloads website.', 'easy-digital-downloads' ), $docs_url ) . '</p>' .
|
||||
'<p>' . sprintf(
|
||||
__( 'Need more from your Easy Digital Downloads store? <a href="%s">Upgrade Now</a>!', 'easy-digital-downloads' ),
|
||||
$upgrade_url
|
||||
) . '</p>'
|
||||
);
|
||||
}
|
||||
|
||||
$screen->add_help_tab( array(
|
||||
'id' => 'edd-discount-general',
|
||||
'title' => __( 'General', 'easy-digital-downloads' ),
|
||||
'content' =>
|
||||
'<p>' . __( 'Discount codes allow you to offer buyers special discounts by having them enter predefined codes during checkout.', 'easy-digital-downloads' ) . '</p>' .
|
||||
'<p>' . __( 'Discount codes that are set to "inactive" cannot be redeemed.', 'easy-digital-downloads' ) . '</p>' .
|
||||
'<p>' . __( 'Discount codes can be setup to only be used only one time by each customer. If a customer attempts to use a code a second time, they will be given an error.', 'easy-digital-downloads' ) . '</p>' .
|
||||
'<p>' . __( 'Discount codes that have already been used cannot be deleted for data integrity and reporting purposes.', 'easy-digital-downloads' ) . '</p>'
|
||||
) );
|
||||
|
||||
$screen->add_help_tab( array(
|
||||
'id' => 'edd-discount-add',
|
||||
'title' => __( 'Adding Discounts', 'easy-digital-downloads' ),
|
||||
'content' =>
|
||||
'<p>' . __( 'You can create any number of discount codes easily from this page.', 'easy-digital-downloads' ) . '</p>' .
|
||||
'<p>' . __( 'Discount codes have several options:', 'easy-digital-downloads' ) . '</p>' .
|
||||
'<ul>'.
|
||||
'<li>' . __( '<strong>Name</strong> - this is the name given to the discount. Used primarily for administrative purposes.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Code</strong> - this is the unique code that customers will enter during checkout to redeem the code.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Type</strong> - this is the type of discount this code awards.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Amount</strong> - this is the discount amount provided by this code. For percentage based discounts, enter a number such as 70 for 70%. Do not enter a percent sign.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Requirements</strong> - this allows you to select the product(s) that are required to be purchased in order for a discount to be applied.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Condition</strong> - this lets you set whether all selected products must be in the cart, or just a minimum of one.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Apply discount only to selected Downloads?</strong> - If this box is checked, only the prices of the required products will be discounted. If left unchecked, the discount will apply to all products in the cart.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Start Date</strong> - this is the date that this code becomes available. If a customer attempts to redeem the code prior to this date, they will be given an error. This is optional.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Expiration Date</strong> - this is the end date for the discount. After this date, the code will no longer be able to be used. This is optional.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Minimum Amount</strong> - this is the minimum purchase amount required to use this code. If a customer has less than this amount in their cart, they will be given an error. This is optional.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'<li>' . __( '<strong>Max Uses</strong> - this is the maximum number of times this discount can be redeemed. Once this number is reached, no more customers will be allowed to use it.', 'easy-digital-downloads' ) . '</li>' .
|
||||
'</ul>'
|
||||
) );
|
||||
|
||||
do_action( 'edd_discounts_contextual_help', $screen );
|
||||
}
|
||||
add_action( 'load-download_page_edd-discounts', 'edd_discounts_contextual_help' );
|
@ -0,0 +1,394 @@
|
||||
<?php
|
||||
/**
|
||||
* Discount Actions
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Discounts
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0.8.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Sets up and stores a new discount code.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 3.0 Added backwards compatibility for pre-3.0 discount data. Added discount start/end time.
|
||||
*
|
||||
* @param array $data Discount code data.
|
||||
*/
|
||||
function edd_admin_add_discount( $data = array() ) {
|
||||
|
||||
// Bail if no nonce or nonce fails.
|
||||
if ( ! isset( $data['edd-discount-nonce'] ) || ! wp_verify_nonce( $data['edd-discount-nonce'], 'edd_discount_nonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if current user cannot manage shop discounts.
|
||||
if ( ! current_user_can( 'manage_shop_discounts' ) ) {
|
||||
wp_die( __( 'You do not have permission to create discount codes', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Bail if discount does not exist.
|
||||
if ( edd_get_discount_by( 'code', $data['code'] ) ) {
|
||||
edd_redirect( add_query_arg( 'edd-message', 'discount_exists', $data['edd-redirect'] ) );
|
||||
}
|
||||
|
||||
// Bail if missing important data.
|
||||
if ( empty( $data['name'] ) || empty( $data['code'] ) || empty( $data['amount_type'] ) || ( empty( $data['amount'] ) && 0 !== absint( $data['amount'] ) ) ) {
|
||||
edd_redirect( add_query_arg( 'edd-message', 'discount_validation_failed' ) );
|
||||
}
|
||||
|
||||
// Verify only accepted characters.
|
||||
$sanitized = preg_replace( '/[^a-zA-Z0-9-_]+/', '', $data['code'] );
|
||||
if ( strtoupper( $data['code'] ) !== strtoupper( $sanitized ) ) {
|
||||
edd_redirect( add_query_arg( 'edd-message', 'discount_invalid_code' ) );
|
||||
}
|
||||
|
||||
if ( ! is_numeric( $data['amount'] ) ) {
|
||||
edd_redirect( add_query_arg( 'edd-message', 'discount_invalid_amount' ) );
|
||||
}
|
||||
|
||||
// Setup default discount values.
|
||||
$to_add = array();
|
||||
$to_add['status'] = 'active';
|
||||
$current_timestamp = current_time( 'timestamp' );
|
||||
|
||||
$data = array_filter( $data );
|
||||
|
||||
foreach ( $data as $column => $value ) {
|
||||
switch ( $column ) {
|
||||
|
||||
// We skip these here as they are handled below.
|
||||
case 'start_date':
|
||||
case 'start':
|
||||
case 'end_date':
|
||||
case 'expiration':
|
||||
break;
|
||||
|
||||
case 'product_reqs':
|
||||
$to_add[ $column ] = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
$to_add[ $column ] = is_array( $value )
|
||||
? array_map( 'sanitize_text_field', $value )
|
||||
: sanitize_text_field( $value );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Start date.
|
||||
if ( ! empty( $data['start_date'] ) ) {
|
||||
$start_date = sanitize_text_field( $data['start_date'] );
|
||||
$start_date_hour = isset( $data['start_date_hour'] ) && (int) $data['start_date_hour'] >= 0 && (int) $data['start_date_hour'] <= 23
|
||||
? intval( $data['start_date_hour'] )
|
||||
: '00';
|
||||
$start_date_minute = isset( $data['start_date_minute'] ) && (int) $data['start_date_minute'] >= 0 && (int) $data['start_date_minute'] <= 59
|
||||
? intval( $data['start_date_minute'] )
|
||||
: '00';
|
||||
|
||||
// The start date is entered in the user's WP timezone. We need to convert it to UTC prior to saving now.
|
||||
$date = edd_get_utc_equivalent_date( EDD()->utils->date( $start_date . ' ' . $start_date_hour . ':' . $start_date_minute . ':00', edd_get_timezone_id(), false ) );
|
||||
$to_add['start_date'] = $date->format( 'Y-m-d H:i:s' );
|
||||
}
|
||||
|
||||
// End date.
|
||||
if ( ! empty( $data['end_date'] ) ) {
|
||||
$end_date = sanitize_text_field( $data['end_date'] );
|
||||
$end_date_hour = isset( $data['end_date_hour'] ) && (int) $data['end_date_hour'] >= 0 && (int) $data['end_date_hour'] <= 23
|
||||
? intval( $data['end_date_hour'] )
|
||||
: '23';
|
||||
$end_date_minute = isset( $data['end_date_minute'] ) && (int) $data['end_date_minute'] >= 0 && (int) $data['end_date_minute'] <= 59
|
||||
? intval( $data['end_date_minute'] )
|
||||
: '59';
|
||||
|
||||
// The end date is entered in the user's WP timezone. We need to convert it to UTC prior to saving now.
|
||||
$date = edd_get_utc_equivalent_date( EDD()->utils->date( $end_date . ' ' . $end_date_hour . ':' . $end_date_minute . ':00', edd_get_timezone_id(), false ) );
|
||||
$to_add['end_date'] = $date->format( 'Y-m-d H:i:s' );
|
||||
}
|
||||
|
||||
// Meta values.
|
||||
$to_add['product_reqs'] = isset( $data['product_reqs'] ) ? wp_parse_id_list( $data['product_reqs'] ) : '';
|
||||
$to_add['excluded_products'] = isset( $data['excluded_products'] ) ? wp_parse_id_list( $data['excluded_products'] ) : '';
|
||||
|
||||
$to_add = array_filter( $to_add );
|
||||
|
||||
// Strip out data that should not be sent to the query methods.
|
||||
$to_strip = array(
|
||||
'discount-id',
|
||||
'edd-redirect',
|
||||
'edd-action',
|
||||
'edd-discount-nonce',
|
||||
'start_date_minute',
|
||||
'start_date_hour',
|
||||
'end_date_minute',
|
||||
'end_date_hour',
|
||||
);
|
||||
|
||||
// Loop through fields to update, and unset known bad keys.
|
||||
foreach ( $to_add as $key => $value ) {
|
||||
if ( in_array( $key, $to_strip, true ) ) {
|
||||
unset( $to_add[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to add.
|
||||
$created = edd_add_discount( $to_add );
|
||||
$arg = ! empty( $created )
|
||||
? 'discount_added'
|
||||
: 'discount_add_failed';
|
||||
|
||||
// Redirect.
|
||||
edd_redirect( add_query_arg( 'edd-message', sanitize_key( $arg ), $data['edd-redirect'] ) );
|
||||
}
|
||||
add_action( 'edd_add_discount', 'edd_admin_add_discount' );
|
||||
|
||||
/**
|
||||
* Saves an edited discount
|
||||
*
|
||||
* @since 3.0
|
||||
* @param array $data Discount code data
|
||||
* @return void
|
||||
*/
|
||||
function edd_admin_edit_discount( $data = array() ) {
|
||||
|
||||
// Bail if no nonce or nonce fails
|
||||
if ( ! isset( $data['edd-discount-nonce'] ) || ! wp_verify_nonce( $data['edd-discount-nonce'], 'edd_discount_nonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if current user cannot manage shop discounts
|
||||
if ( ! current_user_can( 'manage_shop_discounts' ) ) {
|
||||
wp_die( __( 'You do not have permission to edit discount codes', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Bail if discount does not exist
|
||||
if ( empty( $data['discount-id'] ) ) {
|
||||
wp_die( __( 'No discount ID supplied', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Setup default discount values
|
||||
$discount_id = absint( $data['discount-id'] );
|
||||
$discount = edd_get_discount( $discount_id );
|
||||
|
||||
// Bail if no discount
|
||||
if ( empty( $discount ) || ( $discount->id <= 0 ) ) {
|
||||
wp_die( __( 'Invalid discount', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
if ( empty( $data['amount'] ) || ! is_numeric( $data['amount'] ) ) {
|
||||
edd_redirect( add_query_arg( 'edd-message', 'discount_invalid_amount' ) );
|
||||
}
|
||||
|
||||
// Prepare update
|
||||
$to_update = array();
|
||||
$current_time = current_time( 'timestamp' );
|
||||
|
||||
$data = array_filter( $data );
|
||||
|
||||
foreach ( $data as $column => $value ) {
|
||||
switch ( $column ) {
|
||||
// We skip these here as they are handled below.
|
||||
case 'start_date':
|
||||
case 'start':
|
||||
case 'end_date':
|
||||
case 'expiration':
|
||||
break;
|
||||
|
||||
case 'discount-id':
|
||||
$to_update['id'] = $value;
|
||||
break;
|
||||
|
||||
default :
|
||||
$to_update[ $column ] = sanitize_text_field( $value );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Start date.
|
||||
if ( ! empty( $data['start_date'] ) ) {
|
||||
$start_date = sanitize_text_field( $data['start_date'] );
|
||||
$start_date_hour = isset( $data['start_date_hour'] ) && (int) $data['start_date_hour'] >= 0 && (int) $data['start_date_hour'] <= 23
|
||||
? intval( $data['start_date_hour'] )
|
||||
: '00';
|
||||
$start_date_minute = isset( $data['start_date_minute'] ) && (int) $data['start_date_minute'] >= 0 && (int) $data['start_date_minute'] <= 59
|
||||
? intval( $data['start_date_minute'] )
|
||||
: '00';
|
||||
|
||||
// The start date is entered in the user's WP timezone. We need to convert it to UTC prior to saving now.
|
||||
$date = edd_get_utc_equivalent_date( EDD()->utils->date( $start_date . ' ' . $start_date_hour . ':' . $start_date_minute . ':00', edd_get_timezone_id(), false ) );
|
||||
$to_update['start_date'] = $date->format( 'Y-m-d H:i:s' );
|
||||
} else {
|
||||
$to_update['start_date'] = null;
|
||||
}
|
||||
|
||||
// End date.
|
||||
if ( ! empty( $data['end_date'] ) ) {
|
||||
$end_date = sanitize_text_field( $data['end_date'] );
|
||||
$end_date_hour = isset( $data['end_date_hour'] ) && (int) $data['end_date_hour'] >= 0 && (int) $data['end_date_hour'] <= 23
|
||||
? intval( $data['end_date_hour'] )
|
||||
: '23';
|
||||
$end_date_minute = isset( $data['end_date_minute'] ) && (int) $data['end_date_minute'] >= 0 && (int) $data['end_date_minute'] <= 59
|
||||
? intval( $data['end_date_minute'] )
|
||||
: '59';
|
||||
|
||||
// The end date is entered in the user's WP timezone. We need to convert it to UTC prior to saving now.
|
||||
$date = edd_get_utc_equivalent_date( EDD()->utils->date( $end_date . ' ' . $end_date_hour . ':' . $end_date_minute . ':00', edd_get_timezone_id(), false ) );
|
||||
$to_update['end_date'] = $date->format( 'Y-m-d H:i:s' );
|
||||
} else {
|
||||
$to_update['end_date'] = null;
|
||||
}
|
||||
|
||||
// Known & accepted core discount meta
|
||||
$to_update['product_reqs'] = isset( $data['product_reqs'] ) ? wp_parse_id_list( $data['product_reqs'] ) : '';
|
||||
$to_update['excluded_products'] = isset( $data['excluded_products'] ) ? wp_parse_id_list( $data['excluded_products'] ) : '';
|
||||
|
||||
// "Once per customer" checkbox.
|
||||
$to_update['once_per_customer'] = isset( $data['once_per_customer'] )
|
||||
? 1
|
||||
: 0;
|
||||
|
||||
// Strip out known non-columns
|
||||
$to_strip = array(
|
||||
|
||||
// Legacy
|
||||
'discount-id',
|
||||
|
||||
// Redirect
|
||||
'edd-redirect',
|
||||
'edd-action',
|
||||
'edd-discount-nonce',
|
||||
'_wp_http_referer',
|
||||
|
||||
// Time
|
||||
'start_date_minute',
|
||||
'start_date_hour',
|
||||
'end_date_minute',
|
||||
'end_date_hour'
|
||||
);
|
||||
|
||||
// Loop through fields to update, and unset known bad keys
|
||||
foreach ( $to_update as $key => $value ) {
|
||||
if ( in_array( $key, $to_strip, true ) ) {
|
||||
unset( $to_update[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to update
|
||||
$updated = edd_update_discount( $discount_id, $to_update );
|
||||
$arg = ! empty( $updated )
|
||||
? 'discount_updated'
|
||||
: 'discount_not_changed';
|
||||
|
||||
// Redirect
|
||||
edd_redirect( add_query_arg( 'edd-message', sanitize_key( $arg ), $data['edd-redirect'] ) );
|
||||
}
|
||||
add_action( 'edd_edit_discount', 'edd_admin_edit_discount' );
|
||||
|
||||
/**
|
||||
* Listens for when a discount delete button is clicked and deletes the
|
||||
* discount code
|
||||
*
|
||||
* @since 3.0
|
||||
* @param array $data Discount code data
|
||||
* @uses edd_delete_discount()
|
||||
* @return void
|
||||
*/
|
||||
function edd_admin_delete_discount( $data = array() ) {
|
||||
|
||||
// Bail if no nonce or nonce fails
|
||||
if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'edd_discount_nonce' ) ) {
|
||||
wp_die( __( 'Trying to cheat or something?', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Bail if current user cannot manage shop
|
||||
if ( ! current_user_can( 'manage_shop_discounts' ) ) {
|
||||
wp_die( __( 'You do not have permission to delete discount codes', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Bail if discount does not exist
|
||||
if ( empty( $data['discount'] ) ) {
|
||||
wp_die( __( 'No discount ID supplied', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Setup default discount values
|
||||
$discount_id = absint( $data['discount'] );
|
||||
$deleted = edd_delete_discount( $discount_id );
|
||||
$arg = ! empty( $deleted )
|
||||
? 'discount_deleted'
|
||||
: 'discount_deleted_failed';
|
||||
|
||||
// Redirect
|
||||
edd_redirect( remove_query_arg( 'edd-action', add_query_arg( 'edd-message', sanitize_key( $arg ), $_SERVER['REQUEST_URI'] ) ) );
|
||||
}
|
||||
add_action( 'edd_delete_discount', 'edd_admin_delete_discount' );
|
||||
|
||||
/**
|
||||
* Activates Discount Code
|
||||
*
|
||||
* Sets a discount status to active
|
||||
*
|
||||
* @since 1.0
|
||||
* @param array $data Discount code data
|
||||
* @uses edd_update_discount_status()
|
||||
* @return void
|
||||
*/
|
||||
function edd_activate_discount( $data = array() ) {
|
||||
|
||||
// Bail if no nonce or nonce fails
|
||||
if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'edd_discount_nonce' ) ) {
|
||||
wp_die( __( 'Trying to cheat or something?', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Bail if current user cannot manage shop
|
||||
if( ! current_user_can( 'manage_shop_discounts' ) ) {
|
||||
wp_die( __( 'You do not have permission to edit discount codes', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$discount_id = absint( $data['discount'] );
|
||||
$activated = edd_update_discount_status( $discount_id, 'active' );
|
||||
$arg = ! empty( $activated )
|
||||
? 'discount_activated'
|
||||
: 'discount_activation_failed';
|
||||
|
||||
// Redirect
|
||||
edd_redirect( remove_query_arg( 'edd-action', add_query_arg( 'edd-message', sanitize_key( $arg ), $_SERVER['REQUEST_URI'] ) ) );
|
||||
}
|
||||
add_action( 'edd_activate_discount', 'edd_activate_discount' );
|
||||
|
||||
/**
|
||||
* Deactivate Discount
|
||||
*
|
||||
* Sets a discount status to deactivate
|
||||
*
|
||||
* @since 1.0
|
||||
* @param array $data Discount code data
|
||||
* @uses edd_update_discount_status()
|
||||
* @return void
|
||||
*/
|
||||
function edd_deactivate_discount( $data = array() ) {
|
||||
|
||||
// Bail if no nonce or nonce fails
|
||||
if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'edd_discount_nonce' ) ) {
|
||||
wp_die( __( 'Trying to cheat or something?', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// Bail if current user cannot manage shop
|
||||
if ( ! current_user_can( 'manage_shop_discounts' ) ) {
|
||||
wp_die( __( 'You do not have permission to create discount codes', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$discount_id = absint( $data['discount'] );
|
||||
$activated = edd_update_discount_status( $discount_id, 'inactive' );
|
||||
$arg = ! empty( $activated )
|
||||
? 'discount_deactivated'
|
||||
: 'discount_deactivation_failed';
|
||||
|
||||
// Redirect
|
||||
edd_redirect( remove_query_arg( 'edd-action', add_query_arg( 'edd-message', sanitize_key( $arg ), $_SERVER['REQUEST_URI'] ) ) );
|
||||
}
|
||||
add_action( 'edd_deactivate_discount', 'edd_deactivate_discount' );
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Discount Codes
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Discounts
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Renders the Discounts admin page.
|
||||
*
|
||||
* Here only for backwards compatibility
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 3.0 Nomenclature updated for consistency.
|
||||
*/
|
||||
function edd_discounts_page() {
|
||||
// Enqueue scripts.
|
||||
wp_enqueue_script( 'edd-admin-discounts' );
|
||||
|
||||
// Edit
|
||||
if ( ! empty( $_GET['edd-action'] ) && ( 'edit_discount' === $_GET['edd-action'] ) ) {
|
||||
wp_enqueue_script( 'edd-admin-notes' );
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/discounts/edit-discount.php';
|
||||
|
||||
// Add
|
||||
} elseif ( ! empty( $_GET['edd-action'] ) && ( 'add_discount' === $_GET['edd-action'] ) ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/discounts/add-discount.php';
|
||||
|
||||
// List tables
|
||||
} else {
|
||||
edd_adjustments_page();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the discounts page content, in the adjustments page action.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
function edd_discounts_page_content() {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/discounts/class-discount-codes-table.php';
|
||||
|
||||
$discount_codes_table = new EDD_Discount_Codes_Table();
|
||||
$discount_codes_table->prepare_items();
|
||||
|
||||
do_action( 'edd_discounts_page_top' ); ?>
|
||||
|
||||
<form id="edd-discounts-filter" method="get" action="<?php echo esc_url( edd_get_admin_url( array( 'page' => 'edd-discounts' ) ) ); ?>">
|
||||
<?php $discount_codes_table->search_box( __( 'Search Discounts', 'easy-digital-downloads' ), 'edd-discounts' ); ?>
|
||||
|
||||
<input type="hidden" name="post_type" value="download" />
|
||||
<input type="hidden" name="page" value="edd-discounts" />
|
||||
|
||||
<?php
|
||||
$discount_codes_table->views();
|
||||
$discount_codes_table->display();
|
||||
?>
|
||||
</form>
|
||||
|
||||
<?php do_action( 'edd_discounts_page_bottom' );
|
||||
}
|
||||
add_action( 'edd_adjustments_page_discount', 'edd_discounts_page_content' );
|
@ -0,0 +1,297 @@
|
||||
<?php
|
||||
/**
|
||||
* Edit Discount Page
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Discounts
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Bail if no discount passed
|
||||
if ( ! isset( $_GET['discount'] ) || ! is_numeric( $_GET['discount'] ) ) {
|
||||
wp_die( __( 'Something went wrong.', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
// Load discount
|
||||
$discount_id = absint( $_GET['discount'] );
|
||||
|
||||
/** @var EDD_Discount */
|
||||
$discount = edd_get_discount( $discount_id );
|
||||
|
||||
// Bail if discount does not exist
|
||||
if ( empty( $discount ) ) {
|
||||
wp_die( __( 'Something went wrong.', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
// Setup discount vars
|
||||
$product_requirements = $discount->get_product_reqs();
|
||||
$excluded_products = $discount->get_excluded_products();
|
||||
$condition = $discount->get_product_condition();
|
||||
$single_use = $discount->get_once_per_customer();
|
||||
$type = $discount->get_type();
|
||||
$notes = edd_get_discount_notes( $discount->id );
|
||||
|
||||
// Show/Hide
|
||||
$flat_display = ( 'flat' === $type ) ? '' : ' style="display:none;"';
|
||||
$percent_display = ( 'percent' === $type ) ? '' : ' style="display:none;"';
|
||||
$no_notes_display = empty( $notes ) ? '' : ' style="display:none;"';
|
||||
$condition_display = ! empty( $product_requirements ) ? '' : ' style="display:none;"';
|
||||
|
||||
// Dates & times
|
||||
$discount_start_date = edd_get_edd_timezone_equivalent_date_from_utc( EDD()->utils->date( $discount->start_date, 'utc' ) );
|
||||
$discount_end_date = edd_get_edd_timezone_equivalent_date_from_utc( EDD()->utils->date( $discount->end_date, 'utc' ) );
|
||||
$start_date = $discount_start_date->format( 'Y-m-d' );
|
||||
$start_hour = $discount_start_date->format( 'H' );
|
||||
$start_minute = $discount_start_date->format( 'i' );
|
||||
$end_date = $discount_end_date->format( 'Y-m-d' );
|
||||
$end_hour = $discount_end_date->format( 'H' );
|
||||
$end_minute = $discount_end_date->format( 'i' );
|
||||
$hours = edd_get_hour_values();
|
||||
$minutes = edd_get_minute_values();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php _e( 'Edit Discount', 'easy-digital-downloads' ); ?></h1>
|
||||
|
||||
<hr class="wp-header-end">
|
||||
|
||||
<form id="edd-edit-discount" action="" method="post">
|
||||
<?php do_action( 'edd_edit_discount_form_top', $discount->id, $discount ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_name', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-name"><?php _e( 'Name', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input name="name" required="required" id="edd-name" type="text" value="<?php echo esc_attr( stripslashes( $discount->name ) ); ?>" placeholder="<?php esc_html_e( 'Summer Sale', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php _e( 'The name of this discount. Customers will see this on checkout.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_code', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-code"><?php _e( 'Code', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" required="required" id="edd-code" name="code" value="<?php echo esc_attr( $discount->code ); ?>" pattern="[a-zA-Z0-9-_]+" class="code" placeholder="<?php esc_html_e( '10PERCENT', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php _e( 'The code customers will enter to apply this discount. Only alphanumeric characters are allowed.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_type', $discount->id, $discount ); ?>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_amount', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-amount"><?php _e( 'Amount', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<span class="edd-amount-type-wrapper">
|
||||
<input type="text" required="required" class="edd-price-field" id="edd-amount" name="amount" value="<?php echo esc_attr( edd_format_amount( $discount->amount ) ); ?>" placeholder="<?php esc_html_e( '10.00', 'easy-digital-downloads' ); ?>" />
|
||||
<label for="edd-amount-type" class="screen-reader-text"><?php esc_html_e( 'Amount Type', 'easy-digital-downloads' ); ?></label>
|
||||
<select name="amount_type" id="edd-amount-type">
|
||||
<option value="percent" <?php selected( $type, 'percent' ); ?>>%</option>
|
||||
<option value="flat"<?php selected( $type, 'flat' ); ?>><?php echo esc_html( edd_currency_symbol() ); ?></option>
|
||||
</select>
|
||||
</span>
|
||||
<p class="description"><?php _e( 'The amount as a percentage or flat rate. Cannot be left blank.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_products', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd_products"><?php printf( __( '%s Requirements', 'easy-digital-downloads' ), edd_get_label_singular() ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo EDD()->html->product_dropdown( array(
|
||||
'name' => 'product_reqs[]',
|
||||
'id' => 'edd_products',
|
||||
'selected' => $product_requirements,
|
||||
'multiple' => true,
|
||||
'chosen' => true,
|
||||
'placeholder' => sprintf( __( 'Select %s', 'easy-digital-downloads' ), edd_get_label_plural() )
|
||||
) ); ?>
|
||||
<div id="edd-discount-product-conditions"<?php echo $condition_display; ?>>
|
||||
<p>
|
||||
<select id="edd-product-condition" name="product_condition">
|
||||
<option value="all"<?php selected( 'all', $condition ); ?>><?php printf( __( 'Cart must contain all selected %s', 'easy-digital-downloads' ), edd_get_label_plural() ); ?></option>
|
||||
<option value="any"<?php selected( 'any', $condition ); ?>><?php printf( __( 'Cart needs one or more of the selected %s', 'easy-digital-downloads' ), edd_get_label_plural() ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
<input type="radio" class="tog" name="scope" value="global"<?php checked( 'global', $discount->scope ); ?>/>
|
||||
<?php _e( 'Apply discount to entire purchase.', 'easy-digital-downloads' ); ?>
|
||||
</label><br/>
|
||||
<label>
|
||||
<input type="radio" class="tog" name="scope" value="not_global"<?php checked( 'not_global', $discount->scope ); ?>/>
|
||||
<?php printf( __( 'Apply discount only to selected %s.', 'easy-digital-downloads' ), edd_get_label_plural() ); ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
<p class="description"><?php printf( __( '%s this discount can only be applied to. Leave blank for any.', 'easy-digital-downloads' ), edd_get_label_plural() ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_excluded_products', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-excluded-products"><?php printf( __( 'Excluded %s', 'easy-digital-downloads' ), edd_get_label_plural() ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo EDD()->html->product_dropdown( array(
|
||||
'name' => 'excluded_products[]',
|
||||
'id' => 'excluded_products',
|
||||
'selected' => $excluded_products,
|
||||
'multiple' => true,
|
||||
'chosen' => true,
|
||||
'placeholder' => sprintf( __( 'Select %s', 'easy-digital-downloads' ), edd_get_label_plural() )
|
||||
) ); ?>
|
||||
<p class="description"><?php printf( __( '%s this discount cannot be applied to. Leave blank for none.', 'easy-digital-downloads' ), edd_get_label_plural() ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_start', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-start"><?php _e( 'Start date', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td class="edd-discount-datetime">
|
||||
<input name="start_date" id="edd-start" type="text" value="<?php echo esc_attr( false !== $discount->start_date ? $start_date : '' ); ?>" class="edd_datepicker" data-format="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" placeholder="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" />
|
||||
|
||||
<label class="screen-reader-text" for="start-date-hour">
|
||||
<?php esc_html_e( 'Start Date Hour', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="24" step="1" name="start_date_hour" id="start-date-hour" value="<?php echo esc_attr( false !== $discount->start_date ? $start_hour : '' ); ?>" placeholder="00" />
|
||||
:
|
||||
|
||||
<label class="screen-reader-text" for="start-date-minute">
|
||||
<?php esc_html_e( 'Start Date Minute', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="59" step="1" name="start_date_minute" id="start-date-minute" value="<?php echo esc_attr( false !== $discount->start_date ? $start_minute : '' ); ?>" placeholder="00" />
|
||||
|
||||
<?php echo esc_html( ' (' . edd_get_timezone_abbr() . ')' ); ?>
|
||||
<p class="description"><?php _e( 'Pick the date and time this discount will start on. Leave blank for no start date.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_expiration', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-expiration"><?php _e( 'Expiration date', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td class="edd-discount-datetime">
|
||||
<input name="end_date" id="edd-expiration" type="text" value="<?php echo esc_attr( false !== $discount->end_date ? $end_date : '' ); ?>" class="edd_datepicker" data-format="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" placeholder="<?php echo esc_attr( edd_get_date_picker_format() ); ?>" />
|
||||
|
||||
<label class="screen-reader-text" for="end-date-hour">
|
||||
<?php esc_html_e( 'Expiration Date Hour', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="24" step="1" name="end_date_hour" id="end-date-hour" value="<?php echo esc_attr( false !== $discount->end_date ? $end_hour : '' ); ?>" placeholder="23" />
|
||||
:
|
||||
|
||||
<label class="screen-reader-text" for="end-date-minute">
|
||||
<?php esc_html_e( 'Expiration Date Minute', 'easy-digital-downloads' ); ?>
|
||||
</label>
|
||||
<input type="number" min="0" max="59" step="1" name="end_date_minute" id="end-date-minute" value="<?php echo esc_attr( false !== $discount->end_date ? $end_minute : '' ); ?>" placeholder="59" />
|
||||
|
||||
<?php echo esc_html( ' (' . edd_get_timezone_abbr() . ')' ); ?>
|
||||
<p class="description"><?php _e( 'Pick the date and time this discount will expire on. Leave blank to never expire.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_min_cart_amount', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-min-cart-amount"><?php _e( 'Minimum Amount', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" id="edd-min-cart-amount" name="min_charge_amount" value="<?php echo esc_attr( edd_format_amount( $discount->min_charge_amount ) ); ?>" placeholder="<?php esc_html_e( 'No minimum', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php _e( 'The minimum subtotal of item prices in a cart before this discount may be applied.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_max_uses', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-max-uses"><?php _e( 'Max Uses', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" id="edd-max-uses" name="max_uses" value="<?php echo esc_attr( $discount->max_uses ); ?>" placeholder="<?php esc_html_e( 'Unlimited', 'easy-digital-downloads' ); ?>" />
|
||||
<p class="description"><?php _e( 'The maximum number of times this discount can be used.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_use_once', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-use-once"><?php _e( 'Use Once Per Customer', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" id="edd-use-once" name="once_per_customer" value="1"<?php checked( true, $single_use ); ?>/>
|
||||
<span class="description"><?php _e( 'Prevent customers from using this discount more than once.', 'easy-digital-downloads' ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_status', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="edd-status"><?php _e( 'Status', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="status" id="edd-status">
|
||||
<option value="active" <?php selected( $discount->status, 'active' ); ?>><?php _e( 'Active', 'easy-digital-downloads' ); ?></option>
|
||||
<option value="inactive"<?php selected( $discount->status, 'inactive' ); ?>><?php _e( 'Inactive', 'easy-digital-downloads' ); ?></option>
|
||||
</select>
|
||||
<p class="description"><?php _e( 'The status of this discount code.', 'easy-digital-downloads' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_before_notes', $discount->id, $discount ); ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row" valign="top">
|
||||
<label for="notes"><?php _e( 'Discount Notes', 'easy-digital-downloads' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<div class="edd-notes-wrapper">
|
||||
<?php echo edd_admin_get_notes_html( $notes ); ?>
|
||||
<?php echo edd_admin_get_new_note_form( $discount->id, 'discount' ); ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php do_action( 'edd_edit_discount_form_bottom', $discount->id, $discount ); ?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name="type" value="discount" />
|
||||
<input type="hidden" name="edd-action" value="edit_discount" />
|
||||
<input type="hidden" name="discount-id" value="<?php echo esc_attr( $discount->id ); ?>" />
|
||||
<input type="hidden" name="edd-redirect" value="<?php echo esc_url( edd_get_admin_url( array( 'page' => 'edd-discounts', 'edd-action' => 'edit_discount', 'discount' => absint( $discount->id ) ) ) ); ?>" />
|
||||
<input type="hidden" name="edd-discount-nonce" value="<?php echo esc_attr( wp_create_nonce( 'edd_discount_nonce' ) ); ?>" />
|
||||
<input type="submit" value="<?php esc_html_e( 'Update Discount Code', 'easy-digital-downloads' ); ?>" class="button-primary" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
Reference in New Issue
Block a user