'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => wc_get_coupon_types() ) ); // 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 ) ); // Free Shipping woocommerce_wp_checkbox( array( 'id' => 'free_shipping', 'label' => __( 'Allow free shipping', 'woocommerce' ), 'description' => sprintf( __( 'Check this box if the coupon grants free shipping. The free shipping method must be enabled and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce' ), admin_url('admin.php?page=wc-settings&tab=shipping§ion=WC_Shipping_Free_Shipping')) ) ); // Expiry date woocommerce_wp_text_input( array( 'id' => 'expiry_date', 'label' => __( 'Coupon expiry date', 'woocommerce' ), 'placeholder' => _x( 'YYYY-MM-DD', 'placeholder', 'woocommerce' ), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array( 'pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ) ) ); do_action( 'woocommerce_coupon_options' ); ?>
'; // minimum spend woocommerce_wp_text_input( array( 'id' => 'minimum_amount', 'label' => __( 'Minimum spend', 'woocommerce' ), 'placeholder' => __( 'No minimum', 'woocommerce' ), 'description' => __( 'This field allows you to set the minimum subtotal needed to use the coupon.', 'woocommerce' ), 'data_type' => 'price', 'desc_tip' => true ) ); // maximum spend woocommerce_wp_text_input( array( 'id' => 'maximum_amount', 'label' => __( 'Maximum spend', 'woocommerce' ), 'placeholder' => __( 'No maximum', 'woocommerce' ), 'description' => __( 'This field allows you to set the maximum subtotal allowed when using the coupon.', 'woocommerce' ), 'data_type' => 'price', 'desc_tip' => true ) ); // Individual use woocommerce_wp_checkbox( array( 'id' => 'individual_use', 'label' => __( 'Individual use only', 'woocommerce' ), 'description' => __( 'Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce' ) ) ); // Exclude Sale Products woocommerce_wp_checkbox( array( 'id' => 'exclude_sale_items', 'label' => __( 'Exclude sale items', 'woocommerce' ), 'description' => __( 'Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are no sale items in the cart.', 'woocommerce' ) ) ); echo '
'; // Product ids ?>

'; // Categories ?>

'; // Customers woocommerce_wp_text_input( array( 'id' => 'customer_email', 'label' => __( 'Email restrictions', 'woocommerce' ), 'placeholder' => __( 'No restrictions', 'woocommerce' ), 'description' => __( 'List of allowed emails to check against the customer\'s billing email when an order is placed. Separate email addresses with commas.', 'woocommerce' ), 'value' => implode(', ', (array) get_post_meta( $post->ID, 'customer_email', true ) ), 'desc_tip' => true, 'type' => 'email', 'class' => '', 'custom_attributes' => array( 'multiple' => 'multiple' ) ) ); echo '
'; do_action( 'woocommerce_coupon_options_usage_restriction' ); ?>
'; // Usage limit per coupons woocommerce_wp_text_input( array( 'id' => 'usage_limit', 'label' => __( 'Usage limit per coupon', 'woocommerce' ), 'placeholder' => _x('Unlimited usage', 'placeholder', 'woocommerce'), 'description' => __( 'How many times this coupon can be used before it is void.', 'woocommerce' ), 'type' => 'number', 'desc_tip' => true, 'class' => 'short', 'custom_attributes' => array( 'step' => '1', 'min' => '0' ) ) ); // Usage limit per product woocommerce_wp_text_input( array( 'id' => 'limit_usage_to_x_items', 'label' => __( 'Limit usage to X items', 'woocommerce' ), 'placeholder' => _x( 'Apply to all qualifying items in cart', 'placeholder', 'woocommerce' ), 'description' => __( 'The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce' ), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array( 'step' => '1', 'min' => '0' ) ) ); // Usage limit per users woocommerce_wp_text_input( array( 'id' => 'usage_limit_per_user', 'label' => __( 'Usage limit per user', 'woocommerce' ), 'placeholder' => _x( 'Unlimited usage', 'placeholder', 'woocommerce' ), 'description' => __( 'How many times this coupon can be used by an invidual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array( 'step' => '1', 'min' => '0' ) ) ); echo '
'; do_action( 'woocommerce_coupon_options_usage_limit' ); ?>
post_title = apply_filters( 'woocommerce_coupon_code', $post->post_title ); $wpdb->update( $wpdb->posts, array( 'post_title' => $post->post_title ), array( 'ID' => $post_id ) ); // Check for dupe coupons $coupon_found = $wpdb->get_var( $wpdb->prepare( " SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_type = 'shop_coupon' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_title = '%s' AND $wpdb->posts.ID != %s ", $post->post_title, $post_id ) ); if ( $coupon_found ) { 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 $type = wc_clean( $_POST['discount_type'] ); $amount = wc_format_decimal( $_POST['coupon_amount'] ); $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'] ); $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'; $expiry_date = wc_clean( $_POST['expiry_date'] ); $free_shipping = isset( $_POST['free_shipping'] ) ? 'yes' : 'no'; $exclude_sale_items = isset( $_POST['exclude_sale_items'] ) ? 'yes' : 'no'; $minimum_amount = wc_format_decimal( $_POST['minimum_amount'] ); $maximum_amount = wc_format_decimal( $_POST['maximum_amount'] ); $customer_email = array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ); $product_ids = implode( ',', array_filter( array_map( 'intval', explode( ',', $_POST['product_ids'] ) ) ) ); $exclude_product_ids = implode( ',', array_filter( array_map( 'intval', explode( ',', $_POST['exclude_product_ids'] ) ) ) ); $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(); // Save update_post_meta( $post_id, 'discount_type', $type ); update_post_meta( $post_id, 'coupon_amount', $amount ); update_post_meta( $post_id, 'individual_use', $individual_use ); update_post_meta( $post_id, 'product_ids', $product_ids ); update_post_meta( $post_id, 'exclude_product_ids', $exclude_product_ids ); update_post_meta( $post_id, 'usage_limit', $usage_limit ); update_post_meta( $post_id, 'usage_limit_per_user', $usage_limit_per_user ); update_post_meta( $post_id, 'limit_usage_to_x_items', $limit_usage_to_x_items ); update_post_meta( $post_id, 'expiry_date', $expiry_date ); update_post_meta( $post_id, 'free_shipping', $free_shipping ); update_post_meta( $post_id, 'exclude_sale_items', $exclude_sale_items ); update_post_meta( $post_id, 'product_categories', $product_categories ); update_post_meta( $post_id, 'exclude_product_categories', $exclude_product_categories ); update_post_meta( $post_id, 'minimum_amount', $minimum_amount ); update_post_meta( $post_id, 'maximum_amount', $maximum_amount ); update_post_meta( $post_id, 'customer_email', $customer_email ); do_action( 'woocommerce_coupon_options_save', $post_id ); } }