From 73175288c5181fa38ea8bae13699fd09cd2a6bfc Mon Sep 17 00:00:00 2001 From: kathy Date: Wed, 31 Oct 2012 12:02:32 -0500 Subject: [PATCH] add write panel check box to allow any product to be sold individually --- .../writepanels/writepanel-product_data.php | 16 ++++++++++++++++ classes/class-wc-product.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/admin/post-types/writepanels/writepanel-product_data.php b/admin/post-types/writepanels/writepanel-product_data.php index 6eda70c6eec..43c1d45104b 100644 --- a/admin/post-types/writepanels/writepanel-product_data.php +++ b/admin/post-types/writepanels/writepanel-product_data.php @@ -103,6 +103,15 @@ function woocommerce_product_data_box() { echo ''; + echo '
'; + + // Individual product + woocommerce_wp_checkbox( array( 'id' => '_sold_individually', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Product Sold Individually?', 'woocommerce'), 'description' => __('For items of singular quantity.', 'woocommerce') ) ); + + do_action('woocommerce_product_options_sold_individually'); + + echo '
'; + echo '
'; // External URL @@ -824,6 +833,13 @@ function woocommerce_process_product_meta( $post_id, $post ) { $woocommerce->clear_product_transients( $post_parent ); } + // Sold Individuall + if ( ! empty( $_POST['_sold_individually'] ) ) { + update_post_meta( $post_id, '_sold_individually', 'yes' ); + } else { + update_post_meta( $post_id, '_sold_individually', '' ); + } + // Stock Data if ( get_option('woocommerce_manage_stock') == 'yes' ) { diff --git a/classes/class-wc-product.php b/classes/class-wc-product.php index 05a6fc35190..a50caa673ee 100644 --- a/classes/class-wc-product.php +++ b/classes/class-wc-product.php @@ -435,8 +435,8 @@ class WC_Product { function is_sold_individually() { $return = false; - // Sold individually if downloadable, virtual, and the option is enabled - if ( $this->is_downloadable() && $this->is_virtual() && get_option('woocommerce_limit_downloadable_product_qty') == 'yes' ) { + // Sold individually if downloadable, virtual, and the option is enabled OR if intentionally a singular item + if ( 'yes' == get_post_meta( $this->id, '_sold_individually', true ) || ( $this->is_downloadable() && $this->is_virtual() && get_option('woocommerce_limit_downloadable_product_qty') == 'yes' ) ) { $return = true; }