Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created December 4, 2012 23:27
Show Gist options
  • Save ChromeOrange/4210230 to your computer and use it in GitHub Desktop.
Save ChromeOrange/4210230 to your computer and use it in GitHub Desktop.
Woocommerce Sold Individually - with individual as default
/*
* Sell Products Individually in WooCommerce
*/
add_filter( 'woocommerce_is_sold_individually', 'cj_woocommerce_is_sold_individually', 10, 2 );
function cj_woocommerce_is_sold_individually( $value, $product ) {
$isi = get_post_meta( $product->id, '_custom_sell_individually', TRUE );
if ( $isi == 'individual' ) :
$return = true;
endif;
return $return;
}
if ( is_admin() ) :
add_action( 'woocommerce_product_options_dimensions', 'isi_write_panel');
add_action( 'woocommerce_process_product_meta', 'isi_write_panel_save' );
function isi_write_panel() {
echo '<div class="options_group">';
woocommerce_wp_select( array( 'id' => '_custom_sell_individually',
'label' => __('Sell Individually?', 'woocommerce'),
'options' => apply_filters('woocommerce_product_visibility_options',
array(
'individual' => __('Individual Only', 'woocommerce'),
'multiple' => __('Multiple purchases allowed', 'woocommerce')
)),
'description' => __('Limit the product to one per order?', 'woocommerce') ) );
echo '</div>';
}
function isi_write_panel_save( $post_id ) {
$_custom_sell_individually = esc_attr($_POST['_custom_sell_individually']);
update_post_meta($post_id, '_custom_sell_individually', $_custom_sell_individually);
}
endif;
@rajasajidmanzoor
Copy link

Hello
I checked this code. Its good and perfect.
I want to sell individual product. Mean i want to sell One product per order. Your Plugin Add One Quantity of Any product. But i want to add One Product Per order.. Can you please guide me how can i do thi.

@Bandarx69
Copy link

Hi,

Worked likes magic.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment