I used code from these posts (1,2) to create custom stock options:
function add_custom_stock_type() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' =>
'hide_if_variable custom-stock-status', 'label' => __( 'Stock status',
'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'1to3' => __( 'Διαθέσιμο! Παράδοση σε: 1-3 ημέρες', 'woocommerce' ),
'3to5' => __( 'Διαθέσιμο! Παράδοση σε: 3-5 ημέρες', 'woocommerce' ),
'7to10' => __( 'Διαθέσιμο! Παράδοση σε: 7-10 ημέρες', 'woocommerce' ),
'onrequest' => __( 'Διαθέσιμο κατόπιν παραγγελίας', 'woocommerce' ),//
The new option !!!
), 'desc_tip' => true, 'description' => __( 'Controls whether or not the
product is listed as "in stock" or "out of stock" on the frontend.',
'woocommerce' ) ) );
}
add_action('woocommerce_product_options_stock_status',
'add_custom_stock_type');
function save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean(
$_POST['_stock_status'] ) );
}
add_action('woocommerce_process_product_meta',
'save_custom_stock_status',99,1);
function woocommerce_get_custom_availability( $data, $product ) {
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $stock_status ) {
case 'instock':
$data = array( 'availability' => __( 'In stock', 'woocommerce' ),
'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Out of stock', 'woocommerce'
), 'class' => 'out-of-stock' );
break;
case '1to3':
$data = array( 'availability' => __( 'Διαθέσιμο! Παράδοση σε: 1-3
ημέρες', 'woocommerce' ), 'class' => '1to3' );
break;
case '3to5':
$data = array( 'availability' => __( 'Διαθέσιμο! Παράδοση σε: 3-5
ημέρες', 'woocommerce' ), 'class' => '3to5' );
break;
case '7to10':
$data = array( 'availability' => __( 'Διαθέσιμο! Παράδοση σε: 7-10
ημέρες', 'woocommerce' ), 'class' => '7to10' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'Διαθέσιμο κατόπιν
παραγγελίας', 'woocommerce' ), 'class' => 'on-request' );
break;
}
return $data;
}
add_action('woocommerce_get_availability',
'woocommerce_get_custom_availability', 10, 2);
The new stock options show up correctly in the single product edit page, but they won't show up when I try to bulk edit some products. Only "In stock" and "Out of stock" option are shown.
How can I bulk edit the products with the new custom stock options? It's a bit frustrating to edit the products one-by-one.