commit
70a5004ff9
|
@ -60,7 +60,7 @@ class WC_Meta_Box_Coupon_Data {
|
||||||
<div id="general_coupon_data" class="panel woocommerce_options_panel"><?php
|
<div id="general_coupon_data" class="panel woocommerce_options_panel"><?php
|
||||||
|
|
||||||
// Type
|
// Type
|
||||||
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => wc_get_coupon_types() ) );
|
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => wc_get_coupon_types() ) );
|
||||||
|
|
||||||
// Amount
|
// Amount
|
||||||
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => wc_format_localized_price( 0 ), 'description' => __( 'Value of the coupon.', 'woocommerce' ), 'data_type' => 'price', 'desc_tip' => true ) );
|
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => wc_format_localized_price( 0 ), 'description' => __( 'Value of the coupon.', 'woocommerce' ), 'data_type' => 'price', 'desc_tip' => true ) );
|
||||||
|
@ -94,7 +94,7 @@ class WC_Meta_Box_Coupon_Data {
|
||||||
|
|
||||||
// Product ids
|
// Product ids
|
||||||
?>
|
?>
|
||||||
<p class="form-field"><label for="product_ids"><?php _e( 'Products', 'woocommerce' ) ?></label>
|
<p class="form-field"><label for="product_ids"><?php _e( 'Products', 'woocommerce' ); ?></label>
|
||||||
<select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>">
|
<select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>">
|
||||||
<?php
|
<?php
|
||||||
$product_ids = get_post_meta( $post->ID, 'product_ids', true );
|
$product_ids = get_post_meta( $post->ID, 'product_ids', true );
|
||||||
|
@ -108,12 +108,12 @@ class WC_Meta_Box_Coupon_Data {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select> <img class="help_tip" data-tip='<?php _e( 'Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce' ) ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
</select> <img class="help_tip" data-tip='<?php _e( 'Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce' ); ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Exclude Product ids
|
// Exclude Product ids
|
||||||
?>
|
?>
|
||||||
<p class="form-field"><label for="exclude_product_ids"><?php _e( 'Exclude products', 'woocommerce' ) ?></label>
|
<p class="form-field"><label for="exclude_product_ids"><?php _e( 'Exclude products', 'woocommerce' ); ?></label>
|
||||||
<select id="exclude_product_ids" name="exclude_product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>">
|
<select id="exclude_product_ids" name="exclude_product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>">
|
||||||
<?php
|
<?php
|
||||||
$product_ids = get_post_meta( $post->ID, 'exclude_product_ids', true );
|
$product_ids = get_post_meta( $post->ID, 'exclude_product_ids', true );
|
||||||
|
@ -123,39 +123,41 @@ class WC_Meta_Box_Coupon_Data {
|
||||||
|
|
||||||
$product = get_product( $product_id );
|
$product = get_product( $product_id );
|
||||||
|
|
||||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product->get_formatted_name() ) . '</option>';
|
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select> <img class="help_tip" data-tip='<?php _e( 'Products which must not be in the cart to use this coupon or, for "Product Discounts", which products are not discounted.', 'woocommerce' ) ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
</select> <img class="help_tip" data-tip='<?php _e( 'Products which must not be in the cart to use this coupon or, for "Product Discounts", which products are not discounted.', 'woocommerce' ); ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo '</div><div class="options_group">';
|
echo '</div><div class="options_group">';
|
||||||
|
|
||||||
// Categories
|
// Categories
|
||||||
?>
|
?>
|
||||||
<p class="form-field"><label for="product_ids"><?php _e( 'Product categories', 'woocommerce' ) ?></label>
|
<p class="form-field"><label for="product_ids"><?php _e( 'Product categories', 'woocommerce' ); ?></label>
|
||||||
<select id="product_categories" name="product_categories[]" class="chosen_select" multiple="multiple" data-placeholder="<?php _e( 'Any category', 'woocommerce' ); ?>">
|
<select id="product_categories" name="product_categories[]" class="chosen_select" multiple="multiple" data-placeholder="<?php _e( 'Any category', 'woocommerce' ); ?>">
|
||||||
<?php
|
<?php
|
||||||
$category_ids = (array) get_post_meta( $post->ID, 'product_categories', true );
|
$category_ids = (array) get_post_meta( $post->ID, 'product_categories', true );
|
||||||
|
|
||||||
$categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' );
|
$categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' );
|
||||||
if ( $categories ) foreach ( $categories as $cat )
|
if ( $categories ) foreach ( $categories as $cat ) {
|
||||||
echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
|
echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select> <img class="help_tip" data-tip='<?php _e( 'A product must be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will be discounted.', 'woocommerce' ) ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
</select> <img class="help_tip" data-tip='<?php _e( 'A product must be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will be discounted.', 'woocommerce' ); ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Exclude Categories
|
// Exclude Categories
|
||||||
?>
|
?>
|
||||||
<p class="form-field"><label for="exclude_product_categories"><?php _e( 'Exclude categories', 'woocommerce' ) ?></label>
|
<p class="form-field"><label for="exclude_product_categories"><?php _e( 'Exclude categories', 'woocommerce' ); ?></label>
|
||||||
<select id="exclude_product_categories" name="exclude_product_categories[]" class="chosen_select" multiple="multiple" data-placeholder="<?php _e( 'No categories', 'woocommerce' ); ?>">
|
<select id="exclude_product_categories" name="exclude_product_categories[]" class="chosen_select" multiple="multiple" data-placeholder="<?php _e( 'No categories', 'woocommerce' ); ?>">
|
||||||
<?php
|
<?php
|
||||||
$category_ids = (array) get_post_meta( $post->ID, 'exclude_product_categories', true );
|
$category_ids = (array) get_post_meta( $post->ID, 'exclude_product_categories', true );
|
||||||
|
|
||||||
$categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' );
|
$categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' );
|
||||||
if ( $categories ) foreach ( $categories as $cat )
|
if ( $categories ) foreach ( $categories as $cat ) {
|
||||||
echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
|
echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select> <img class="help_tip" data-tip='<?php _e( 'Product must not be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will not be discounted.', 'woocommerce' ) ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
</select> <img class="help_tip" data-tip='<?php _e( 'Product must not be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will not be discounted.', 'woocommerce' ) ?>' src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
|
||||||
<?php
|
<?php
|
||||||
|
@ -215,43 +217,44 @@ class WC_Meta_Box_Coupon_Data {
|
||||||
// Check for dupe coupons
|
// Check for dupe coupons
|
||||||
$coupon_found = $wpdb->get_var( $wpdb->prepare( "
|
$coupon_found = $wpdb->get_var( $wpdb->prepare( "
|
||||||
SELECT $wpdb->posts.ID
|
SELECT $wpdb->posts.ID
|
||||||
FROM $wpdb->posts
|
FROM $wpdb->posts
|
||||||
WHERE $wpdb->posts.post_type = 'shop_coupon'
|
WHERE $wpdb->posts.post_type = 'shop_coupon'
|
||||||
AND $wpdb->posts.post_status = 'publish'
|
AND $wpdb->posts.post_status = 'publish'
|
||||||
AND $wpdb->posts.post_title = '%s'
|
AND $wpdb->posts.post_title = '%s'
|
||||||
AND $wpdb->posts.ID != %s
|
AND $wpdb->posts.ID != %s
|
||||||
", $post->post_title, $post_id ) );
|
", $post->post_title, $post_id ) );
|
||||||
|
|
||||||
if ( $coupon_found )
|
if ( $coupon_found ) {
|
||||||
WC_Admin_Meta_Boxes::add_error( __( 'Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce' ) );
|
WC_Admin_Meta_Boxes::add_error( __( 'Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce' ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Add/Replace data to array
|
// Add/Replace data to array
|
||||||
$type = wc_clean( $_POST['discount_type'] );
|
$type = wc_clean( $_POST['discount_type'] );
|
||||||
$amount = wc_format_decimal( $_POST['coupon_amount'] );
|
$amount = wc_format_decimal( $_POST['coupon_amount'] );
|
||||||
$usage_limit = empty( $_POST['usage_limit'] ) ? '' : absint( $_POST['usage_limit'] );
|
$usage_limit = empty( $_POST['usage_limit'] ) ? '' : absint( $_POST['usage_limit'] );
|
||||||
$usage_limit_per_user = empty( $_POST['usage_limit_per_user'] ) ? '' : absint( $_POST['usage_limit_per_user'] );
|
$usage_limit_per_user = empty( $_POST['usage_limit_per_user'] ) ? '' : absint( $_POST['usage_limit_per_user'] );
|
||||||
$limit_usage_to_x_items = empty( $_POST['limit_usage_to_x_items'] ) ? '' : absint( $_POST['limit_usage_to_x_items'] );
|
$limit_usage_to_x_items = empty( $_POST['limit_usage_to_x_items'] ) ? '' : absint( $_POST['limit_usage_to_x_items'] );
|
||||||
$individual_use = isset( $_POST['individual_use'] ) ? 'yes' : 'no';
|
$individual_use = isset( $_POST['individual_use'] ) ? 'yes' : 'no';
|
||||||
$expiry_date = wc_clean( $_POST['expiry_date'] );
|
$expiry_date = wc_clean( $_POST['expiry_date'] );
|
||||||
$apply_before_tax = isset( $_POST['apply_before_tax'] ) ? 'yes' : 'no';
|
$apply_before_tax = isset( $_POST['apply_before_tax'] ) ? 'yes' : 'no';
|
||||||
$free_shipping = isset( $_POST['free_shipping'] ) ? 'yes' : 'no';
|
$free_shipping = isset( $_POST['free_shipping'] ) ? 'yes' : 'no';
|
||||||
$exclude_sale_items = isset( $_POST['exclude_sale_items'] ) ? 'yes' : 'no';
|
$exclude_sale_items = isset( $_POST['exclude_sale_items'] ) ? 'yes' : 'no';
|
||||||
$minimum_amount = wc_format_decimal( $_POST['minimum_amount'] );
|
$minimum_amount = wc_format_decimal( $_POST['minimum_amount'] );
|
||||||
$customer_email = array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) );
|
$customer_email = array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) );
|
||||||
|
|
||||||
if ( isset( $_POST['product_ids'] ) ) {
|
if ( isset( $_POST['product_ids'] ) ) {
|
||||||
$product_ids = implode( ',', array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) );
|
$product_ids = implode( ',', array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) );
|
||||||
} else {
|
} else {
|
||||||
$product_ids = '';
|
$product_ids = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $_POST['exclude_product_ids'] ) ) {
|
if ( isset( $_POST['exclude_product_ids'] ) ) {
|
||||||
$exclude_product_ids = implode( ',', array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) );
|
$exclude_product_ids = implode( ',', array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) );
|
||||||
} else {
|
} else {
|
||||||
$exclude_product_ids = '';
|
$exclude_product_ids = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$product_categories = isset( $_POST['product_categories'] ) ? array_map( 'intval', $_POST['product_categories'] ) : array();
|
$product_categories = isset( $_POST['product_categories'] ) ? array_map( 'intval', $_POST['product_categories'] ) : array();
|
||||||
$exclude_product_categories = isset( $_POST['exclude_product_categories'] ) ? array_map( 'intval', $_POST['exclude_product_categories'] ) : array();
|
$exclude_product_categories = isset( $_POST['exclude_product_categories'] ) ? array_map( 'intval', $_POST['exclude_product_categories'] ) : array();
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
Loading…
Reference in New Issue