diff --git a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php index 194d5c6a3d0..2721f516b65 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php @@ -4,9 +4,9 @@ * * Display the coupon data meta box. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ @@ -101,8 +101,10 @@ class WC_Meta_Box_Coupon_Data { ID, 'exclude_product_ids', true ); + if ( $product_ids ) { + $product_ids = array_map( 'absint', explode( ',', $product_ids ) ); + foreach ( $product_ids as $product_id ) { $product = wc_get_product( $product_id ); @@ -143,6 +148,7 @@ class WC_Meta_Box_Coupon_Data { $category_ids = (array) get_post_meta( $post->ID, 'product_categories', true ); $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); + if ( $categories ) foreach ( $categories as $cat ) { echo ''; } @@ -158,6 +164,7 @@ class WC_Meta_Box_Coupon_Data { $category_ids = (array) get_post_meta( $post->ID, 'exclude_product_categories', true ); $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); + if ( $categories ) foreach ( $categories as $cat ) { echo ''; } @@ -170,7 +177,7 @@ class WC_Meta_Box_Coupon_Data { // Customers woocommerce_wp_text_input( array( 'id' => 'customer_email', 'label' => __( 'Email restrictions', 'woocommerce' ), 'placeholder' => __( 'No restrictions', 'woocommerce' ), 'description' => __( 'List of 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 ''; @@ -185,19 +192,19 @@ class WC_Meta_Box_Coupon_Data { 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 ''; diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php b/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php index fe1b12cb2bb..c4d681d72a9 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php @@ -4,9 +4,9 @@ * * Functions for displaying the order actions meta box. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ @@ -61,7 +61,9 @@ class WC_Meta_Box_Order_Actions {
  • ID ) ) { + if ( ! EMPTY_TRASH_DAYS ) { $delete_text = __( 'Delete Permanently', 'woocommerce' ); } else { @@ -84,6 +86,7 @@ class WC_Meta_Box_Order_Actions { * Save meta box data */ public static function save( $post_id, $post ) { + // Order data saved, now get it so we can manipulate status $order = wc_get_order( $post_id ); diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php index d0246ac357d..6ba8aa5774e 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php @@ -37,6 +37,7 @@ class WC_Meta_Box_Order_Data { * Init billing and shipping fields we display + save */ public static function init_address_fields() { + self::$billing_fields = apply_filters( 'woocommerce_admin_billing_fields', array( 'first_name' => array( 'label' => __( 'First Name', 'woocommerce' ), diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php b/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php index 69ddd06e1e2..548452f6f24 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php @@ -2,9 +2,9 @@ /** * Order Downloads * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ @@ -32,10 +32,11 @@ class WC_Meta_Box_Order_Downloads { $product = null; $loop = 0; + if ( $download_permissions && sizeof( $download_permissions ) > 0 ) foreach ( $download_permissions as $download ) { if ( ! $product || $product->id != $download->product_id ) { - $product = wc_get_product( absint( $download->product_id ) ); + $product = wc_get_product( absint( $download->product_id ) ); $file_counter = 1; } @@ -80,47 +81,48 @@ class WC_Meta_Box_Order_Downloads { if ( isset( $_POST['download_id'] ) ) { // Download data - $download_ids = $_POST['download_id']; - $product_ids = $_POST['product_id']; - $downloads_remaining = $_POST['downloads_remaining']; - $access_expires = $_POST['access_expires']; + $download_ids = $_POST['download_id']; + $product_ids = $_POST['product_id']; + $downloads_remaining = $_POST['downloads_remaining']; + $access_expires = $_POST['access_expires']; // Order data - $order_key = get_post_meta( $post->ID, '_order_key', true ); - $customer_email = get_post_meta( $post->ID, '_billing_email', true ); - $customer_user = get_post_meta( $post->ID, '_customer_user', true ); - $product_ids_count = sizeof( $product_ids ); + $order_key = get_post_meta( $post->ID, '_order_key', true ); + $customer_email = get_post_meta( $post->ID, '_billing_email', true ); + $customer_user = get_post_meta( $post->ID, '_customer_user', true ); + $product_ids_count = sizeof( $product_ids ); for ( $i = 0; $i < $product_ids_count; $i ++ ) { - if ( ! isset( $product_ids[ $i ] ) ) - continue; - $data = array( + if ( ! isset( $product_ids[ $i ] ) ) { + continue; + } + + $data = array( 'user_id' => absint( $customer_user ), 'user_email' => wc_clean( $customer_email ), 'downloads_remaining' => wc_clean( $downloads_remaining[ $i ] ) - ); + ); - $format = array( '%d', '%s', '%s' ); + $format = array( '%d', '%s', '%s' ); - $expiry = ( array_key_exists( $i, $access_expires ) && $access_expires[ $i ] != '' ) ? date_i18n( 'Y-m-d', strtotime( $access_expires[ $i ] ) ) : null; + $expiry = ( array_key_exists( $i, $access_expires ) && $access_expires[ $i ] != '' ) ? date_i18n( 'Y-m-d', strtotime( $access_expires[ $i ] ) ) : null; - if ( ! is_null( $expiry ) ) { + if ( ! is_null( $expiry ) ) { $data['access_expires'] = $expiry; $format[] = '%s'; - } + } - $wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", - $data, - array( + $wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", + $data, + array( 'order_id' => $post_id, 'product_id' => absint( $product_ids[ $i ] ), 'download_id' => wc_clean( $download_ids[ $i ] ) ), $format, array( '%d', '%d', '%s' ) ); - } } } -} \ No newline at end of file +} diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-items.php b/includes/admin/meta-boxes/class-wc-meta-box-order-items.php index 6a91da61101..0a24cfe0b9a 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-items.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-items.php @@ -4,9 +4,9 @@ * * Functions for displaying the order items meta box. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-notes.php b/includes/admin/meta-boxes/class-wc-meta-box-order-notes.php index 49a6c2af60b..c73e4a4f8a4 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-notes.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-notes.php @@ -2,9 +2,9 @@ /** * Order Notes * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ @@ -22,9 +22,9 @@ class WC_Meta_Box_Order_Notes { global $post; $args = array( - 'post_id' => $post->ID, - 'approve' => 'approve', - 'type' => 'order_note' + 'post_id' => $post->ID, + 'approve' => 'approve', + 'type' => 'order_note' ); remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); @@ -36,7 +36,9 @@ class WC_Meta_Box_Order_Notes { echo '
    '; $product_type_options = apply_filters( 'product_type_options', array( @@ -260,7 +262,9 @@ class WC_Meta_Box_Product_Data { $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); $classes_options = array(); $classes_options[''] = __( 'Standard', 'woocommerce' ); + if ( $tax_classes ) { + foreach ( $tax_classes as $class ) { $classes_options[ sanitize_title( $class ) ] = esc_html( $class ); } @@ -524,7 +528,9 @@ class WC_Meta_Box_Product_Data { // Custom Attributes if ( ! empty( $attributes ) ) { + foreach ( $attributes as $attribute ) { + if ( $attribute['is_taxonomy'] ) { continue; } @@ -580,6 +586,7 @@ class WC_Meta_Box_Product_Data { attribute_name ); $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; @@ -602,7 +609,9 @@ class WC_Meta_Box_Product_Data { ID, '_upsell_ids', true ); $product_ids = ! empty( $upsell_ids ) ? array_map( 'absint', $upsell_ids ) : null; + if ( $product_ids ) { + foreach ( $product_ids as $product_id ) { $product = wc_get_product( $product_id ); @@ -620,7 +629,9 @@ class WC_Meta_Box_Product_Data { ID, '_crosssell_ids', true ); $product_ids = ! empty( $crosssell_ids ) ? array_map( 'absint', $crosssell_ids ) : null; + if ( $product_ids ) { + foreach ( $product_ids as $product_id ) { $product = wc_get_product( $product_id ); @@ -646,7 +657,9 @@ class WC_Meta_Box_Product_Data { if ( $grouped_term = get_term_by( 'slug', 'grouped', 'product_type' ) ) { $posts_in = array_unique( (array) get_objects_in_term( $grouped_term->term_id, 'product_type' ) ); + if ( sizeof( $posts_in ) > 0 ) { + $args = array( 'post_type' => 'product', 'post_status' => 'any', @@ -657,9 +670,11 @@ class WC_Meta_Box_Product_Data { 'suppress_filters' => 0, 'include' => $posts_in, ); + $grouped_products = get_posts( $args ); if ( $grouped_products ) { + foreach ( $grouped_products as $product ) { if ( $product->ID == $post->ID ) { @@ -740,8 +755,11 @@ class WC_Meta_Box_Product_Data { // See if any are set $variation_attribute_found = false; + if ( $attributes ) { + foreach ( $attributes as $attribute ) { + if ( isset( $attribute['is_variation'] ) ) { $variation_attribute_found = true; break; @@ -753,7 +771,9 @@ class WC_Meta_Box_Product_Data { $tax_classes = array_filter( array_map('trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); $tax_class_options = array(); $tax_class_options[''] = __( 'Standard', 'woocommerce' ); + if ( $tax_classes ) { + foreach ( $tax_classes as $class ) { $tax_class_options[ sanitize_title( $class ) ] = esc_attr( $class ); } @@ -862,19 +882,22 @@ class WC_Meta_Box_Product_Data { 'order' => 'asc', 'post_parent' => $post->ID ); + $variations = get_posts( $args ); $loop = 0; + if ( $variations ) { + foreach ( $variations as $variation ) { - $variation_id = absint( $variation->ID ); - $variation_post_status = esc_attr( $variation->post_status ); - $variation_data = get_post_meta( $variation_id ); + $variation_id = absint( $variation->ID ); + $variation_post_status = esc_attr( $variation->post_status ); + $variation_data = get_post_meta( $variation_id ); $variation_data['variation_post_id'] = $variation_id; // Grab shipping classes $shipping_classes = get_the_terms( $variation_id, 'product_shipping_class' ); - $shipping_class = ( $shipping_classes && ! is_wp_error( $shipping_classes ) ) ? current( $shipping_classes )->term_id : ''; + $shipping_class = ( $shipping_classes && ! is_wp_error( $shipping_classes ) ) ? current( $shipping_classes )->term_id : ''; $variation_fields = array( '_sku', @@ -936,6 +959,7 @@ class WC_Meta_Box_Product_Data { : [?] ID, '_default_attributes', true ) ); + foreach ( $attributes as $attribute ) { // Only deal with attributes that are variations @@ -1001,15 +1025,19 @@ class WC_Meta_Box_Product_Data { if ( isset( $_POST['_regular_price'] ) ) { update_post_meta( $post_id, '_regular_price', ( $_POST['_regular_price'] === '' ) ? '' : wc_format_decimal( $_POST['_regular_price'] ) ); } + if ( isset( $_POST['_sale_price'] ) ) { update_post_meta( $post_id, '_sale_price', ( $_POST['_sale_price'] === '' ? '' : wc_format_decimal( $_POST['_sale_price'] ) ) ); } + if ( isset( $_POST['_tax_status'] ) ) { update_post_meta( $post_id, '_tax_status', stripslashes( $_POST['_tax_status'] ) ); } + if ( isset( $_POST['_tax_class'] ) ) { update_post_meta( $post_id, '_tax_class', stripslashes( $_POST['_tax_class'] ) ); } + if ( isset( $_POST['_purchase_note'] ) ) { update_post_meta( $post_id, '_purchase_note', stripslashes( $_POST['_purchase_note'] ) ); } @@ -1056,8 +1084,11 @@ class WC_Meta_Box_Product_Data { if ( '' == $new_sku ) { update_post_meta( $post_id, '_sku', '' ); } elseif ( $new_sku !== $sku ) { + if ( ! empty( $new_sku ) ) { + $unique_sku = wc_product_has_unique_sku( $post_id, $new_sku ); + if ( ! $unique_sku ) { WC_Admin_Meta_Boxes::add_error( __( 'Product SKU must be unique.', 'woocommerce' ) ); } else { @@ -1072,6 +1103,7 @@ class WC_Meta_Box_Product_Data { $attributes = array(); if ( isset( $_POST['attribute_names'] ) && isset( $_POST['attribute_values'] ) ) { + $attribute_names = $_POST['attribute_names']; $attribute_values = $_POST['attribute_values']; @@ -1088,6 +1120,7 @@ class WC_Meta_Box_Product_Data { $attribute_names_count = sizeof( $attribute_names ); for ( $i = 0; $i < $attribute_names_count; $i++ ) { + if ( ! $attribute_names[ $i ] ) { continue; } @@ -1246,6 +1279,7 @@ class WC_Meta_Box_Product_Data { ) ); if ( $children_by_price ) { + foreach ( $children_by_price as $child ) { $child_price = get_post_meta( $child, '_price', true ); update_post_meta( $clear_id, '_price', $child_price ); @@ -1312,6 +1346,7 @@ class WC_Meta_Box_Product_Data { $ids = $_POST['upsell_ids']; foreach ( $ids as $id ) { + if ( $id && $id > 0 ) { $upsells[] = $id; } @@ -1324,6 +1359,7 @@ class WC_Meta_Box_Product_Data { // Cross sells if ( isset( $_POST['crosssell_ids'] ) ) { + $crosssells = array(); $ids = $_POST['crosssell_ids']; @@ -1334,6 +1370,7 @@ class WC_Meta_Box_Product_Data { } update_post_meta( $post_id, '_crosssell_ids', $crosssells ); + } else { delete_post_meta( $post_id, '_crosssell_ids' ); } @@ -1383,9 +1420,11 @@ class WC_Meta_Box_Product_Data { // Product url if ( 'external' == $product_type ) { + if ( isset( $_POST['_product_url'] ) ) { update_post_meta( $post_id, '_product_url', esc_attr( $_POST['_product_url'] ) ); } + if ( isset( $_POST['_button_text'] ) ) { update_post_meta( $post_id, '_button_text', esc_attr( $_POST['_button_text'] ) ); } @@ -1496,8 +1535,10 @@ class WC_Meta_Box_Product_Data { if ( '' == $new_sku ) { update_post_meta( $variation_id, '_sku', '' ); } elseif ( $new_sku !== $sku ) { + if ( ! empty( $new_sku ) ) { $unique_sku = wc_product_has_unique_sku( $variation_id, $new_sku ); + if ( ! $unique_sku ) { WC_Admin_Meta_Boxes::add_error( __( 'Variation SKU must be unique.', 'woocommerce' ) ); } else { @@ -1516,12 +1557,15 @@ class WC_Meta_Box_Product_Data { if ( isset( $variable_weight[ $i ] ) ) { update_post_meta( $variation_id, '_weight', ( '' === $variable_weight[ $i ] ) ? '' : wc_format_decimal( $variable_weight[ $i ] ) ); } + if ( isset( $variable_length[ $i ] ) ) { update_post_meta( $variation_id, '_length', ( '' === $variable_length[ $i ] ) ? '' : wc_format_decimal( $variable_length[ $i ] ) ); } + if ( isset( $variable_width[ $i ] ) ) { update_post_meta( $variation_id, '_width', ( '' === $variable_width[ $i ] ) ? '' : wc_format_decimal( $variable_width[ $i ] ) ); } + if ( isset( $variable_height[ $i ] ) ) { update_post_meta( $variation_id, '_height', ( '' === $variable_height[ $i ] ) ? '' : wc_format_decimal( $variable_height[ $i ] ) ); } @@ -1592,7 +1636,9 @@ class WC_Meta_Box_Product_Data { $file_url_size = sizeof( $file_urls ); for ( $ii = 0; $ii < $file_url_size; $ii ++ ) { + if ( ! empty( $file_urls[ $ii ] ) ) { + $files[ md5( $file_urls[ $ii ] ) ] = array( 'name' => $file_names[ $ii ], 'file' => $file_urls[ $ii ] @@ -1617,6 +1663,7 @@ class WC_Meta_Box_Product_Data { // Update taxonomies - don't use wc_clean as it destroys sanitized characters $updated_attribute_keys = array(); foreach ( $attributes as $attribute ) { + if ( $attribute['is_variation'] ) { $attribute_key = 'attribute_' . sanitize_title( $attribute['name'] ); $value = isset( $_POST[ $attribute_key ][ $i ] ) ? sanitize_title( stripslashes( $_POST[ $attribute_key ][ $i ] ) ) : ''; @@ -1643,6 +1690,7 @@ class WC_Meta_Box_Product_Data { $default_attributes = array(); foreach ( $attributes as $attribute ) { + if ( $attribute['is_variation'] ) { // Don't use wc_clean as it destroys sanitized characters diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-images.php b/includes/admin/meta-boxes/class-wc-meta-box-product-images.php index e07c8044d39..ad1102a3dc9 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-images.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-images.php @@ -4,9 +4,9 @@ * * Display the product images meta box. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ @@ -36,7 +36,7 @@ class WC_Meta_Box_Product_Images { $attachments = array_filter( explode( ',', $product_image_gallery ) ); - if ( $attachments ) + if ( $attachments ) { foreach ( $attachments as $attachment_id ) { echo '
  • ' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . ' @@ -45,6 +45,7 @@ class WC_Meta_Box_Product_Images {
  • '; } + } ?> @@ -65,4 +66,4 @@ class WC_Meta_Box_Product_Images { update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) ); } -} \ No newline at end of file +} diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-short-description.php b/includes/admin/meta-boxes/class-wc-meta-box-product-short-description.php index cbcba911778..46f758e8a82 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-short-description.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-short-description.php @@ -4,9 +4,9 @@ * * Replaces the standard excerpt box. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.1.0 */ @@ -21,14 +21,15 @@ class WC_Meta_Box_Product_Short_Description { * Output the metabox */ public static function output( $post ) { + $settings = array( - 'textarea_name' => 'excerpt', - 'quicktags' => array( 'buttons' => 'em,strong,link' ), - 'tinymce' => array( + 'textarea_name' => 'excerpt', + 'quicktags' => array( 'buttons' => 'em,strong,link' ), + 'tinymce' => array( 'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator', 'theme_advanced_buttons2' => '', ), - 'editor_css' => '' + 'editor_css' => '' ); wp_editor( htmlspecialchars_decode( $post->post_excerpt ), 'excerpt', apply_filters( 'woocommerce_product_short_description_editor_settings', $settings ) );