From 030cab584d0476d9c8bfbe8db430fb5101cda891 Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Wed, 15 Jan 2014 01:57:41 -0200 Subject: [PATCH 1/3] fixed validation for "Exclude products" in coupons metabox, fixes #4509 --- .../post-types/meta-boxes/class-wc-meta-box-coupon-data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php index 42fa220c683..089448fa96e 100644 --- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php @@ -123,7 +123,7 @@ class WC_Meta_Box_Coupon_Data { $product = get_product( $product_id ); - echo ''; + echo ''; } } ?> @@ -275,4 +275,4 @@ class WC_Meta_Box_Coupon_Data { /* Deprecated - same hook name as in the meta */ do_action( 'woocommerce_coupon_options' ); do_action( 'woocommerce_coupon_options_save' ); } -} \ No newline at end of file +} From 990e765c24a3f19ad8f3eb2cd830db7d0ffdba26 Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Wed, 15 Jan 2014 01:58:07 -0200 Subject: [PATCH 2/3] fixed the indentation in includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php --- .../meta-boxes/class-wc-meta-box-coupon-data.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php index 089448fa96e..29ec3a909db 100644 --- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php @@ -60,7 +60,7 @@ class WC_Meta_Box_Coupon_Data {
'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 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 ) ); @@ -215,11 +215,11 @@ class WC_Meta_Box_Coupon_Data { // 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 + 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 ) From 9abf6f63ab66f299c5b0bc0390c34d3d9ae6aea8 Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Wed, 15 Jan 2014 02:02:29 -0200 Subject: [PATCH 3/3] fixed some coding standards in includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php --- .../class-wc-meta-box-coupon-data.php | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php index 29ec3a909db..46da632334e 100644 --- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-coupon-data.php @@ -94,7 +94,7 @@ class WC_Meta_Box_Coupon_Data { // Product ids ?> -

+

' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

+ ' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

-

+

' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

+ ' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

'; // Categories ?> -

+

' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

+ ' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

-

+

' src="plugin_url(); ?>/assets/images/help.png" height="16" width="16" />

posts.ID != %s ", $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' ) ); + } // 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'] ); + $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'] ); - $apply_before_tax = isset( $_POST['apply_before_tax'] ) ? 'yes' : 'no'; - $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'] ); - $customer_email = array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ); + $individual_use = isset( $_POST['individual_use'] ) ? 'yes' : 'no'; + $expiry_date = wc_clean( $_POST['expiry_date'] ); + $apply_before_tax = isset( $_POST['apply_before_tax'] ) ? 'yes' : 'no'; + $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'] ); + $customer_email = array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ); 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 { $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 { $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(); // Save